97 lines
3.1 KiB
JavaScript
Raw Normal View History

2011-11-30 18:06:45 -03:00
/*
* Copyright [2011] [wisemapping]
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
mindplot.widget.IMenu = new Class({
2012-07-01 17:21:02 -03:00
initialize:function (designer, containerId, mapId) {
2011-11-30 18:06:45 -03:00
$assert(designer, "designer can not be null");
$assert(containerId, "containerId can not be null");
this._designer = designer;
this._toolbarElems = [];
this._containerId = containerId;
this._mapId = mapId;
this._mindmapUpdated = false;
// Register update events ...
this._designer.addEvent('modelUpdate', function () {
this.setRequireChange(true);
}.bind(this));
2011-11-30 18:06:45 -03:00
},
2012-07-01 17:21:02 -03:00
clear:function () {
this._toolbarElems.each(function (item) {
2011-11-30 18:06:45 -03:00
item.hide();
});
},
2012-07-04 02:15:55 -03:00
discardChanges:function () {
// Avoid autosave before leaving the page ....
this.setRequireChange(false);
// Finally call discard function ...
2012-03-07 20:52:09 -03:00
var persistenceManager = mindplot.PersistenceManager.getInstance();
var mindmap = designer.getMindmap();
2012-07-04 02:15:55 -03:00
persistenceManager.discardChanges(mindmap.getId());
// Reload the page ...
window.location.reload();
2012-03-07 20:52:09 -03:00
},
save:function (saveElem, designer, saveHistory) {
2011-11-30 18:06:45 -03:00
// Load map content ...
var mindmap = designer.getMindmap();
var mindmapProp = designer.getMindmapProperties();
// Display save message ..
if (saveHistory) {
2012-07-01 17:21:02 -03:00
$notify($msg('SAVING'));
2011-11-30 18:06:45 -03:00
saveElem.setStyle('cursor', 'wait');
} else {
console.log("Saving without history ...");
}
// Call persistence manager for saving ...
var menu = this;
var persistenceManager = mindplot.PersistenceManager.getInstance();
2011-11-30 18:06:45 -03:00
persistenceManager.save(mindmap, mindmapProp, saveHistory, {
2012-07-01 17:21:02 -03:00
onSuccess:function () {
2011-11-30 18:06:45 -03:00
if (saveHistory) {
saveElem.setStyle('cursor', 'pointer');
2012-07-01 17:21:02 -03:00
$notify($msg('SAVE_COMPLETE'));
2011-11-30 18:06:45 -03:00
}
menu.setRequireChange(false);
2011-11-30 18:06:45 -03:00
},
2012-07-01 17:21:02 -03:00
onError:function () {
2011-11-30 18:06:45 -03:00
if (saveHistory) {
saveElem.setStyle('cursor', 'pointer');
2012-07-01 17:21:02 -03:00
$notify($msg('SAVE_COULD_NOT_BE_COMPLETED'));
2011-11-30 18:06:45 -03:00
}
}
});
},
isSaveRequired:function () {
return this._mindmapUpdated;
},
setRequireChange:function (value) {
this._mindmapUpdated = value;
2011-11-30 18:06:45 -03:00
}
2012-03-07 20:52:09 -03:00
});