Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
EXOGTN-1608 [Edit-InPlace] Refactor - move snapshot into internal of …
Browse files Browse the repository at this point in the history
…model
  • Loading branch information
nttuyen authored and vietj committed Oct 26, 2013
1 parent 75eebc4 commit ee959f1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
Expand Up @@ -292,10 +292,10 @@
var PageContainer = AbstractContainer.extend({
initialize : function() {
AbstractContainer.prototype.initialize.call(this);

this.set({
layout_id : ''
});
this._snapshot = this;
},

isAllowDropping : function(dragObj) {
Expand All @@ -307,6 +307,33 @@
}
},

/*
* methods on childrens
*/
addChild : function(child, options) {
child = typeof child == 'string' ? this.getRoot().getDescendant(child) : child;
AbstractContainer.prototype.addChild.call(this, child, options);

//We need listen to child to update this._snapshot model
if(child.getParent().getId() === this.getId()) {
this.listenTo(child, 'addChild.eXo.Container', this.updateSnapshot);
this.listenTo(child, 'removeChild.eXo.Container', this.updateSnapshot);
}
},
removeChild : function(child, options) {
child = typeof child == 'string' ? this.getChild(child) : child;
AbstractContainer.prototype.removeChild.call(this, child, options);

//After remove child success, need to stop listening it
if(child.getParent().getId() !== this.getId()) {
this.stopListening(child);
}
},

updateSnapshot: function() {
this._snapshot = this;
},

setLayoutId : function(layoutId) {
this.set('layout_id', layoutId);
},
Expand All @@ -315,7 +342,8 @@
},

switchLayout : function(newContainer) {
var conts = this.getChildrens();
var _oldModel = this._snapshot;
var conts = _oldModel.getChildrens();
conts.sort(function(m1, m2) {
var i1 = parseInt(m1.getId());
var i2 = parseInt(m2.getId());
Expand All @@ -342,6 +370,7 @@
}
});
});
newContainer._snapshot = _oldModel;
},

// Return the JSON object that contains metadata information
Expand Down
Expand Up @@ -107,8 +107,12 @@
dropApp : function(event, ui) {
var $dragObj = $(ui.item);
var targetContainerId = $dragObj.closest('.sortable').attr('id');
var layoutView = editorView.layoutView;
var targetContainer = layoutView.getModel().getChild(targetContainerId);
var targetContainer = null;
if(targetContainerId == this.model.getId()) {
targetContainer = this.model;
} else {
var targetContainer = this.model.getParent().getChild(targetContainerId);
}

var prev = $dragObj.prev('.portlet');
var idx = 0;
Expand All @@ -134,11 +138,6 @@
at : idx
});
}

// Update snapshot
var pageView = window.editorView.getPageView();
pageView.resetModelSnapshot();
//this.snapshotModel = this.model;
},
// An event handler for deleting a window.
// Find the target window ID and container ID
Expand All @@ -149,11 +148,6 @@
var layoutView = editorView.layoutView;
var container = layoutView.getModel().getChild(containerId);
container.removeChild(appId);

// Update snapshot
var pageView = window.editorView.getPageView();
pageView.resetModelSnapshot();
//this.snapshotModel = this.model;
},
/*
* Listen to model changes
Expand Down Expand Up @@ -198,7 +192,6 @@
// Build model from current DOM
var model = this.buildModel();
this.setModel(model);
this.snapshotModel = this.model;
},

setModel : function(model) {
Expand Down Expand Up @@ -245,7 +238,7 @@
this.$el.html(layoutData.html);

// Retrieve this before building the new model
var snapshot = this.snapshotModel;
var _model = this.model;

// Build new model according to new layout
var model = this.buildModel();
Expand All @@ -255,7 +248,7 @@
}

// Start switching layout
snapshot.switchLayout(this.model);
_model.switchLayout(this.model);

// remove old layout
tmp.remove();
Expand Down Expand Up @@ -286,9 +279,6 @@
},
getModel: function() {
return this.model;
},
resetModelSnapshot: function() {
this.snapshotModel = this.model;
}
});

Expand Down

0 comments on commit ee959f1

Please sign in to comment.