
function EditManager(){var param={templateLogs:[],updateCallback:null}
return{addLog:function(tempLog){var domOperation=Kooboo.dom.DomOperationHelper.getDomOperationByType(tempLog.domOperationType,tempLog);domOperation.update(tempLog.newValue);switch(tempLog.logType){case Kooboo.SiteEditorTypes.LogType.log:this.change(tempLog);break;case Kooboo.SiteEditorTypes.LogType.tempLog:param.templateLogs.push(tempLog);break;}},editImages:function(log){log.action=Kooboo.SiteEditorTypes.ActionType.update;log.editorType=Kooboo.SiteEditorTypes.EditorType.dom;log.domOperationType=Kooboo.SiteEditorTypes.DomOperationType.images;log.logType=Kooboo.SiteEditorTypes.LogType.tempLog;this.addLog(log);},editLink:function(log){log.action=Kooboo.SiteEditorTypes.ActionType.update;log.editorType=Kooboo.SiteEditorTypes.EditorType.dom;log.logType=Kooboo.SiteEditorTypes.LogType.tempLog;this.addLog(log);},replaceWithText:function(log){this.updateDom(log);},replaceWithImage:function(log){log.logType=Kooboo.SiteEditorTypes.LogType.tempLog;this.updateDom(log);},editImage:function(log){log.action=Kooboo.SiteEditorTypes.ActionType.update;log.editorType=Kooboo.SiteEditorTypes.EditorType.dom;log.domOperationType=Kooboo.SiteEditorTypes.DomOperationType.image;log.logType=Kooboo.SiteEditorTypes.LogType.tempLog;this.addLog(log);},editTreeDom:function(log){this.updateDom(log);},editTableDom:function(log){this.updateDom(log);},updateDom:function(log){log.action=Kooboo.SiteEditorTypes.ActionType.update;log.editorType=Kooboo.SiteEditorTypes.EditorType.dom;log.domOperationType=Kooboo.SiteEditorTypes.DomOperationType.html;this.addLog(log);},deleteDom:function(log){log.action=Kooboo.SiteEditorTypes.ActionType.delete;log.editorType=Kooboo.SiteEditorTypes.EditorType.dom;log.domOperationType=Kooboo.SiteEditorTypes.DomOperationType.html;this.addLog(log);},updateStyle:function(log){log.action=Kooboo.SiteEditorTypes.ActionType.update;log.editorType=Kooboo.SiteEditorTypes.EditorType.style;log.logType=Kooboo.SiteEditorTypes.LogType.tempLog;this.addLog(log);},removeContent:function(log){this.addLog(log);},editContent:function(log){this.addLog(log)},copyContent:function(log){this.addLog(log);},editMenu:function(log){this.addLog(log);},editHtmlBlock:function(log){this.addLog(log);},updateConverter:function(log){this.addLog(log);},removeLogs:function(){if(param.templateLogs.length==0)return;for(var i=param.templateLogs.length-1;i>=0;i--){var templateLog=param.templateLogs[i];var domOperation=Kooboo.dom.DomOperationHelper.getDomOperationByType(templateLog.domOperationType,templateLog);domOperation.update(templateLog.oldValue);}
param.templateLogs=[];},saveLogs:function(){if(param.templateLogs.length==0)return;var mergeTempLog=Kooboo.EditTempLogMerge.merge(param.templateLogs);this.change(mergeTempLog);param.templateLogs=[];},change:function(log){Kooboo.EditLog.add(log);if(param.updateCallback){param.updateCallback();}},hasNext:function(){return Kooboo.EditLog.hasNext();},hasPrev:function(){return Kooboo.EditLog.hasPrevious();},remove:function(isExistDataFn){var removeItem=Kooboo.EditLog.removeEditLog(isExistDataFn);if(removeItem){var domOperation=Kooboo.dom.DomOperationHelper.getDomOperationByType(removeItem.domOperationType,removeItem);domOperation.update(removeItem.oldValue);}
if(param.updateCallback){param.updateCallback();}
return removeItem;},undo:function(){if(this.hasPrev()){var log=Kooboo.EditLog.getPrevious();var changes=[log];if(log.changes&&log.changes.length>0){changes=log.changes;}
for(var i=changes.length-1;i>=0;i--){var change=changes[i];var domOperation=Kooboo.dom.DomOperationHelper.getDomOperationByType(change.domOperationType,change);if(domOperation!=null){domOperation.update(change.oldValue);if(change.undo){change.undo(change);}}}}},redo:function(){if(this.hasNext()){var log=Kooboo.EditLog.getNext();var changes=[log];if(log.changes&&log.changes.length>0){changes=log.changes;}
for(var i=0;i<=changes.length-1;i++){var change=changes[i];var domOperation=Kooboo.dom.DomOperationHelper.getDomOperationByType(change.domOperationType,change);if(domOperation!=null){domOperation.update(change.newValue);if(change.redo){change.redo(change);}}}}},convert:function(){return Kooboo.EditLog.decorateAndMergeLogs();},setUpdateCallback:function(fn){param.updateCallback=fn;}}}