refactored FlightDeck.Editor into PackageController

This commit is contained in:
Sean McArthur 2011-10-20 20:59:14 -05:00
Родитель 3dd0ba4d4b
Коммит 80671bfa5b
6 изменённых файлов: 55 добавлений и 77 удалений

Просмотреть файл

@ -8,10 +8,8 @@
<link rel="stylesheet" href="/media/jetpack/css/FlightDeck.Autocomplete.css" type="text/css" media="screen" />
<link rel="stylesheet" href="/media/jetpack/css/tree.css" type="text/css" media="screen" />
<link rel="stylesheet" href="/media/jetpack/css/collapse.css" type="text/css" media="screen" />
<script src="/media/lib/ace/ace-uncompressed.js"></script>
<script src="/media/lib/tree.js"></script>
<script src="/media/jetpack/js/FlightDeck.Editor.js"></script>
<script src="/media/lib/ace/ace.js"></script>
<script src="/media/lib/ace/mode-javascript.js"></script>
<script src="/media/lib/ace/mode-css.js"></script>

Просмотреть файл

@ -16,7 +16,6 @@
<script src="/media/jetpack/js/editor-min.js"></script>
{% endif %}
<script src="/media/jetpack/js/FlightDeck.Editor.js"></script>
<script src="/media/lib/ace/mode-javascript.js"></script>
<script src="/media/lib/ace/mode-css.js"></script>
<script src="/media/lib/ace/mode-html.js"></script>

Просмотреть файл

@ -1,61 +0,0 @@
/*
* Extending Flightdeck with Editor functionality
*/
FlightDeck = Class.refactor(FlightDeck,{
initialize: function(options) {
this.setOptions(options);
this.previous(options);
this.edited = 0;
window.addEvent('beforeunload', function(e) {
if (fd.edited && !fd.saving) {
e.stop();
e.returnValue = "You've got unsaved changes.";
} else {
}
});
this.enableMenuButtons();
this.addEvent('change', this.onChanged);
this.addEvent('save', this.onSaved);
this.addEvent('reset', this.onReset);
},
onChanged: function() {
$log('FD: INFO: document changed - onbeforeunload warning is on and save button is lit.');
$$('li.Icon_save').addClass('Icon_save_changes');
this.edited++;
},
onSaved: function() {
//any save specific logic?
this.fireEvent('reset');
},
onReset: function() {
$log('FD: INFO: document saved - onbeforeunload warning is off and save button is not lit.');
$$('li.Icon_save').removeClass('Icon_save_changes');
this.edited = 0;
},
/*
* Method: getItem
*/
getItem: function() {
return this.item;
},
/*
* Method: enableMenuButtons
* Switch on menu buttons, check if possible
*/
enableMenuButtons: function() {
$$('.' + this.options.menu_el + ' li.disabled').each(function(menuItem){
var switch_on = true;
if (switch_on) {
menuItem.removeClass('disabled');
}
}, this);
}
});

Просмотреть файл

@ -1,5 +1,6 @@
var Class = require('shipyard/class/Class'),
Options = require('shipyard/class/Options'),
Events = require('shipyard/class/Events'),
dom = require('shipyard/dom'),
//Request = require('shipyard/http/Request'),
@ -9,7 +10,7 @@ module.exports = new Class({
//Extends: Controller?,
Implements: Options,
Implements: [Events, Options],
options: {
modules: [],
@ -39,6 +40,10 @@ module.exports = new Class({
modules: {},
attachments: {},
folders: {},
dependencies: {},
edited: 0,
initialize: function PackageController(package, options, editor, tabs, sidebar) {
this.package = package;
@ -130,6 +135,10 @@ module.exports = new Class({
assignEditActions: function() {
var controller = this;
dom.window.addEvent('beforeunload', function(e) {
controller.alertUnsavedData(e);
});
this.packageInfoEl.addEvent('click', function(e) {
e.preventDefault();
controller.editInfo();
@ -165,6 +174,8 @@ module.exports = new Class({
}
});
this.attachEditor();
if (dom.$('jetpack_core_sdk_version')) {
dom.$('jetpack_core_sdk_version').addEvent('change', function() {
@ -321,7 +332,7 @@ module.exports = new Class({
return;
}
if (fd.edited) {
if (this.edited) {
fd.error.alert("There are unsaved changes",
"To make a copy, please save your changes.");
return;
@ -430,12 +441,41 @@ module.exports = new Class({
},
//Package.Edit
attachEditor: function() {
var controller = this;
this.editor.addEvent('change', function() {
controller.onChanged();
});
this.addEvent('change', this.onChanged);
this.addEvent('save', this.onSaved);
this.addEvent('reset', this.onReset);
},
onChanged: function() {
$log('FD: INFO: document changed - onbeforeunload warning is on and save button is lit.');
dom.$$('li.Icon_save').addClass('Icon_save_changes');
this.edited++;
},
onSaved: function() {
//any save specific logic?
this.fireEvent('reset');
},
onReset: function() {
$log('FD: INFO: document saved - onbeforeunload warning is off and save button is not lit.');
dom.$$('li.Icon_save').removeClass('Icon_save_changes');
this.edited = 0;
},
downloadAddonOrSave: function(e){
if (e) {
e.preventDefault();
}
var that = this;
if (fd.edited) {
if (this.edited) {
// display message
fd.showQuestion({
title: 'You\'ve got unsaved changes.',
@ -948,7 +988,7 @@ module.exports = new Class({
},
removeLibrary: function(lib) {
new Request.JSON({
new Request.JSON({
url: this.options.remove_library_url,
data: {'id_number': lib.options.id_number},
useSpinner: true,
@ -1301,6 +1341,14 @@ module.exports = new Class({
if (urls.download_url && $(this.options.download_el)) {
$(this.options.download_el).set('href', urls.download_url);
}
}
},
alertUnsavedData: function(e) {
if (this.edited && fd.saving) {
e.preventDefault();
e.returnValue = "You've got unsaved changes.";
}
}
});

Просмотреть файл

@ -56,8 +56,8 @@ module.exports = new Class({
setTimeout(function() {
file.content = file.original_content;
file.setChanged(false);
fd.edited--;
if(!fd.edited) {
fd.item.edited--;
if(!fd.item.edited) {
fd.fireEvent('reset');
}
}, 1);

Просмотреть файл

@ -156,12 +156,6 @@ var FDEditor = module.exports = new Class({
this.fireEvent('change');
$log('FD: DEBUG: changed, code is considered dirty and will remain'
+'be treated as such even if changes are reverted');
// fire the fd event
if (!fd.edited) {
fd.fireEvent('change');
} else {
fd.edited++;
}
this.unhookChange();
} else if (!this.switching && this.current.changed) {
this.current.setChanged(false);