Commit 32317211 authored by techird's avatar techird

导入导出容错

parent 3af6dcd7
......@@ -21,10 +21,10 @@ if (isset($_REQUEST['content'])) {
$filename = "kikyminder";
}
header("Content-type: application/octet-stream; charset=utf-8; name=".$filename);
header("Content-type: application/octet-stream; charset=utf8; name=".urlencode($filename));
header("Accept-Length: ".strlen($content));
header("Content-Length: ".strlen($content));
header("Content-Disposition: attachment; filename=".$filename);
header("Content-Disposition: attachment; filename=".urlencode($filename));
header('Content-Description: File Transfer');
echo $content;
......
......@@ -114,15 +114,15 @@
});
km.on('unziperror', function(ev) {
alert('unziperror');
alert('文件解析错误,文件可能已损坏!');
});
km.on('parseerror', function(ev) {
alert('parseerror');
alert('文件解析错误,文件可能已损坏!');
});
km.on('unknownprotocal', function(ev) {
alert('unknownprotocal');
alert('不支持的文件格式!');
});
</script>
......
......@@ -150,7 +150,7 @@ $(function() {
menus = menus.concat([{
divider: true,
}, {
label: '登陆',
label: '请登录',
click: login,
id: 'net-hint-buttom'
}, {
......
......@@ -4,7 +4,8 @@
var content = url.split(',')[1];
var $form = $('<form></form>').attr({
'action': 'download.php',
'method': 'POST'
'method': 'POST',
'accept-charset': 'utf-8'
});
var $content = $('<input />').attr({
......@@ -25,6 +26,8 @@
value: filename
}).appendTo($form);
$('<input name="iehack" value="&#9760;" />').appendTo($form);
$form.appendTo('body').submit().remove();
}
......
......@@ -91,13 +91,19 @@ kity.extendClass(Minder, {
var stoped = this._fire(new MinderEvent('beforeimport', params, true));
if (stoped) return this;
try {
json = params.json || (params.json = protocal.decode(local));
} catch (e) {
return this.fire('parseerror');
}
if (typeof json === 'object' && 'then' in json) {
var self = this;
json.then(local, function(data) {
json.then(function(data) {
params.json = data;
self._doImport(data, params);
}).error(function() {
self.fire('parseerror');
});
} else {
this._doImport(json, params);
......@@ -124,6 +130,8 @@ kity.extendClass(Minder, {
return node;
}
if (!json) return;
this._fire(new MinderEvent('preimport', params, false));
// 删除当前所有节点
......
......@@ -37,7 +37,11 @@ KityMinder.registerModule('DropFile', function() {
function importMinderFile(minder, file) {
if (!file) return;
var ext = /(.)\w+$/.exec(file.name)[0];
var ext = /(.)\w+$/.exec(file.name);
if (!ext) return alert('不支持导入此类文件!');
ext = ext[0];
if ((/xmind/g).test(ext)) { //xmind zip
importSync(minder, file, 'xmind');
......@@ -50,7 +54,7 @@ KityMinder.registerModule('DropFile', function() {
} else if (/txt/.test(ext)) {
importAsync(minder, file, 'plain');
} else {
alert('不支持文件!');
alert('不支持导入此类文件!');
}
}
......
......@@ -28,7 +28,7 @@ KityMinder.registerModule('PriorityModule', function() {
bg = new kity.Rect()
.setRadius(3)
.setPosition(0, 0)
.setPosition(0.5, 0.5)
.setSize(this.width, this.height);
number = new kity.Text()
......
......@@ -6,66 +6,68 @@
*/
KityMinder.registerProtocal( 'freemind', function () {
KityMinder.registerProtocal('freemind', function() {
// 标签 map
var markerMap = {
'full-1' : ['PriorityIcon', 1]
,'full-2' : ['PriorityIcon', 2]
,'full-3' : ['PriorityIcon', 3]
,'full-4' : ['PriorityIcon', 4]
,'full-5' : ['PriorityIcon', 5]
,'full-6' : null
,'full-7' : null
,'full-8' : null
,'full-9' : null
,'full-0' : null
'full-1': ['priority', 1],
'full-2': ['priority', 2],
'full-3': ['priority', 3],
'full-4': ['priority', 4],
'full-5': ['priority', 5],
'full-6': ['priority', 6],
'full-7': ['priority', 7],
'full-8': ['priority', 8]
};
function processTopic(topic, obj){
function processTopic(topic, obj) {
//处理文本
obj.data = { text : topic.TEXT };
obj.data = {
text: topic.TEXT
};
var i;
// 处理标签
if(topic.icon){
if (topic.icon) {
var icons = topic.icon;
if(icons.length && icons.length > 0){
for (var i in icons) {
var type = markerMap[ icons[i]['BUILTIN'] ];
type && (obj.data[ type[0] ] = type[1]);
var type;
if (icons.length && icons.length > 0) {
for (i in icons) {
type = markerMap[icons[i].BUILTIN];
if (type) obj.data[type[0]] = type[1];
}
}else{
var type = markerMap[ icons['BUILTIN'] ];
type && (obj.data[ type[0] ] = type[1]);
} else {
type = markerMap[icons.BUILTIN];
if (type) obj.data[type[0]] = type[1];
}
}
// 处理超链接
if(topic.LINK){
if (topic.LINK) {
obj.data.hyperlink = topic.LINK;
}
//处理子节点
if( topic.node ){
if (topic.node) {
var tmp = topic.node;
if( tmp.length && tmp.length > 0 ){ //多个子节点
if (tmp.length && tmp.length > 0) { //多个子节点
obj.children = [];
for(var i in tmp){
for (i in tmp) {
obj.children.push({});
processTopic(tmp[i], obj.children[i]);
}
}else{ //一个子节点
} else { //一个子节点
obj.children = [{}];
processTopic(tmp, obj.children[0]);
}
}
}
function xml2km(xml){
function xml2km(xml) {
var json = $.xml2json(xml);
var result = {};
processTopic(json.node, result);
......@@ -76,18 +78,11 @@ KityMinder.registerProtocal( 'freemind', function () {
fileDescription: 'freemind格式文件',
fileExtension: '.mm',
decode: function ( local ) {
try{
return xml2km( local );
}catch(e){
km.fire('parseerror');
return undefined;
}
decode: function(local) {
return xml2km(local);
},
// recognize: null,
recognizePriority: -1
};
} );
});
\ No newline at end of file
KityMinder.registerProtocal( 'json', function () {
function filter( key, value ) {
if ( key == 'layout' || key == 'shicon' ) {
KityMinder.registerProtocal('json', function() {
function filter(key, value) {
if (key == 'layout' || key == 'shicon') {
return undefined;
}
return value;
......@@ -9,15 +9,15 @@ KityMinder.registerProtocal( 'json', function () {
fileDescription: 'KityMinder',
fileExtension: '.km',
mineType: 'application/json',
encode: function ( json ) {
return JSON.stringify( json, filter );
encode: function(json) {
return JSON.stringify(json, filter);
},
decode: function ( local ) {
return JSON.parse( local );
decode: function(local) {
return JSON.parse(local);
},
recognize: function ( local ) {
return Utils.isString( local ) && local.charAt( 0 ) == '{' && local.charAt( local.length - 1 ) == '}';
recognize: function(local) {
return Utils.isString(local) && local.charAt(0) == '{' && local.charAt(local.length - 1) == '}';
},
recognizePriority: 0
};
} );
\ No newline at end of file
});
\ No newline at end of file
/* global zip:true */
/*
http://www.mindjet.com/mindmanager/
mindmanager的后缀为.mmap,实际文件格式是zip,解压之后核心文件是Document.xml
*/
KityMinder.registerProtocal('mindmanager', function() {
KityMinder.registerProtocal( 'mindmanager', function () {
var successCall, errorCall;
// 标签 map
var markerMap = {
'urn:mindjet:Prio1': [ 'PriorityIcon', 1 ],
'urn:mindjet:Prio2': [ 'PriorityIcon', 2 ],
'urn:mindjet:Prio3': [ 'PriorityIcon', 3 ],
'urn:mindjet:Prio4': [ 'PriorityIcon', 4 ],
'urn:mindjet:Prio5': [ 'PriorityIcon', 5 ],
'0': [ 'ProgressIcon', 1 ],
'25': [ 'ProgressIcon', 2 ],
'50': [ 'ProgressIcon', 3 ],
'75': [ 'ProgressIcon', 4 ],
'100': [ 'ProgressIcon', 5 ]
'urn:mindjet:Prio1': ['PriorityIcon', 1],
'urn:mindjet:Prio2': ['PriorityIcon', 2],
'urn:mindjet:Prio3': ['PriorityIcon', 3],
'urn:mindjet:Prio4': ['PriorityIcon', 4],
'urn:mindjet:Prio5': ['PriorityIcon', 5],
'0': ['ProgressIcon', 1],
'25': ['ProgressIcon', 2],
'50': ['ProgressIcon', 3],
'75': ['ProgressIcon', 4],
'100': ['ProgressIcon', 5]
};
function processTopic( topic, obj ) {
function processTopic(topic, obj) {
//处理文本
obj.data = {
text: topic.Text && topic.Text.PlainText || ''
}; // 节点默认的文本,没有Text属性
// 处理标签
if ( topic.Task ) {
if (topic.Task) {
var type;
if ( topic.Task.TaskPriority ) {
type = markerMap[ topic.Task.TaskPriority ];
type && ( obj.data[ type[ 0 ] ] = type[ 1 ] );
if (topic.Task.TaskPriority) {
type = markerMap[topic.Task.TaskPriority];
if (type) obj.data[type[0]] = type[1];
}
if ( topic.Task.TaskPercentage ) {
type = markerMap[ topic.Task.TaskPercentage ];
type && ( obj.data[ type[ 0 ] ] = type[ 1 ] );
if (topic.Task.TaskPercentage) {
type = markerMap[topic.Task.TaskPercentage];
if (type) obj.data[type[0]] = type[1];
}
}
// 处理超链接
if ( topic.Hyperlink ) {
if (topic.Hyperlink) {
obj.data.hyperlink = topic.Hyperlink.Url;
}
//处理子节点
if ( topic.SubTopics && topic.SubTopics.Topic ) {
if (topic.SubTopics && topic.SubTopics.Topic) {
var tmp = topic.SubTopics.Topic;
if ( tmp.length && tmp.length > 0 ) { //多个子节点
if (tmp.length && tmp.length > 0) { //多个子节点
obj.children = [];
for ( var i in tmp ) {
obj.children.push( {} );
processTopic( tmp[ i ], obj.children[ i ] );
for (var i in tmp) {
obj.children.push({});
processTopic(tmp[i], obj.children[i]);
}
} else { //一个子节点
obj.children = [ {} ];
processTopic( tmp, obj.children[ 0 ] );
obj.children = [{}];
processTopic(tmp, obj.children[0]);
}
}
}
function xml2km( xml ) {
var json = $.xml2json( xml );
function xml2km(xml) {
var json = $.xml2json(xml);
var result = {};
processTopic( json.OneTopic.Topic, result );
processTopic(json.OneTopic.Topic, result);
return result;
}
function onerror(){
km.fire('unziperror');
function onerror() {
errorCall('ziperror');
}
function getEntries( file, onend ) {
zip.createReader( new zip.BlobReader( file ), function ( zipReader ) {
zipReader.getEntries( onend );
}, onerror );
function getEntries(file, onend) {
zip.createReader(new zip.BlobReader(file), function(zipReader) {
zipReader.getEntries(onend);
}, onerror);
}
return {
fileDescription: 'mindmanager格式文件',
fileExtension: '.mmap',
decode: function ( local ) {
decode: function(local) {
return {
then: function ( local, callback ) {
getEntries( local, function ( entries ) {
then: function(callback) {
successCall = callback;
getEntries(local, function(entries) {
var hasMainDoc = false;
entries.forEach( function ( entry ) {
if ( entry.filename == 'Document.xml' ) {
entries.forEach(function(entry) {
if (entry.filename == 'Document.xml') {
hasMainDoc = true;
entry.getData( new zip.TextWriter(), function ( text ) {
try{
var km = xml2km( $.parseXML( text ) );
callback && callback( km );
}catch(e){
km.fire('parseerror');
entry.getData(new zip.TextWriter(), function(text) {
try {
var km = xml2km($.parseXML(text));
if (successCall) successCall(km);
} catch (e) {
if (errorCall) errorCall('parseerror');
}
} );
});
}
} );
!hasMainDoc && km.fire('parseerror');
} );
});
if (!hasMainDoc && errorCall) errorCall('parseerror');
});
return this;
},
error: function(callback) {
errorCall = callback;
}
};
},
// recognize: recognize,
recognizePriority: -1
};
} );
\ No newline at end of file
});
\ No newline at end of file
KityMinder.registerProtocal( "plain", function () {
KityMinder.registerProtocal('plain', function() {
var LINE_ENDING = '\n',
TAB_CHAR = '\t';
function repeat( s, n ) {
var result = "";
while ( n-- ) result += s;
function repeat(s, n) {
var result = '';
while (n--) result += s;
return result;
}
function encode( json, level ) {
var local = "";
function encode(json, level) {
var local = '';
level = level || 0;
local += repeat( TAB_CHAR, level );
local += repeat(TAB_CHAR, level);
local += json.data.text + LINE_ENDING;
if ( json.children ) {
json.children.forEach( function ( child ) {
local += encode( child, level + 1 );
} );
if (json.children) {
json.children.forEach(function(child) {
local += encode(child, level + 1);
});
}
return local;
}
function isEmpty( line ) {
return !/\S/.test( line );
function isEmpty(line) {
return !/\S/.test(line);
}
function getLevel( line ) {
function getLevel(line) {
var level = 0;
while ( line.charAt( level ) === TAB_CHAR ) level++;
while (line.charAt(level) === TAB_CHAR) level++;
return level;
}
function getNode( line ) {
function getNode(line) {
return {
data: {
text: line.replace( new RegExp( '^' + TAB_CHAR + '*' ), '' )
text: line.replace(new RegExp('^' + TAB_CHAR + '*'), '')
}
};
}
function decode( local ) {
function decode(local) {
var json,
parentMap = {},
lines = local.split( LINE_ENDING ),
lines = local.split(LINE_ENDING),
line, level, node;
function addChild( parent, child ) {
var children = parent.children || ( parent.children = [] );
children.push( child );
function addChild(parent, child) {
var children = parent.children || (parent.children = []);
children.push(child);
}
for ( var i = 0; i < lines.length; i++ ) {
line = lines[ i ];
if ( isEmpty( line ) ) continue;
for (var i = 0; i < lines.length; i++) {
line = lines[i];
if (isEmpty(line)) continue;
level = getLevel( line );
node = getNode( line );
level = getLevel(line);
node = getNode(line);
if ( level === 0 ) {
if ( json ) {
throw new Error( 'Invalid local format' );
if (level === 0) {
if (json) {
throw new Error('Invalid local format');
}
json = node;
} else {
if ( !parentMap[ level - 1 ] ) {
throw new Error( 'Invalid local format' );
if (!parentMap[level - 1]) {
throw new Error('Invalid local format');
}
addChild( parentMap[ level - 1 ], node );
addChild(parentMap[level - 1], node);
}
parentMap[ level ] = node;
parentMap[level] = node;
}
return json;
}
var lastTry, lastResult;
function recognize( local ) {
if ( !Utils.isString( local ) ) return false;
function recognize(local) {
if (!Utils.isString(local)) return false;
lastTry = local;
try {
lastResult = decode( local );
} catch ( e ) {
lastResult = decode(local);
} catch (e) {
lastResult = null;
}
return !!lastResult;
}
return {
fileDescription: '大纲文本',
fileExtension: '.txt',
mineType: 'text/plain',
encode: function ( json ) {
return encode( json, 0 );
encode: function(json) {
return encode(json, 0);
},
decode: function ( local ) {
if ( lastTry == local && lastResult ) {
decode: function(local) {
if (lastTry == local && lastResult) {
return lastResult;
}
return decode( local );
return decode(local);
},
recognize: recognize,
recognizePriority: -1
};
} );
\ No newline at end of file
});
\ No newline at end of file
/*
http://www.xmind.net/developer/
Parsing XMind file
XMind files are generated in XMind Workbook (.xmind) format, an open format that is based on the principles of OpenDocument. It consists of a ZIP compressed archive containing separate XML documents for content and styles, a .jpg image file for thumbnails, and directories for related attachments.
XMind files are generated in XMind Workbook (.xmind) format, an open format
that is based on the principles of OpenDocument. It consists of a ZIP
compressed archive containing separate XML documents for content and styles,
a .jpg image file for thumbnails, and directories for related attachments.
*/
KityMinder.registerProtocal( 'xmind', function () {
KityMinder.registerProtocal('xmind', function() {
// 标签 map
var markerMap = {
'priority-1' : ['PriorityIcon', 1]
,'priority-2' : ['PriorityIcon', 2]
,'priority-3' : ['PriorityIcon', 3]
,'priority-4' : ['PriorityIcon', 4]
,'priority-5' : ['PriorityIcon', 5]
,'task-start' : ['ProgressIcon', 1]
,'task-quarter' : ['ProgressIcon', 2]
,'task-half' : ['ProgressIcon', 3]
,'task-3quar' : ['ProgressIcon', 4]
,'task-done' : ['ProgressIcon', 5]
,'task-oct' : null
,'task-3oct' : null
,'task-5oct' : null
,'task-7oct' : null
'priority-1': ['priority', 1],
'priority-2': ['priority', 2],
'priority-3': ['priority', 3],
'priority-4': ['priority', 4],
'priority-5': ['priority', 5],
'priority-6': ['priority', 6],
'priority-7': ['priority', 7],
'priority-8': ['priority', 8],
'task-start': ['progress', 1],
'task-oct': ['progress', 2],
'task-quarter': ['progress', 3],
'task-3oct': ['progress', 4],
'task-half': ['progress', 5],
'task-5oct': ['progress', 6],
'task-3quar': ['progress', 7],
'task-7oct': ['progress', 8],
'task-done': ['progress', 9]
};
function getAttachedNode( arr ){
for (var i = 0; i < arr.length; i++) {
if( arr[ i ].type == "attached" )
return arr[ i ]
}
}
return {
fileDescription: 'xmind格式文件',
fileExtension: '.xmind',
decode: function(local) {
var successCall, errorCall;
function processTopic(topic, obj){
function processTopic(topic, obj) {
//处理文本
obj.data = { text : topic.title };
obj.data = {
text: topic.title
};
// 处理标签
if(topic.marker_refs && topic.marker_refs.marker_ref){
if (topic.marker_refs && topic.marker_refs.marker_ref) {
var markers = topic.marker_refs.marker_ref;
if( markers.length && markers.length > 0 ){
if (markers.length && markers.length > 0) {
for (var i in markers) {
var type = markerMap[ markers[i]['marker_id'] ];
type && (obj.data[ type[0] ] = type[1]);
var type = markerMap[markers[i]['marker_id']];
type && (obj.data[type[0]] = type[1]);
}
}else{
var type = markerMap[ markers['marker_id'] ];
type && (obj.data[ type[0] ] = type[1]);
} else {
var type = markerMap[markers['marker_id']];
type && (obj.data[type[0]] = type[1]);
}
}
// 处理超链接
if(topic['xlink:href']){
if (topic['xlink:href']) {
obj.data.hyperlink = topic['xlink:href'];
}
//处理子节点
var topics;
if( topic.children && (topics=topic.children.topics) && ( topics.topic || (utils.isArray( topics ) && topics.length>0) ) ){
var tmp = topics.topic || (getAttachedNode( topics )).topic;
if( tmp.length && tmp.length > 0 ){ //多个子节点
var topics = topic.children && topic.children.topics;
var subTopics = topics && (topics.topic || topics[0] && topics[0].topic);
if (subTopics) {
var tmp = subTopics;
if (tmp.length && tmp.length > 0) { //多个子节点
obj.children = [];
for(var i in tmp){
for (var i in tmp) {
obj.children.push({});
processTopic(tmp[i], obj.children[i]);
}
}else{ //一个子节点
} else { //一个子节点
obj.children = [{}];
processTopic(tmp, obj.children[0]);
}
}
}
function xml2km(xml){
function xml2km(xml) {
var json = $.xml2json(xml);
var result = {};
var sheet = json.sheet;
......@@ -88,8 +93,8 @@ KityMinder.registerProtocal( 'xmind', function () {
return result;
}
function onerror(){
km.fire('unziperror');
function onerror() {
errorCall('ziperror');
}
function getEntries(file, onend) {
......@@ -97,34 +102,31 @@ KityMinder.registerProtocal( 'xmind', function () {
zipReader.getEntries(onend);
}, onerror);
}
return {
fileDescription: 'xmind格式文件',
fileExtension: '.xmind',
decode: function ( local ) {
return {
then : function(local, callback){
then: function(callback) {
getEntries( local, function( entries ) {
getEntries(local, function(entries) {
var hasMainDoc = false;
entries.forEach(function( entry ) {
if(entry.filename == 'content.xml'){
entries.forEach(function(entry) {
if (entry.filename == 'content.xml') {
hasMainDoc = true;
entry.getData(new zip.TextWriter(), function(text) {
try{
try {
var km = xml2km($.parseXML(text));
callback && callback( km );
}catch(e){
km.fire('parseerror');
callback && callback(km);
} catch (e) {
errorCall && errorCall('parseerror');
}
});
}
});
!hasMainDoc && km.fire('parseerror');
!hasMainDoc && errorCall && errorCall('parseerror');
});
return this;
},
error: function(callback) {
errorCall = callback;
}
};
......@@ -133,6 +135,4 @@ KityMinder.registerProtocal( 'xmind', function () {
recognizePriority: -1
};
} );
});
\ No newline at end of file
......@@ -114,6 +114,7 @@ button#tool-btn {
#panel button#tool-btn {
padding-right: 20px;
position: relative;
overflow: visible;
}
#panel button#tool-btn.active:before {
......@@ -273,9 +274,17 @@ svg, body {
transition: all ease .3s 0.3s;
-webkit-transform: translate(100%);
-moz-transform: translate(100%);
-ms-transform: translate(100%);
-o-transform: translate(100%);
transform: translate(100%);
}
#about:hover {
#about:hover, #about:hover #km-cat {
-webkit-transform: translate(0);
-moz-transform: translate(0);
-ms-transform: translate(0);
-o-transform: translate(0);
transform: translate(0);
}
#about a {
color: #eee;
......@@ -286,11 +295,12 @@ svg, body {
top: 5px;
transition: all ease 1.3s 0.3s;
-webkit-transform: translate(-60px, 0);
-moz-transform: translate(-60px, 0);
-ms-transform: translate(-60px, 0);
-o-transform: translate(-60px, 0);
transform: translate(-60px, 0);
cursor: pointer;
}
#about:hover #km-cat {
-webkit-transform: translate(0);
}
#about #cat-face {
fill: #393F4F;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment