undo: function(){ if(!this._newId || !this._oldData){ return; } var widgetUtils = require("davinci/ve/widget"); var widget = widgetUtils.byId(this._newId); if(!widget){ return; } var index = dojo.indexOf(this._parentWidget.getChildren(), widget); if(index < 0){ return; } // remove new var context = this._parentWidget.getContext(); if(context){ context.detach(widget); } this._parentWidget.removeChild( widget); widget.destroyWidget(); // add old this._oldData.children = this._oldText; this._oldData.properties.id = this._oldId; // make sure the id is restored var newWidget = widgetUtils.createWidget(this._oldData); widget.getParent().addChild(newWidget, index); if(context){ this._refresh(newWidget); } dojo.publish("/davinci/ui/widget/replaced", [newWidget, widget]); // Recompute styling properties in case we aren't in Normal state var states = require("davinci/ve/States"); states.resetState(newWidget.domNode); },
execute: function(){ if(!this._oldId || !this._properties){ return; } var widgetUtils = require("davinci/ve/widget"); var widget = widgetUtils.byId(this._oldId); if(!widget){ return; } this._parentWidget = widget.getParent(); if (!this._oldText){ this._oldText = widget._srcElement.getElementText(this._context); if (this._oldText && (typeof this._oldText == 'string')){ this._oldText = this._oldText.replace(/\n/g, ''); // new lines breaks create widget richtext } } if(!this._oldData ){ this._oldData = widget.getData(); this._oldData.context = this._context; this._newData = {type: this._oldData.type, properties: dojo.mixin({}, this._oldData.properties, this._properties), children: this._newText, states: this._oldData.states, context:this._context }; this._oldData = {type: this._oldData.type, properties: dojo.mixin({}, this._oldData.properties, this._properties), children: this._oldText, states: this._oldData.states, context:this._context }; } if(this._context){ this._context.detach(widget); } if(this._properties.id){ delete this._newData.properties.isTempID; } if (!this._newId_isTempID){ this._newId_isTempID = this._newData.properties.isTempID; } if (!this._oldId_isTempID){ this._oldId_isTempID = this._oldData.properties.isTempID; } var newWidget = null; var index = this._parentWidget.indexOf(widget); this._parentWidget.removeChild(widget); widget.destroyWidget(); if (this._newId) { this._newData.properties.id = this._newId; // make sure the id is restored } if (this._newId_isTempID) { this._newData.properties.isTempID = this._newId_isTempID; } newWidget = widgetUtils.createWidget(this._newData); if(!newWidget){ return; } this._parentWidget.addChild(newWidget,index); this._newId = newWidget.id; if(this._context){ this._refresh(newWidget); } this.newWidget=newWidget; dojo.publish("/davinci/ui/widget/replaced", [newWidget, widget]); // Recompute styling properties in case we aren't in Normal state var states = require("davinci/ve/States"); states.resetState(newWidget.domNode); },