зеркало из https://github.com/mozilla/FlightDeck.git
the removal the huge Package.js
* converted various Files to use Models now
This commit is contained in:
Родитель
5a0584a6ba
Коммит
de89cd75fb
|
@ -16,7 +16,6 @@
|
|||
<script src="/media/lib/ace/mode-html.js"></script>
|
||||
<script src="/media/lib/meio/Meio.Autocomplete.HTML-1.3.js"></script>
|
||||
<script src="/media/base/js/FlightDeck.Autocomplete.js"></script>
|
||||
<script src="/media/jetpack/js/Package.js"></script>
|
||||
<script src="/media/lib/FloatingTips.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
<script src="/media/lib/ace/mode-html.js"></script>
|
||||
<script src="/media/lib/meio/Meio.Autocomplete.HTML-1.3.js"></script>
|
||||
<script src="/media/base/js/FlightDeck.Autocomplete.js"></script>
|
||||
<script src="/media/jetpack/js/Package.js"></script>
|
||||
<script src="/media/lib/FloatingTips.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
|
|
@ -1,325 +0,0 @@
|
|||
var File = new Class({
|
||||
|
||||
Implements: [Options, Events],
|
||||
|
||||
options: {
|
||||
path: null
|
||||
//events
|
||||
//onDestroy: function() {}
|
||||
},
|
||||
|
||||
initialize: function(pack, options) {
|
||||
this.pack = pack;
|
||||
this.setOptions(options);
|
||||
},
|
||||
|
||||
getShortName: function() {
|
||||
return this.getFullName().split('/').pop();
|
||||
},
|
||||
|
||||
getFullName: function() {
|
||||
var name = this.options.filename;
|
||||
if(this.options.type) {
|
||||
name += '.' + this.options.type;
|
||||
}
|
||||
return name;
|
||||
},
|
||||
|
||||
is_editable: function() {
|
||||
return ['css', 'txt', 'js', 'html'].contains(this.options.type);
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
if (this.active) {
|
||||
// switch editor!
|
||||
mod = null;
|
||||
// try to switch to first element
|
||||
first = false;
|
||||
Object.each(this.pack.modules, function(mod) {
|
||||
if (!first) {
|
||||
first = true;
|
||||
editor.sidebar.setSelectedFile(mod);
|
||||
}
|
||||
});
|
||||
if (!first) {
|
||||
this.pack.editor.setContent('');
|
||||
}
|
||||
}
|
||||
|
||||
if(this.tab) {
|
||||
this.tab.destroy();
|
||||
|
||||
}
|
||||
this.fireEvent('destroy');
|
||||
},
|
||||
|
||||
setChanged: function(isChanged) {
|
||||
if (this.changed != isChanged) {
|
||||
this.fireEvent(isChanged ? 'change' : 'reset');
|
||||
}
|
||||
this.changed = isChanged;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
File.sanitize = function(name) {
|
||||
return name.replace(/[^a-zA-Z0-9=!@#\$%\^&\(\)\+\-_\/\.]+/g, '-');
|
||||
};
|
||||
|
||||
var Library = new Class({
|
||||
|
||||
Extends: File,
|
||||
|
||||
options: {
|
||||
append: true
|
||||
},
|
||||
|
||||
initialize: function(pack, options) {
|
||||
this.parent(pack, options);
|
||||
|
||||
this.addEvent('destroy', function(){
|
||||
delete pack.libraries[this.options.id_number];
|
||||
});
|
||||
},
|
||||
|
||||
getID: function() {
|
||||
return 'Library-' + this.options.id_number;
|
||||
},
|
||||
|
||||
getShortName: function() {
|
||||
return this.options.full_name;
|
||||
},
|
||||
|
||||
getFullName: function() {
|
||||
return this.getID();
|
||||
},
|
||||
|
||||
storeNewVersion: function(version_data) {
|
||||
this._latest_version = version_data;
|
||||
},
|
||||
|
||||
retrieveNewVersion: function() {
|
||||
return this._latest_version;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var Attachment = new Class({
|
||||
|
||||
Extends: File,
|
||||
|
||||
options: {
|
||||
code_trigger_suffix: '_attachment_switch', // id of an element which is used to switch editors
|
||||
code_editor_suffix: '_attachment_textarea', // id of the textarea
|
||||
active: false,
|
||||
type: 'js',
|
||||
append: false,
|
||||
filename: '',
|
||||
readonly: false,
|
||||
counter: 'attachments'
|
||||
},
|
||||
|
||||
is_image: function() {
|
||||
return ['jpg', 'gif', 'png'].contains(this.options.type);
|
||||
},
|
||||
|
||||
initialize: function(pack, options) {
|
||||
this.parent(pack, options);
|
||||
this.options.path = options.filename + '.' + options.type;
|
||||
// uid for editor items
|
||||
this.uid = this.getEditorID();
|
||||
|
||||
this.addEvent('destroy', function(){
|
||||
delete pack.attachments[this.options.uid];
|
||||
});
|
||||
// create editor
|
||||
pack.editor.registerItem(this);
|
||||
},
|
||||
|
||||
loadContent: function() {
|
||||
var that = this,
|
||||
spinnerEl = $(this.tab);
|
||||
new Request({
|
||||
method: 'get',
|
||||
url: this.options.get_url,
|
||||
useSpinner: !!spinnerEl,
|
||||
spinnerTarget: spinnerEl,
|
||||
spinnerOptions: {
|
||||
img: {
|
||||
'class': 'spinner-img spinner-16'
|
||||
},
|
||||
maskBorder: false
|
||||
},
|
||||
onSuccess: function() {
|
||||
var content = this.response.text || '';
|
||||
that.content = content;
|
||||
that.original_content = content;
|
||||
that.fireEvent('loadcontent', content);
|
||||
}
|
||||
}).send();
|
||||
},
|
||||
|
||||
isLoaded: function() {
|
||||
return this.content != null;
|
||||
},
|
||||
|
||||
getID: function() {
|
||||
return 'Attachment-'+this.uid;
|
||||
},
|
||||
|
||||
getEditorID: function() {
|
||||
return this.options.uid + this.options.code_editor_suffix;
|
||||
},
|
||||
|
||||
reassign: function(options) {
|
||||
// every revision, attachments that have changed get a new `uid`.
|
||||
// since Attachments are currently kept track of via the `uid`,
|
||||
// we must adjust all instances that keep track of this
|
||||
// attachment to use the new id, and any other new options that
|
||||
// comes with it
|
||||
|
||||
var packAttachments = this.pack.attachments,
|
||||
editorItems = this.pack.editor.items,
|
||||
oldUID = this.options.uid;
|
||||
|
||||
delete packAttachments[oldUID];
|
||||
|
||||
this.setOptions(options);
|
||||
this.options.path = options.filename + '.' + options.type;
|
||||
packAttachments[options.uid] = this;
|
||||
|
||||
var editorUID = this.getEditorID();
|
||||
editorItems[editorUID] = editorItems[this.uid];
|
||||
delete editorItems[this.uid];
|
||||
this.uid = editorUID;
|
||||
|
||||
if (options.append) {
|
||||
this.append();
|
||||
}
|
||||
|
||||
if (this.tab) {
|
||||
this.tab.setLabel(this.getShortName());
|
||||
}
|
||||
this.fireEvent('reassign', this.options.uid);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Attachment.exists = function(filename, ext) {
|
||||
return Object.some(fd.item.attachments, function(att) {
|
||||
return (att.options.filename == filename) &&
|
||||
att.options.type == ext;
|
||||
});
|
||||
};
|
||||
|
||||
var Module = new Class({
|
||||
|
||||
Extends: File,
|
||||
|
||||
options: {
|
||||
// data
|
||||
// filename: '',
|
||||
// code: '',
|
||||
// author: '',
|
||||
// DOM
|
||||
code_trigger_suffix: '_switch', // id of an element which is used to switch editors
|
||||
suffix: '_module',
|
||||
readonly: false,
|
||||
main: false,
|
||||
executable: false,
|
||||
active: false,
|
||||
type: 'js',
|
||||
append: false,
|
||||
counter: 'modules'
|
||||
},
|
||||
|
||||
initialize: function(pack, options) {
|
||||
this.parent(pack, options);
|
||||
this.options.path = this.options.filename + '.' + this.options.type;
|
||||
|
||||
this.addEvent('destroy', function(){
|
||||
delete pack.modules[this.options.filename];
|
||||
});
|
||||
|
||||
// an uid for the editor
|
||||
this.uid = this.options.filename + this.options.suffix;
|
||||
// create editor
|
||||
pack.editor.registerItem(this);
|
||||
},
|
||||
|
||||
loadContent: function() {
|
||||
// load data synchronously
|
||||
var spinnerEl = $(this.tab);
|
||||
new Request.JSON({
|
||||
method: 'get',
|
||||
url: this.options.get_url,
|
||||
useSpinner: !!spinnerEl,
|
||||
spinnerTarget: spinnerEl,
|
||||
spinnerOptions: {
|
||||
img: {
|
||||
'class': 'spinner-img spinner-16'
|
||||
},
|
||||
maskBorder: false
|
||||
},
|
||||
onSuccess: function(mod) {
|
||||
var code = mod.code || '';
|
||||
this.original_content = code;
|
||||
this.content = code;
|
||||
this.fireEvent('loadcontent', code);
|
||||
}.bind(this)
|
||||
}).send();
|
||||
},
|
||||
|
||||
isLoaded: function() {
|
||||
return this.content != null;
|
||||
},
|
||||
|
||||
getID: function() {
|
||||
return 'Module-' + this.options.filename.replace(/\//g, '-');
|
||||
}
|
||||
});
|
||||
|
||||
Module.exists = function(filename) {
|
||||
return Object.some(fd.item.modules, function(mod) {
|
||||
return mod.options.filename == filename;
|
||||
});
|
||||
};
|
||||
|
||||
var Folder = new Class({
|
||||
|
||||
Extends: File,
|
||||
|
||||
options: {
|
||||
root_dir: 'l',
|
||||
name: ''
|
||||
},
|
||||
|
||||
initialize: function(pack, options) {
|
||||
this.parent(pack, options);
|
||||
|
||||
this.addEvent('destroy', function(){
|
||||
delete pack.folders[this.options.root_dir + '/' +this.options.name];
|
||||
});
|
||||
},
|
||||
|
||||
getFullName: function() {
|
||||
return this.options.name;
|
||||
},
|
||||
|
||||
getID: function() {
|
||||
return this.options.root_dir + '-'+
|
||||
this.options.name.replace(/\//g, '-');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Folder.ROOT_DIR_LIB = 'l';
|
||||
Folder.ROOT_DIR_DATA = 'd';
|
||||
|
||||
Folder.exists = function(filename, root_dir) {
|
||||
return Object.some(fd.item.folders, function(folder) {
|
||||
return (folder.options.root_dir == root_dir &&
|
||||
folder.options.name == filename);
|
||||
});
|
||||
};
|
|
@ -2,8 +2,13 @@ var Class = require('shipyard/class/Class'),
|
|||
Options = require('shipyard/class/Options'),
|
||||
Events = require('shipyard/class/Events'),
|
||||
dom = require('shipyard/dom'),
|
||||
object = require('shipyard/utils/object'),
|
||||
//Request = require('shipyard/http/Request'),
|
||||
|
||||
Module = require('../models/Module'),
|
||||
Attachment = require('../models/Attachment'),
|
||||
Folder = require('../models/Folder'),
|
||||
Package = require('../models/Package'),
|
||||
PackageRevision = require('../models/PackageRevision');
|
||||
|
||||
module.exports = new Class({
|
||||
|
@ -33,7 +38,7 @@ module.exports = new Class({
|
|||
|
||||
},
|
||||
|
||||
package: null,
|
||||
package_: null,
|
||||
|
||||
//junk
|
||||
data: {},
|
||||
|
@ -45,8 +50,8 @@ module.exports = new Class({
|
|||
|
||||
edited: 0,
|
||||
|
||||
initialize: function PackageController(package, options, editor, tabs, sidebar) {
|
||||
this.package = package;
|
||||
initialize: function PackageController(package_, options, editor, tabs, sidebar) {
|
||||
this.package_ = package_;
|
||||
this.editor = editor;
|
||||
this.tabs = tabs;
|
||||
this.sidebar = sidebar;
|
||||
|
@ -66,26 +71,26 @@ module.exports = new Class({
|
|||
|
||||
assignActions: function() {
|
||||
var controller = this,
|
||||
package = this.package;
|
||||
package_ = this.package_;
|
||||
|
||||
// All actions
|
||||
|
||||
// reset version_name (in case of reload)
|
||||
var versionEl = this.versionEl = dom.$('version_name');
|
||||
if (versionEl) {
|
||||
versionEl.set('value', package.get('version_name'));
|
||||
package.observe('version_name', function(name) {
|
||||
versionEl.set('value', package_.get('version_name'));
|
||||
package_.observe('version_name', function(name) {
|
||||
versionEl.set('value', name);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
this.revision_list_btn = dom.$('revisions_list')
|
||||
this.revision_list_btn = dom.$('revisions_list');
|
||||
this.revision_list_btn.addEvent('click', function(e) {
|
||||
e.preventDefault();
|
||||
controller.showRevisionList();
|
||||
});
|
||||
if (this.package.isAddon()) {
|
||||
if (this.package_.isAddon()) {
|
||||
this.boundTestAddon = this.testAddon.bind(this);
|
||||
this.test_el = dom.$(this.options.test_el);
|
||||
this.options.test_url = this.test_el.getElement('a').get('href');
|
||||
|
@ -101,7 +106,7 @@ module.exports = new Class({
|
|||
controller.downloadAddon();
|
||||
});
|
||||
}
|
||||
this.copy_el = dom.$(this.options.copy_el)
|
||||
this.copy_el = dom.$(this.options.copy_el);
|
||||
if (this.copy_el) {
|
||||
this.copy_el.addEvent('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
@ -114,7 +119,7 @@ module.exports = new Class({
|
|||
});
|
||||
}
|
||||
|
||||
this.packageInfoEl = dom.$(this.options.package_info_el);
|
||||
this.package_InfoEl = dom.$(this.options.package_info_el);
|
||||
|
||||
if (this.getOption('readonly')) {
|
||||
this.assignViewActions();
|
||||
|
@ -126,7 +131,7 @@ module.exports = new Class({
|
|||
assignViewActions: function() {
|
||||
var controller = this;
|
||||
|
||||
this.packageInfoEl.addEvent('click', function(e) {
|
||||
this.package_InfoEl.addEvent('click', function(e) {
|
||||
e.preventDefault();
|
||||
controller.showInfo();
|
||||
});
|
||||
|
@ -139,12 +144,12 @@ module.exports = new Class({
|
|||
controller.alertUnsavedData(e);
|
||||
});
|
||||
|
||||
this.packageInfoEl.addEvent('click', function(e) {
|
||||
this.package_InfoEl.addEvent('click', function(e) {
|
||||
e.preventDefault();
|
||||
controller.editInfo();
|
||||
});
|
||||
|
||||
if (this.package.isAddon()) {
|
||||
if (this.package_.isAddon()) {
|
||||
this.console_el = dom.$(this.options.console_el);
|
||||
this.console_el.addEvent('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
@ -171,13 +176,13 @@ module.exports = new Class({
|
|||
} else {
|
||||
this.save_el.addEvent('mouseenter', function(e) {
|
||||
controller.versionEl.focus();
|
||||
})
|
||||
});
|
||||
}
|
||||
this.revision_message_el = dom.$('revision_message');
|
||||
this.revision_message_el.addEvent('keypress', function(e) {
|
||||
//TODO: the dom Event system should make this possible
|
||||
//if (e.key == 'tab') {
|
||||
if (e.keyCode = 9) {
|
||||
if (e.keyCode == 9) {
|
||||
e.preventDefault();
|
||||
controller.save_el.focus();
|
||||
}
|
||||
|
@ -222,8 +227,7 @@ module.exports = new Class({
|
|||
// iterate by modules and instantiate Module
|
||||
this.options.modules.forEach(function(module) {
|
||||
module.readonly = this.options.readonly;
|
||||
var mod = this.modules[module.filename] = new Module(this,module);
|
||||
this.sidebar.addLib(mod);
|
||||
var mod = this.newModule(module);
|
||||
if (module.main) this.editFile(mod);
|
||||
}, this);
|
||||
},
|
||||
|
@ -232,33 +236,77 @@ module.exports = new Class({
|
|||
// iterate through attachments
|
||||
this.options.attachments.forEach(function(attachment) {
|
||||
attachment.readonly = this.options.readonly;
|
||||
var att = this.attachments[attachment.uid] = new Attachment(this,attachment);
|
||||
this.sidebar.addData(att);
|
||||
this.newAttachment(attachment);
|
||||
}, this);
|
||||
},
|
||||
|
||||
instantiate_dependencies: function() {
|
||||
// iterate through attachments
|
||||
this.options.dependencies.forEach(function(plugin) {
|
||||
plugin.readonly = this.options.readonly;
|
||||
var lib = this.libraries[plugin.id_number] = new Library(this,plugin);
|
||||
this.sidebar.addPlugin(lib);
|
||||
this.newDependency(plugin);
|
||||
}, this);
|
||||
},
|
||||
|
||||
instantiate_folders: function() {
|
||||
this.options.folders.forEach(function(folder) {
|
||||
folder.append = true;
|
||||
var key = folder.root_dir + '/' + folder.name;
|
||||
var f = this.folders[key] = new Folder(this, folder);
|
||||
if (folder.root_dir == Folder.ROOT_DIR_LIB) {
|
||||
this.sidebar.addLib(f);
|
||||
} else if (folder.root_dir == Folder.ROOT_DIR_DATA) {
|
||||
this.sidebar.addData(f);
|
||||
}
|
||||
this.newFolder(folder);
|
||||
}, this);
|
||||
},
|
||||
|
||||
newModule: function(data) {
|
||||
var mod = new Module(data);
|
||||
this.modules[mod.get('uid')] = mod;
|
||||
this.sidebar.addLib(mod);
|
||||
this.editor.registerItem(mod.get('uid'), mod);
|
||||
var controller =
|
||||
mod.addEvent('destroy', function() {
|
||||
delete controller.modules[this.get('uid')];
|
||||
});
|
||||
return mod;
|
||||
},
|
||||
|
||||
newAttachment: function(data) {
|
||||
if (!data.id) data.id = data.uid;
|
||||
var att = new Attachment(data);
|
||||
this.attachments[att.get('uid')] = att;
|
||||
this.sidebar.addData(att);
|
||||
this.editor.registerItem(att.get('uid'), att);
|
||||
|
||||
var controller = this;
|
||||
att.addEvent('destroy', function() {
|
||||
delete controller.attachments[this.get('uid')];
|
||||
});
|
||||
return att;
|
||||
},
|
||||
|
||||
newFolder: function(data) {
|
||||
var folder = new Folder(data);
|
||||
this.folders[folder.get('uid')] = folder;
|
||||
var rootDir = folder.get('root_dir');
|
||||
|
||||
if (rootDir == Folder.ROOT_DIR_LIB) {
|
||||
this.sidebar.addLib(folder);
|
||||
} else if (rootDir == Folder.ROOT_DIR_DATA) {
|
||||
this.sidebar.addData(folder);
|
||||
}
|
||||
|
||||
var controller = this;
|
||||
folder.addEvent('destroy', function() {
|
||||
delete controller.folders[this.get('uid')];
|
||||
});
|
||||
},
|
||||
|
||||
newDependendy: function(data) {
|
||||
var lib = new Package(plugin);
|
||||
this.dependencies[lib.get('uid')] = lib;
|
||||
this.sidebar.addPlugin(lib);
|
||||
|
||||
var controller = this;
|
||||
lib.addEvent('destroy', function() {
|
||||
delete controller[this.get('uid')];
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
showRevisionList: function() {
|
||||
new Request({
|
||||
|
@ -285,7 +333,7 @@ module.exports = new Class({
|
|||
}
|
||||
}
|
||||
showVersionsEl.addEvent('change', function(e) {
|
||||
toggleVersionsOnly()
|
||||
toggleVersionsOnly();
|
||||
});
|
||||
toggleVersionsOnly();
|
||||
}
|
||||
|
@ -309,7 +357,7 @@ module.exports = new Class({
|
|||
var controller = this;
|
||||
|
||||
/*PackageRevision.find({
|
||||
conditions: { package: this.package.get('pk') },
|
||||
conditions: { package: this.package_.get('pk') },
|
||||
options: { limit: 1, order_by: '-revision_number' },
|
||||
callback: function(r) {
|
||||
r = r[0];
|
||||
|
@ -324,8 +372,8 @@ module.exports = new Class({
|
|||
method: 'get',
|
||||
url: this.options.check_latest_url,
|
||||
onSuccess: function(response) {
|
||||
if (failCallback && controller.package.get('revision_number') < response.revision_number) {
|
||||
failCallback.call()
|
||||
if (failCallback && controller.package_.get('revision_number') < response.revision_number) {
|
||||
failCallback.call();
|
||||
}
|
||||
}.bind(this)
|
||||
}).send();
|
||||
|
@ -432,12 +480,12 @@ module.exports = new Class({
|
|||
'class': 'spinner-img spinner-16'
|
||||
},
|
||||
maskBorder: false
|
||||
}).show()
|
||||
}).show();
|
||||
fd.tests[this.options.hashtag] = {
|
||||
spinner: spinner
|
||||
};
|
||||
var data = this.data || {};
|
||||
data['hashtag'] = this.options.hashtag;
|
||||
data.hashtag = this.options.hashtag;
|
||||
this._test_request = new Request.JSON({
|
||||
url: this.options.test_url,
|
||||
data: data,
|
||||
|
@ -487,7 +535,7 @@ module.exports = new Class({
|
|||
var controller = this;
|
||||
this.tabs.addEvent('select', function(tab) {
|
||||
controller.onTabSelect(tab);
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
onSidebarSelect: function(file) {
|
||||
|
@ -515,24 +563,24 @@ module.exports = new Class({
|
|||
|
||||
editFile: function(file) {
|
||||
this.tabs.selectTab(file);
|
||||
this.editor.switchTo(file).focus();
|
||||
this.editor.switchTo(file.get('uid')).focus();
|
||||
},
|
||||
|
||||
showAttachmentModal: function(file) {
|
||||
var template_start = '<div id="attachment_view"><h3>'
|
||||
+file.options.filename+'</h3><div class="UI_Modal_Section">';
|
||||
var template_end = '</div><div class="UI_Modal_Actions"><ul><li>'
|
||||
+'<input type="reset" value="Close" class="closeModal"/>'
|
||||
+'</li></ul></div></div>';
|
||||
var template_middle = 'Download <a href="'
|
||||
+file.options.get_url
|
||||
+'">'
|
||||
+file.options.filename
|
||||
+'</a>';
|
||||
var template_start = '<div id="attachment_view"><h3>'+
|
||||
file.options.filename+'</h3><div class="UI_Modal_Section">';
|
||||
var template_end = '</div><div class="UI_Modal_Actions"><ul><li>'+
|
||||
'<input type="reset" value="Close" class="closeModal"/>'+
|
||||
'</li></ul></div></div>';
|
||||
var template_middle = 'Download <a href="'+
|
||||
file.options.get_url+
|
||||
'">'+
|
||||
file.options.filename+
|
||||
'</a>';
|
||||
var spinner, img;
|
||||
if (file.is_image()) {
|
||||
template_middle += '<p></p>';
|
||||
var img = new Element('img', { src: file.options.get_url });
|
||||
var spinner;
|
||||
img = new Element('img', { src: file.options.get_url });
|
||||
img.addEvent('load', function() {
|
||||
if (spinner) spinner.destroy();
|
||||
modal.position();
|
||||
|
@ -614,8 +662,9 @@ module.exports = new Class({
|
|||
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === 4) {
|
||||
var response;
|
||||
try {
|
||||
var response = JSON.decode(xhr.responseText);
|
||||
response = JSON.decode(xhr.responseText);
|
||||
} catch(ex) {
|
||||
$log(ex);
|
||||
return;
|
||||
|
@ -657,11 +706,11 @@ module.exports = new Class({
|
|||
}
|
||||
}
|
||||
};
|
||||
$log('FD: DEBUG: uploading ' + file.name)
|
||||
$log('FD: DEBUG: uploading ' + file.name);
|
||||
data.append('upload_attachment', file);
|
||||
xhr.open('POST', this.options.upload_attachment_url);
|
||||
xhr.setRequestHeader('X-File-Name', file.name);
|
||||
xhr.setRequestHeader('X-File-Size', file.fileSize)
|
||||
xhr.setRequestHeader('X-File-Size', file.fileSize);
|
||||
xhr.setRequestHeader("X-CSRFToken", Cookie.read('csrftoken'));
|
||||
xhr.send(data);
|
||||
},
|
||||
|
@ -697,17 +746,15 @@ module.exports = new Class({
|
|||
fd.setURIRedirect(response.view_url);
|
||||
that.registerRevision(response);
|
||||
fd.message.alert(response.message_title, response.message);
|
||||
that.attachments[response.uid] = new Attachment(that, {
|
||||
append: true,
|
||||
active: true,
|
||||
var att = that.newAttachment({
|
||||
filename: response.filename,
|
||||
ext: response.ext,
|
||||
author: response.author,
|
||||
code: response.code,
|
||||
content: response.code,
|
||||
get_url: response.get_url,
|
||||
uid: response.uid,
|
||||
type: response.ext
|
||||
pk: response.uid
|
||||
});
|
||||
that.editFile(att);
|
||||
}
|
||||
}).send();
|
||||
},
|
||||
|
@ -808,15 +855,14 @@ module.exports = new Class({
|
|||
this.registerRevision(response);
|
||||
fd.message.alert(response.message_title, response.message);
|
||||
// initiate new Module
|
||||
var mod = new Module(this,{
|
||||
append: true,
|
||||
var mod = this.newModule({
|
||||
active: true,
|
||||
filename: response.filename,
|
||||
author: response.author,
|
||||
code: response.code,
|
||||
content: response.code,
|
||||
get_url: response.get_url
|
||||
});
|
||||
this.modules[response.filename] = mod;
|
||||
this.editFile(mod);
|
||||
}.bind(this)
|
||||
}).send();
|
||||
},
|
||||
|
@ -844,7 +890,7 @@ module.exports = new Class({
|
|||
|
||||
var mod = this.modules[oldName];
|
||||
var modId = mod.getID();
|
||||
mod.setOptions({
|
||||
mod.set({
|
||||
filename: response.filename,
|
||||
get_url: response.get_url
|
||||
});
|
||||
|
@ -901,9 +947,9 @@ module.exports = new Class({
|
|||
this.attachments[uid].destroy();
|
||||
}, this);
|
||||
response.removed_dirs.forEach(function(name) {
|
||||
controller.sidebar.removeFile(name, 'd')
|
||||
controller.sidebar.removeFile(name, 'd');
|
||||
}, this);
|
||||
controller.sidebar.removeFile(response.foldername, 'd')
|
||||
controller.sidebar.removeFile(response.foldername, 'd');
|
||||
}.bind(this)
|
||||
}).send();
|
||||
},
|
||||
|
@ -929,7 +975,7 @@ module.exports = new Class({
|
|||
this.modules[filename].destroy();
|
||||
}, this);
|
||||
response.removed_dirs.forEach(function(name) {
|
||||
controller.sidebar.removeFile(name, 'l')
|
||||
controller.sidebar.removeFile(name, 'l');
|
||||
}, this);
|
||||
|
||||
}.bind(this)
|
||||
|
@ -956,9 +1002,8 @@ module.exports = new Class({
|
|||
fd.setURIRedirect(response.view_url);
|
||||
this.registerRevision(response);
|
||||
fd.message.alert(response.message_title, response.message);
|
||||
this.folders[root_dir + '/' + response.name] = new Folder(this, {
|
||||
append: true,
|
||||
name: response.name,
|
||||
this.newFolder({
|
||||
name: reponse.name,
|
||||
root_dir: root_dir
|
||||
});
|
||||
}.bind(this)
|
||||
|
@ -1006,7 +1051,7 @@ module.exports = new Class({
|
|||
// set data changed by save
|
||||
this.registerRevision(response);
|
||||
fd.message.alert(response.message_title, response.message);
|
||||
this.libraries[response.library_id_number] = new Library(this, {
|
||||
this.newDependency({
|
||||
full_name: response.library_full_name,
|
||||
id_number: response.library_id_number,
|
||||
library_name: response.library_name,
|
||||
|
@ -1101,6 +1146,25 @@ module.exports = new Class({
|
|||
}).send();
|
||||
},
|
||||
|
||||
moduleExists: function(filename) {
|
||||
return object.some(this.modules, function(mod) {
|
||||
return mod.get('filename') === filename;
|
||||
});
|
||||
},
|
||||
|
||||
attachmentExists: function(filename) {
|
||||
return object.some(this.attachments, function(att) {
|
||||
return att.get('fullName') === filename;
|
||||
});
|
||||
},
|
||||
|
||||
folderExists: function(name, rootDir) {
|
||||
return object.some(this.folders, function(folder) {
|
||||
return (folder.get('root_dir') === rootDir &&
|
||||
folder.get('name') === name);
|
||||
});
|
||||
},
|
||||
|
||||
/*
|
||||
* Method: makePublic
|
||||
* activate a package
|
||||
|
@ -1116,7 +1180,7 @@ module.exports = new Class({
|
|||
spinnerTarget: activateButton,
|
||||
spinnerOptions: {
|
||||
img: {
|
||||
class: 'spinner-img spinner-16'
|
||||
'class': 'spinner-img spinner-16'
|
||||
},
|
||||
maskBorder: false
|
||||
},
|
||||
|
@ -1144,7 +1208,7 @@ module.exports = new Class({
|
|||
spinnerTarget: deactivateButton,
|
||||
spinnerOptions: {
|
||||
img: {
|
||||
class: 'spinner-img spinner-16'
|
||||
'class': 'spinner-img spinner-16'
|
||||
},
|
||||
maskBorder: false
|
||||
},
|
||||
|
@ -1198,7 +1262,7 @@ module.exports = new Class({
|
|||
$log(key + ': ' + value);
|
||||
$(key).value = value;
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
/*
|
||||
|
@ -1232,8 +1296,8 @@ module.exports = new Class({
|
|||
}
|
||||
}, this);
|
||||
Object.each(this.attachments, function(attachment, uid) {
|
||||
var att = this.editor.items[uid
|
||||
+ attachment.options.code_editor_suffix];
|
||||
var att = this.editor.items[uid +
|
||||
attachment.options.code_editor_suffix];
|
||||
if (att.content && att.changed) {
|
||||
this.data[attachment.options.uid] = att.content;
|
||||
}
|
||||
|
@ -1261,7 +1325,7 @@ module.exports = new Class({
|
|||
},
|
||||
onSuccess: function(response) {
|
||||
// set the redirect data to view_url of the new revision
|
||||
$log('FD: DEBUG: Save succeeded')
|
||||
$log('FD: DEBUG: Save succeeded');
|
||||
if (response.full_name) {
|
||||
$('package-info-name').set('text', response.full_name);
|
||||
this.options.full_name = response.full_name;
|
||||
|
@ -1287,7 +1351,7 @@ module.exports = new Class({
|
|||
this.data = {};
|
||||
this.options.package_info_form_elements.each(function(key) {
|
||||
if (response[key] != null) {
|
||||
this.data[key] = response[key]
|
||||
this.data[key] = response[key];
|
||||
}
|
||||
}, this);
|
||||
if (fd.editPackageInfoModal) fd.editPackageInfoModal.destroy();
|
||||
|
@ -1383,7 +1447,7 @@ module.exports = new Class({
|
|||
that.toggleShortcutsModal();
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
this.keyboard.manage(this.sidebar.keyboard);
|
||||
this.keyboard.activate();
|
||||
this.sidebar.keyboard.deactivate();
|
||||
|
@ -1393,8 +1457,9 @@ module.exports = new Class({
|
|||
},
|
||||
|
||||
toggleShortcutsModal: function() {
|
||||
this._shortcutsModal ?
|
||||
this.hideShortcuts() :
|
||||
if (this._shortcutsModal)
|
||||
this.hideShortcuts();
|
||||
else
|
||||
this.showShortcuts();
|
||||
},
|
||||
|
||||
|
@ -1411,13 +1476,13 @@ module.exports = new Class({
|
|||
shortcuts.push('<strong>Tree</strong>');
|
||||
this.sidebar.keyboard.getShortcuts().forEach(buildLines);
|
||||
|
||||
this._shortcutsModal = fd.displayModal('<h3>Keyboard Shortcuts</h3>'
|
||||
+'<div class="UI_Modal_Section"><p>'
|
||||
+shortcuts.join('</p><p>')
|
||||
+'</p></div>'
|
||||
this._shortcutsModal = fd.displayModal('<h3>Keyboard Shortcuts</h3>'+
|
||||
'<div class="UI_Modal_Section"><p>'+
|
||||
shortcuts.join('</p><p>')+
|
||||
'</p></div>'
|
||||
);
|
||||
this._shortcutsModal.addEvent('destroy', function() {
|
||||
this._shortcutsModal = null
|
||||
this._shortcutsModal = null;
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ module.exports = new Class({
|
|||
if(file.changed) {
|
||||
fd.showQuestion({
|
||||
title: 'Lose unsaved changes?',
|
||||
message: 'The tab "'+file.getShortName()+'" that you are trying to close has unsaved changes.',
|
||||
message: 'The tab "'+file.get('shortName')+'" that you are trying to close has unsaved changes.',
|
||||
buttons: [
|
||||
{
|
||||
'type': 'reset',
|
||||
|
@ -83,7 +83,7 @@ module.exports = new Class({
|
|||
addTab: function(file) {
|
||||
var controller = this;
|
||||
var tab = new tabs.Tab(this.tabs, {
|
||||
title: file.getShortName()
|
||||
title: file.get('shortName')
|
||||
});
|
||||
|
||||
function change() {
|
||||
|
|
|
@ -19,6 +19,10 @@ module.exports = new Class({
|
|||
fields: {
|
||||
url: fields.TextField(),
|
||||
data: fields.TextField()
|
||||
},
|
||||
|
||||
uid: function uid() {
|
||||
return this.get('pk');
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
var Class = require('shipyard/class/Class'),
|
||||
Model = require('shipyard/model/Model'),
|
||||
fields = require('shipyard/model/fields'),
|
||||
Syncable = require('shipyard/sync/Syncable');
|
||||
Syncable = require('shipyard/sync/Syncable'),
|
||||
Request = require('shipyard/http/Request'),
|
||||
string = require('shipyard/utils/string');
|
||||
|
||||
var File = module.exports = new Class({
|
||||
|
||||
|
@ -14,7 +16,12 @@ var File = module.exports = new Class({
|
|||
id: fields.NumberField(),
|
||||
filename: fields.TextField({ required: true }),
|
||||
ext: fields.TextField({ 'default': 'js' }),
|
||||
content: fields.TextField()
|
||||
content: fields.TextField(),
|
||||
main: fields.BooleanField({ 'default': false, write: false }),
|
||||
readonly: fields.BooleanField({ 'default': false, write: false }),
|
||||
|
||||
url: fields.TextField({ write: false }),
|
||||
get_url: fields.TextField({ write: false })
|
||||
},
|
||||
|
||||
shortName: function() {
|
||||
|
@ -32,10 +39,63 @@ var File = module.exports = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
uid: function() {
|
||||
//TODO: this should be the unique hash from the new API
|
||||
return this._uid || (this._uid = string.uniqueID());
|
||||
},
|
||||
|
||||
isEditable: function() {
|
||||
return this.constructor.EDITABLE_EXTS.indexOf(this.get('ext')) !== -1;
|
||||
},
|
||||
|
||||
//TODO: Shipyard Models should probably has a isDirty API
|
||||
setChanged: function(isChanged) {
|
||||
this.changed = isChanged;
|
||||
if (isChanged) {
|
||||
this.fireEvent('change');
|
||||
} else {
|
||||
this.fireEvent('reset');
|
||||
}
|
||||
},
|
||||
|
||||
loadContent: function(callback) {
|
||||
var file = this;
|
||||
var spinnerEl;
|
||||
return new Request({
|
||||
method: 'get',
|
||||
url: this.get('get_url'),
|
||||
useSpinner: !!spinnerEl,
|
||||
spinnerTarget: spinnerEl,
|
||||
spinnerOptions: {
|
||||
img: {
|
||||
'class': 'spinner-img spinner-16'
|
||||
},
|
||||
maskBorder: false
|
||||
},
|
||||
onSuccess: function(text) {
|
||||
var content = text || '';
|
||||
file.original_content = content;
|
||||
file.set('content', content);
|
||||
file.fireEvent('loadcontent', content);
|
||||
if (callback) callback.call(this, content);
|
||||
}
|
||||
}).send();
|
||||
|
||||
},
|
||||
|
||||
isLoaded: function() {
|
||||
return this.get('content') != null;
|
||||
},
|
||||
|
||||
toString: function() {
|
||||
return this.get('fullName');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
File.EDITABLE_EXTS = ['js', 'html', 'css', 'txt', 'json', 'md'];
|
||||
|
||||
var sanitizeRE = /[^a-zA-Z0-9=!@#\$%\^&\(\)\+\-_\/\.]+/g;
|
||||
File.sanitize = function(name) {
|
||||
return name.replace(sanitizeRE, '-');
|
||||
};
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
var Class = require('shipyard/class/Class'),
|
||||
Model = require('shipyard/model/Model'),
|
||||
fields = require('shipyard/model/fields'),
|
||||
Syncable = require('shipyard/sync/Syncable'),
|
||||
string = require('shipyard/utils/string');
|
||||
|
||||
var Folder = module.exports = new Class({
|
||||
|
||||
Extends: Model,
|
||||
|
||||
Implements: Syncable,
|
||||
|
||||
fields: {
|
||||
name: fields.TextField({ required: true }),
|
||||
root_dir: fields.TextField({ required: true }) //ChoiceField
|
||||
},
|
||||
|
||||
shortName: function() {
|
||||
return this.get('name');
|
||||
},
|
||||
|
||||
fullName: function() {
|
||||
return this.get('name');
|
||||
},
|
||||
|
||||
uid: function() {
|
||||
return this.get('root_dir') + '/' + this.get('name');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Folder.ROOT_DIR_LIB = 'l';
|
||||
Folder.ROOT_DIR_DATA = 'd';
|
|
@ -1,7 +1,8 @@
|
|||
var Class = require('shipyard/class/Class'),
|
||||
File = require('./File'),
|
||||
fields = require('shipyard/model/fields'),
|
||||
ServerSync = require('shipyard/sync/Server');
|
||||
ServerSync = require('shipyard/sync/Server'),
|
||||
Request = require('shipyard/http/Request');
|
||||
|
||||
module.exports = new Class({
|
||||
|
||||
|
@ -15,6 +16,35 @@ module.exports = new Class({
|
|||
},
|
||||
|
||||
fields: {
|
||||
},
|
||||
|
||||
uid: function() {
|
||||
return this.get('filename');
|
||||
},
|
||||
|
||||
loadContent: function(callback) {
|
||||
var spinnerEl,
|
||||
file = this;
|
||||
return new Request({
|
||||
method: 'get',
|
||||
url: this.get('get_url'),
|
||||
useSpinner: !!spinnerEl,
|
||||
spinnerTarget: spinnerEl,
|
||||
spinnerOptions: {
|
||||
img: {
|
||||
'class': 'spinner-img spinner-16'
|
||||
},
|
||||
maskBorder: false
|
||||
},
|
||||
onSuccess: function(text) {
|
||||
var mod = JSON.parse(text);
|
||||
var code = mod.code || '';
|
||||
this.original_content = code;
|
||||
this.set('content', code);
|
||||
this.fireEvent('loadcontent', code);
|
||||
if (callback) callback.call(this, code);
|
||||
}.bind(this)
|
||||
}).send();
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -32,13 +32,33 @@ var Package = module.exports = new Class({
|
|||
version_name: fields.TextField(),
|
||||
revision_number: fields.NumberField(),
|
||||
|
||||
latest: fields.NumberField(), // a FK to PackageRevision
|
||||
latest: fields.NumberField() // a FK to PackageRevision
|
||||
|
||||
// modules: FK from Module
|
||||
// attachments: FK from Attachment
|
||||
// dependencies: ManyToManyField('self')
|
||||
},
|
||||
|
||||
uid: function() {
|
||||
return this.get('id_number');
|
||||
},
|
||||
|
||||
shortName: function() {
|
||||
return this.get('name');
|
||||
},
|
||||
|
||||
fullName: function() {
|
||||
return this.get('full_name');
|
||||
},
|
||||
|
||||
storeNewVersion: function(version_data) {
|
||||
this._latest_version = version_data;
|
||||
},
|
||||
|
||||
retrieveNewVersion: function() {
|
||||
return this._latest_version;
|
||||
},
|
||||
|
||||
isAddon: function isAddon() {
|
||||
return this.get('type') === this.constructor.TYPE_ADDON;
|
||||
},
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
"shipyard": {
|
||||
"app": "./",
|
||||
"mini_require": true,
|
||||
"min": "../editor-min.js",
|
||||
"target": "../editor-min.js",
|
||||
"min": false,
|
||||
|
||||
"test": "./tests"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
var File = require('../../models/File');
|
||||
|
||||
module.exports = {
|
||||
|
||||
'File.sanitize': function(it, setup) {
|
||||
it('should clean out unwanted characters', function(expect) {
|
||||
var val = File.sanitize('<script>window.open()');
|
||||
expect(val).toBe('-script-window.open()');
|
||||
});
|
||||
|
||||
it('should not strip plus characters', function(expect) {
|
||||
var val = File.sanitize('unload+');
|
||||
expect(val).toBe('unload+');
|
||||
});
|
||||
}
|
||||
};
|
|
@ -1,4 +1,6 @@
|
|||
var Module = require('../../models/Module');
|
||||
var Module = require('../../models/Module'),
|
||||
mockXHR = require('shipyard/test/mockXHR'),
|
||||
Spy = require('shipyard/test/Spy');
|
||||
|
||||
module.exports = {
|
||||
'Module': function(it, setup) {
|
||||
|
@ -14,6 +16,19 @@ module.exports = {
|
|||
|
||||
m.set('filename', 'events/key.down');
|
||||
expect(m.get('shortName')).toBe('key.down.js');
|
||||
})
|
||||
});
|
||||
|
||||
it('should be able to loadContent', function(expect) {
|
||||
mockXHR('test content');
|
||||
var m = new Module();
|
||||
var fn = new Spy;
|
||||
m.addEvent('loadcontent', fn);
|
||||
m.loadContent(function(content) {
|
||||
expect(content).toBe('test content');
|
||||
expect(m.get('content')).toBe('test content');
|
||||
expect(fn.getCallCount()).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@
|
|||
*/
|
||||
var Class = require('shipyard/class/Class'),
|
||||
Events = require('shipyard/class/Events'),
|
||||
Options = require('shipyard/class/Options')
|
||||
Options = require('shipyard/class/Options'),
|
||||
object = require('shipyard/utils/object');
|
||||
|
||||
// globals: Element, Spinner, Element.addVolatileEvent, fd
|
||||
// globals: Element, Spinner, fd
|
||||
|
||||
var FDEditor = module.exports = new Class({
|
||||
|
||||
|
@ -45,8 +45,8 @@ var FDEditor = module.exports = new Class({
|
|||
});
|
||||
},
|
||||
|
||||
registerItem: function(item){
|
||||
this.items[item.uid] = item;
|
||||
registerItem: function(uid, item){
|
||||
this.items[uid] = item;
|
||||
},
|
||||
|
||||
getItem: function(uid){
|
||||
|
@ -62,38 +62,39 @@ var FDEditor = module.exports = new Class({
|
|||
|
||||
activateItem: function(item){
|
||||
// activate load and hook events
|
||||
var editor = this;
|
||||
this.current = item;
|
||||
this.current.active = true;
|
||||
if (!this.current.isLoaded()) {
|
||||
this.spinner.show();
|
||||
this.setContent('', true);
|
||||
this.current.addVolatileEvent('loadcontent', function(content) {
|
||||
//if item == this.current still
|
||||
if (item == this.current) {
|
||||
this.setContent(content);
|
||||
this.spinner.hide();
|
||||
this.current.loadContent(function(content) {
|
||||
if (item == editor.current) {
|
||||
editor.setContent(content);
|
||||
editor.spinner.hide();
|
||||
}
|
||||
//else another file has become active
|
||||
}.bind(this));
|
||||
this.current.loadContent();
|
||||
});
|
||||
} else {
|
||||
this.setContent(this.current.content);
|
||||
this.setContent(this.current.get('content'));
|
||||
this.spinner.hide();
|
||||
}
|
||||
if (this.current.options.readonly) {
|
||||
if (this.current.get('readonly')) {
|
||||
this.setReadOnly();
|
||||
} else {
|
||||
this.setEditable();
|
||||
}
|
||||
this.setSyntax(this.current.options.type);
|
||||
this.setSyntax(this.current.get('ext'));
|
||||
},
|
||||
|
||||
switchTo: function(item){
|
||||
$log('FD: DEBUG: FDEditor.switchTo ' + item.uid);
|
||||
switchTo: function(uid){
|
||||
$log('FD: DEBUG: FDEditor.switchTo ' + uid);
|
||||
var self = this;
|
||||
this.switching = true;
|
||||
if (!this.getItem(item.uid)) {
|
||||
this.registerItem(item);
|
||||
var item = this.getItem(uid);
|
||||
if (!item) {
|
||||
//this.registerItem(item);
|
||||
$log('no item wtf');
|
||||
}
|
||||
if (this.current) {
|
||||
this.deactivateCurrent();
|
||||
|
@ -103,7 +104,7 @@ var FDEditor = module.exports = new Class({
|
|||
},
|
||||
|
||||
dumpCurrent: function() {
|
||||
this.current.content = this.getContent();
|
||||
this.current.set('content', this.getContent());
|
||||
return this;
|
||||
},
|
||||
|
||||
|
@ -126,13 +127,13 @@ var FDEditor = module.exports = new Class({
|
|||
item.setChanged(false);
|
||||
item.change_hooked = false;
|
||||
// refresh original content
|
||||
item.original_content = item.content;
|
||||
item.original_content = item.get('content');
|
||||
});
|
||||
this.hookChangeIfNeeded();
|
||||
},
|
||||
|
||||
hookChangeIfNeeded: function() {
|
||||
if (!this.current.options.readonly) {
|
||||
if (!this.current.get('readonly')) {
|
||||
if (!this.current.changed && !this.change_hooked) {
|
||||
this.hookChange();
|
||||
} else if (this.current.changed && this.change_hooked) {
|
||||
|
@ -156,8 +157,8 @@ var FDEditor = module.exports = new Class({
|
|||
if (!this.switching && this.getContent() != this.current.original_content) {
|
||||
this.current.setChanged(true);
|
||||
this.fireEvent('change');
|
||||
$log('FD: DEBUG: changed, code is considered dirty and will remain'
|
||||
+'be treated as such even if changes are reverted');
|
||||
$log('DEBUG: changed, code is considered dirty and will remain'+
|
||||
'be treated as such even if changes are reverted');
|
||||
this.unhookChange();
|
||||
} else if (!this.switching && this.current.changed) {
|
||||
this.current.setChanged(false);
|
||||
|
|
|
@ -2,7 +2,10 @@ var /*Class = require('shipyard/class'),
|
|||
shipyard/class only lets Class extends from other shipyard/class,
|
||||
and FileTree extends from Tree (which is a regular Moo Class)
|
||||
*/
|
||||
object = require('shipyard/utils/object');
|
||||
object = require('shipyard/utils/object'),
|
||||
|
||||
Module = require('../models/Module'),
|
||||
Attachment = require('../models/Attachment');
|
||||
|
||||
// globals: Class, Tree, Collapse.LocalStorage, Element, String.implement
|
||||
|
||||
|
@ -28,7 +31,7 @@ var FileTree = module.exports = new Class({
|
|||
|
||||
// if container is null, container will default to the Tree el
|
||||
// "false" will cancel the container
|
||||
container: true,
|
||||
container: true
|
||||
//onAddBranch: function(el, attributes, target){}
|
||||
//onRenameStart: function(li, span){}
|
||||
//onRenameComplete: function(li, span){}
|
||||
|
@ -181,9 +184,9 @@ var FileTree = module.exports = new Class({
|
|||
label.store('$blur', function blur(e) {
|
||||
label.removeEvent('blur', blur);
|
||||
this.renameBranchCancel(element);
|
||||
}.bind(this))
|
||||
}.bind(this));
|
||||
|
||||
label.addEvent('blur', label.retrieve('$blur'))
|
||||
label.addEvent('blur', label.retrieve('$blur'));
|
||||
|
||||
hasExtension = hasExtension || !!text.getFileExtension();
|
||||
|
||||
|
@ -246,7 +249,7 @@ var FileTree = module.exports = new Class({
|
|||
|
||||
li.set('name', text);
|
||||
li.set('title', text);
|
||||
var path = this.getFullPath(li)
|
||||
var path = this.getFullPath(li);
|
||||
li.set('path', path);
|
||||
|
||||
|
||||
|
@ -265,13 +268,17 @@ var FileTree = module.exports = new Class({
|
|||
addPath: function(obj, options){
|
||||
options = options || {};
|
||||
var suffix = options.suffix || '',
|
||||
splitted = obj.getFullName().split('/'),
|
||||
splitted = obj.get('fullName').split('/'),
|
||||
elements = Array.clone(splitted),
|
||||
end = splitted.length - 1,
|
||||
selector = '',
|
||||
el,
|
||||
url = options.url,
|
||||
target = options.target,
|
||||
id_prefix = this.options.id_prefix;
|
||||
id_prefix = this.options.id_prefix,
|
||||
rel = (obj instanceof Module || obj instanceof Attachment) ?
|
||||
'file':
|
||||
'directory';
|
||||
|
||||
if (id_prefix) {
|
||||
id_prefix += '-';
|
||||
|
@ -282,12 +289,12 @@ var FileTree = module.exports = new Class({
|
|||
if (i == end){
|
||||
var previous = elements[i - 1] ? elements[i - 1].getElement('ul') : (options.target.getElement('ul') || options.target);
|
||||
el = elements[i] = previous.getChildren(selector += 'li[title='+ name + suffix +'] ')[0] || this.addBranch({
|
||||
'title': obj.getShortName(),
|
||||
'name': obj.getShortName(),
|
||||
'title': obj.get('shortName'),
|
||||
'name': obj.get('shortName'),
|
||||
'path': path,
|
||||
'url': obj.options.url,
|
||||
'id': obj.getID(),
|
||||
'rel': obj.options.type ? 'file' : 'directory',
|
||||
'url': url,
|
||||
'id': options.id,
|
||||
'rel': rel,
|
||||
'class': 'UI_File_Normal' + (options.nodrag ? ' nodrag' : '')
|
||||
}, previous, options);
|
||||
|
||||
|
|
|
@ -2,7 +2,10 @@ var Class = require('shipyard/class/Class'),
|
|||
Events = require('shipyard/class/Events'),
|
||||
Options = require('shipyard/class/Options'),
|
||||
object = require('shipyard/utils/object'),
|
||||
string = require('shipyard/utils/string'),
|
||||
|
||||
File = require('../models/File'),
|
||||
Folder = require('../models/Folder'),
|
||||
FileTree = require('./FileTree');
|
||||
|
||||
// globals: $, FlightDeck.Keyboard, fd.item
|
||||
|
@ -137,7 +140,7 @@ var Sidebar = module.exports = new Class({
|
|||
sidebarEl = $(this);
|
||||
|
||||
// highlight branch on click
|
||||
sidebarEl.addEvent('click:relay(.{file_listing_class} li:not(.top_branch) .label:not([contenteditable="true"]))'.substitute(this.options), function(e) {
|
||||
sidebarEl.addEvent('click:relay(.{file_listing_class} li:not(.top_branch) .label:not([contenteditable="true"]))'.substitute(this.options), function(e, label) {
|
||||
that.selectFile($(e.target).getParent('li'));
|
||||
});
|
||||
|
||||
|
@ -199,7 +202,7 @@ var Sidebar = module.exports = new Class({
|
|||
},
|
||||
|
||||
renameFile: function(file, fullpath) {
|
||||
var pack = fd.getItem();
|
||||
var pack = fd.item;
|
||||
if (file instanceof Module) {
|
||||
pack.renameModule(file.options.filename, fullpath);
|
||||
} else if (file instanceof Attachment) {
|
||||
|
@ -213,26 +216,39 @@ var Sidebar = module.exports = new Class({
|
|||
el;
|
||||
|
||||
el = this.getBranchFromFile(file);
|
||||
delete this.uids[file.get('uid')];
|
||||
if (el) {
|
||||
tree.removeBranch(el);
|
||||
}
|
||||
},
|
||||
|
||||
uids: {},
|
||||
|
||||
addFileToTree: function(treeName, file) {
|
||||
var tree = this.trees[treeName],
|
||||
that = this;
|
||||
that = this,
|
||||
isFile = file instanceof File;
|
||||
|
||||
if (!tree) {
|
||||
this.buildTree();
|
||||
tree = this.trees[treeName];
|
||||
}
|
||||
|
||||
var url;
|
||||
try {
|
||||
url = file.get('url');
|
||||
} catch(dontCare) {}
|
||||
|
||||
var id = string.uniqueID();
|
||||
this.uids[file.get('uid')] = id;
|
||||
|
||||
var options = {
|
||||
target: $(tree).getElement('.top_branch'),
|
||||
url: file.options.url
|
||||
url: url,
|
||||
id: id
|
||||
};
|
||||
|
||||
if (!this.options.editable || file.options.main) {
|
||||
if (!this.options.editable || (isFile && file.get('main'))) {
|
||||
options.add = false
|
||||
options.edit = false;
|
||||
options.remove = false;
|
||||
|
@ -264,7 +280,7 @@ var Sidebar = module.exports = new Class({
|
|||
//check all of element's parents for Folders, destroy them
|
||||
this.silentlyRemoveFolders(element);
|
||||
|
||||
if((file.options.active || file.options.main) && file.is_editable()) {
|
||||
if(isFile && (file.active || file.get('main')) && file.isEditable()) {
|
||||
this.setSelectedFile(element);
|
||||
}
|
||||
}.protect(),
|
||||
|
@ -408,17 +424,17 @@ var Sidebar = module.exports = new Class({
|
|||
'irreversible': true,
|
||||
'callback': function() {
|
||||
if (file instanceof Module) {
|
||||
fd.getItem().removeModule(file);
|
||||
fd.item.removeModule(file);
|
||||
} else if (file instanceof Attachment) {
|
||||
fd.getItem().removeAttachment(file);
|
||||
fd.item.removeAttachment(file);
|
||||
} else if (file instanceof Library) {
|
||||
fd.getItem().removeLibrary(file);
|
||||
fd.item.removeLibrary(file);
|
||||
} else if (file instanceof Folder) {
|
||||
fd.getItem().removeFolder(file);
|
||||
fd.item.removeFolder(file);
|
||||
} else if (fileType == Module) {
|
||||
fd.getItem().removeModules(file);
|
||||
fd.item.removeModules(file);
|
||||
} else if (fileType == Attachment) {
|
||||
fd.getItem().removeAttachments(file);
|
||||
fd.item.removeAttachments(file);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -441,7 +457,7 @@ var Sidebar = module.exports = new Class({
|
|||
callback: function() {
|
||||
// get data
|
||||
var filename = path + $('new_file').value,
|
||||
pack = fd.getItem();
|
||||
pack = fd.item;
|
||||
|
||||
if (!filename) {
|
||||
fd.error.alert(
|
||||
|
@ -464,10 +480,10 @@ var Sidebar = module.exports = new Class({
|
|||
filename = filename.replace(/\.[^\.]+$/, '');
|
||||
}
|
||||
|
||||
if (!isFolder && Module.exists(filename)) {
|
||||
if (!isFolder && pack.moduleExists(filename)) {
|
||||
fd.error.alert('Filename has to be unique', 'You already have the module with that name');
|
||||
return;
|
||||
} else if (isFolder && Folder.exists(filename, Folder.ROOT_DIR_LIB)) {
|
||||
} else if (isFolder && pack.folderExists(filename, Folder.ROOT_DIR_LIB)) {
|
||||
fd.error.alert('Folder has to be unique', 'You already have the folder with that name');
|
||||
return;
|
||||
}
|
||||
|
@ -510,7 +526,7 @@ var Sidebar = module.exports = new Class({
|
|||
promptAttachment: function(folder) {
|
||||
var basename,
|
||||
that = this,
|
||||
pack = fd.getItem(),
|
||||
pack = fd.item,
|
||||
path = (folder && folder.get('path')) || '';
|
||||
if (path) path += '/';
|
||||
fd.showQuestion({
|
||||
|
@ -554,7 +570,7 @@ var Sidebar = module.exports = new Class({
|
|||
var fname = files[f].name.getFileName(),
|
||||
ex = files[f].name.getFileExtension();
|
||||
|
||||
if (Attachment.exists(fname, ex)) {
|
||||
if (fd.item.attachmentExists(fname +'.'+ ex)) {
|
||||
fd.error.alert('Filename has to be unique',
|
||||
'You already have an attachment with that name.');
|
||||
return;
|
||||
|
@ -651,7 +667,7 @@ var Sidebar = module.exports = new Class({
|
|||
return;
|
||||
}
|
||||
|
||||
fd.getItem().assignLibrary(lib_id)
|
||||
fd.item.assignLibrary(lib_id)
|
||||
prompt.destroy();
|
||||
}
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче