зеркало из https://github.com/mozilla/FlightDeck.git
Going forward to support the dependencies
This commit is contained in:
Родитель
877cfbfe54
Коммит
eb06cbbfca
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* File: jetpack/CapDependency.js
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Class: CapDependency
|
||||
* Refactored Capability class. Changes the behaviour to make it work as dependency
|
||||
*/
|
||||
|
||||
var CapDependency = new Class({
|
||||
Extends: Capability,
|
||||
options: {
|
||||
is_dependency: true // this will probably be redundant
|
||||
},
|
||||
initialize: function(options) {
|
||||
this.setOptions(options);
|
||||
this.initializeVersion();
|
||||
this.listenToEvents();
|
||||
console.log(this.version_create)
|
||||
},
|
||||
initializeVersion: function() {
|
||||
this.version = new CapVersionDependency(this.options.version);
|
||||
},
|
||||
createAfterBounds: function() {
|
||||
this.boundAfterVersionChanged = this.afterVersionChanged.bind(this);
|
||||
},
|
||||
listenToEvents: function() {
|
||||
this.createAfterBounds();
|
||||
this.version.addEvent('change', this.boundAfterVersionChanged);
|
||||
},
|
||||
afterVersionChanged: function() {
|
||||
item = jetpack || capability;
|
||||
console.log(item)
|
||||
$(item.options.version_create_el).addEvent('click', function(e) {
|
||||
e.stop();
|
||||
this.version_create();
|
||||
}.bind(this));
|
||||
this.version.removeEvent('click', this.boundAfterVersionChanged);
|
||||
},
|
||||
afterVersionCreated: function(response) {
|
||||
fd.message.alert(response.message);
|
||||
// change id's on the elements
|
||||
},
|
||||
instantiateEditors: $empty,
|
||||
initializeEditorSwitches: $empty,
|
||||
switchToDescription: $empty,
|
||||
try_in_browser: $empty,
|
||||
getContent: $empty,
|
||||
prepareData: $empty
|
||||
});
|
||||
|
||||
var CapVersionDependency = new Class({
|
||||
Extends: CapVersion,
|
||||
options: {
|
||||
is_dependency: true
|
||||
},
|
||||
initialize: function(options) {
|
||||
this.setOptions(options);
|
||||
this.instantiateEditors();
|
||||
this.listenToEvents();
|
||||
this.initializeEditorSwitches();
|
||||
this.data = $H({
|
||||
version_name: this.options.name,
|
||||
versin_description: this.options.description,
|
||||
version_content: this.options.content,
|
||||
});
|
||||
},
|
||||
listenToEvents: function() {
|
||||
this.changed = false;
|
||||
this.boundAfterDataChanged = this.afterDataChanged.bind(this);
|
||||
this.content_el.addEvent('change', this.boundAfterDataChanged);
|
||||
},
|
||||
afterDataChanged: function() {
|
||||
this.changed = true;
|
||||
$(this.options.update_el).addEvent('click', function(e) {
|
||||
e.stop();
|
||||
this.update();
|
||||
}.bind(this));
|
||||
this.content_el.removeEvent('change', this.boundAfterDataChanged);
|
||||
this.fireEvent('change');
|
||||
},
|
||||
instantiateEditors: function() {
|
||||
this.content_el = new Editor(this.options.content_el).hide();
|
||||
fd.editors.push(this.content_el);
|
||||
},
|
||||
initializeEditorSwitches: function() {
|
||||
this.switch_content_el = $(this.options.switch_content_id);
|
||||
if (this.switch_content_el) {
|
||||
this.switch_content_el.addEvent('click', this.switchToContent.bind(this));
|
||||
}
|
||||
},
|
||||
updateFromDOM: function() {
|
||||
this.data.version_content = this.content_el.getContent();
|
||||
},
|
||||
setAsBase: $empty,
|
||||
switchToDescription: $empty,
|
||||
getName: $empty,
|
||||
|
||||
});
|
|
@ -11,7 +11,7 @@ var Capability = new Class({
|
|||
//slug: null,
|
||||
//name: null,
|
||||
//description: null,
|
||||
//author: null,
|
||||
//creator: null,
|
||||
//managers: [],
|
||||
//developers: [],
|
||||
//public_permission: 2,
|
||||
|
@ -40,17 +40,19 @@ var Capability = new Class({
|
|||
|
||||
this.listenToEvents();
|
||||
if (!this.options.is_dependency) {
|
||||
// TODO: this should probably be moved to the Flightdeck.Editor.js
|
||||
// TODO: this should probably be moved to the UI.Editor.js or however this file will be called
|
||||
this.initializeEditorSwitches();
|
||||
}
|
||||
|
||||
this.data = {};
|
||||
if (!this.options.is_dependency) {
|
||||
this.data[this.type+'_name'] = this.options.name;
|
||||
this.data[this.type+'_description'] = this.options.description;
|
||||
}
|
||||
this.data[this.type+'_slug'] = this.options.slug;
|
||||
this.data[this.type+'_name'] = this.options.name;
|
||||
this.data[this.type+'_description'] = this.options.description;
|
||||
// #TODO: remove these - it's just to switch the buttons all the time
|
||||
this.afterVersionChanged();
|
||||
this.afterDataChanged();
|
||||
// this.afterVersionChanged();
|
||||
// this.afterDataChanged();
|
||||
},
|
||||
/*
|
||||
* Method: instantiateEditors
|
||||
|
@ -70,11 +72,11 @@ var Capability = new Class({
|
|||
// to not bother about new dependencies added
|
||||
$$('.UI_File_Listing li').each(function(file_el) {
|
||||
file_el.switch_mode_on = function() {
|
||||
$$('.UI_File_Selected').each(function(el) {
|
||||
el.switch_mode_off();
|
||||
});
|
||||
this.removeClass('UI_File_Normal')
|
||||
.addClass('UI_File_Selected')
|
||||
.getSiblings('.UI_File_Selected').each(function(el) {
|
||||
el.switch_mode_off();
|
||||
});
|
||||
};
|
||||
file_el.switch_mode_off = function() {
|
||||
this.removeClass('UI_File_Selected')
|
||||
|
@ -99,15 +101,17 @@ var Capability = new Class({
|
|||
fd.hideEditors();
|
||||
this.description_el.show();
|
||||
},
|
||||
createAfterBounds: function() {
|
||||
this.boundAfterDataChanged = this.afterDataChanged.bind(this);
|
||||
this.boundAfterVersionChanged = this.afterVersionChanged.bind(this);
|
||||
},
|
||||
/*
|
||||
* Method: listenToEvents
|
||||
*/
|
||||
listenToEvents: function() {
|
||||
this.boundAfterDataChanged = this.afterDataChanged.bind(this);
|
||||
this.boundAfterVersionChanged = this.afterVersionChanged.bind(this);
|
||||
// #TODO: using change is wrong here
|
||||
this.description_el.addEvent('change', this.boundAfterDataChanged);
|
||||
this.createAfterBounds();
|
||||
this.version.addEvent('change', this.boundAfterVersionChanged);
|
||||
this.description_el.addEvent('change', this.boundAfterDataChanged);
|
||||
// one may try even not edited data
|
||||
$(this.options.try_in_browser_el).addEvent('click', function(e) {
|
||||
e.stop();
|
||||
|
@ -171,11 +175,12 @@ var Capability = new Class({
|
|||
url: this.options.version_create_url,
|
||||
data: data,
|
||||
method: 'post',
|
||||
onSuccess: function(response) {
|
||||
window.location.href = response.version_absolute_url;
|
||||
}
|
||||
onSuccess: this.afterVersionCreated.bind(this)
|
||||
}).send();
|
||||
},
|
||||
afterVersionCreated: function(response) {
|
||||
window.location.href = response.version_absolute_url;
|
||||
},
|
||||
/*
|
||||
* Method: try_in_browser
|
||||
* Prepare Capability using saved content and install temporary in the browser
|
||||
|
@ -197,7 +202,7 @@ var Capability = new Class({
|
|||
* Wrapper for getting Version name from options
|
||||
*/
|
||||
getVersionName: function() {
|
||||
return this.version.getName()
|
||||
return this.version.getName();
|
||||
},
|
||||
/*
|
||||
* Method: prepareData
|
||||
|
@ -249,7 +254,8 @@ var CapVersion = new Class({
|
|||
set_as_base_el: 'set_as_base',
|
||||
edit_url: '',
|
||||
update_url: '',
|
||||
set_as_base_url: ''
|
||||
set_as_base_url: '',
|
||||
is_dependency: false
|
||||
},
|
||||
/*
|
||||
* Method: initialize
|
||||
|
@ -262,22 +268,20 @@ var CapVersion = new Class({
|
|||
this.initializeEditorSwitches();
|
||||
|
||||
// this.data is everything we send to the backend
|
||||
this.data = {
|
||||
this.data = $H({
|
||||
version_content: this.options.content,
|
||||
version_name: this.options.name,
|
||||
version_description: this.options.description,
|
||||
version_content: this.options.content,
|
||||
};
|
||||
// #TODO: remove these - it's just to switch the buttons all the time
|
||||
this.afterDataChanged();
|
||||
});
|
||||
},
|
||||
/*
|
||||
* Method: instantiateEditors
|
||||
*/
|
||||
instantiateEditors: function() {
|
||||
this.name_el = $(this.options.name_el);
|
||||
this.content_el = new Editor(this.options.content_el);
|
||||
this.description_el = new Editor(this.options.description_el).hide();
|
||||
fd.editors.push(this.content_el);
|
||||
this.name_el = $(this.options.name_el);
|
||||
this.description_el = new Editor(this.options.description_el).hide();
|
||||
fd.editors.push(this.description_el);
|
||||
},
|
||||
/*
|
||||
|
@ -319,7 +323,6 @@ var CapVersion = new Class({
|
|||
this.content_el.addEvent('change', this.boundAfterDataChanged);
|
||||
},
|
||||
afterDataChanged: function() {
|
||||
this.fireEvent('change');
|
||||
// TODO: discover if change was actually an undo and there is
|
||||
// no change to the original content
|
||||
this.changed = true;
|
||||
|
@ -329,11 +332,12 @@ var CapVersion = new Class({
|
|||
}.bind(this));
|
||||
this.content_el.removeEvent('change', this.boundAfterDataChanged);
|
||||
this.description_el.removeEvent('change', this.boundAfterDataChanged);
|
||||
this.set_as_base_el = $(this.options.set_as_base_el)
|
||||
this.set_as_base_el = $(this.options.set_as_base_el);
|
||||
this.set_as_base_el.addEvent('click', function(e) {
|
||||
e.stop();
|
||||
this.setAsBase();
|
||||
}.bind(this));
|
||||
this.fireEvent('change');
|
||||
},
|
||||
/*
|
||||
* Method: setAsBase
|
||||
|
@ -356,8 +360,7 @@ var CapVersion = new Class({
|
|||
update: function() {
|
||||
var data = this.prepareData();
|
||||
// prevent from updating a version with different name
|
||||
if (data.version_name != this.options.name) {
|
||||
// # TODO: create version
|
||||
if (data.version_name && data.version_name != this.options.name) {
|
||||
return window[this.type].version_create(data);
|
||||
}
|
||||
new Request.JSON({
|
||||
|
@ -397,8 +400,8 @@ var CapVersion = new Class({
|
|||
*/
|
||||
updateFromDOM: function() {
|
||||
this.data.version_name = this.name_el.get('value');
|
||||
this.data.version_content = this.content_el.getContent();
|
||||
this.data.version_description = this.description_el.getContent();
|
||||
this.data.version_content = this.content_el.getContent();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
* Class representing the Jetpack only
|
||||
* Prepare the editor, save, update
|
||||
*/
|
||||
var Jetpack = Class.refactor(Capability, {
|
||||
var Jetpack = new Class({
|
||||
Extends: Capability,
|
||||
type: 'jetpack',
|
||||
options: {
|
||||
description_el: {element: 'jetpack_description'},
|
||||
|
@ -17,7 +18,7 @@ var Jetpack = Class.refactor(Capability, {
|
|||
*/
|
||||
initialize: function(options) {
|
||||
this.setOptions(options);
|
||||
this.previous(this.options);
|
||||
this.parent(this.options);
|
||||
},
|
||||
/*
|
||||
* Method: initializeVersion
|
||||
|
@ -31,7 +32,7 @@ var Jetpack = Class.refactor(Capability, {
|
|||
* get all jetpack editable fields from DOM and set parameters in model
|
||||
*/
|
||||
updateFromDOM: function() {
|
||||
this.previous();
|
||||
this.parent();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -39,7 +40,8 @@ var Jetpack = Class.refactor(Capability, {
|
|||
* Class representing the Version only
|
||||
* Prepare the editor, save, update
|
||||
*/
|
||||
var JetVersion = Class.refactor(CapVersion, {
|
||||
var JetVersion = new Class({
|
||||
Extends: CapVersion,
|
||||
type: 'jetpack',
|
||||
options: {
|
||||
//manifest: null,
|
||||
|
@ -53,14 +55,14 @@ var JetVersion = Class.refactor(CapVersion, {
|
|||
*/
|
||||
initialize: function(options) {
|
||||
this.setOptions(options);
|
||||
this.previous(options);
|
||||
this.parent(options);
|
||||
this.data.version_manifest = this.options.manifest;
|
||||
},
|
||||
/*
|
||||
* Method: instantiateEditors
|
||||
*/
|
||||
instantiateEditors: function() {
|
||||
this.previous();
|
||||
this.parent();
|
||||
this.manifest_el = new Editor(this.options.manifest_el).hide();
|
||||
fd.editors.push(this.manifest_el);
|
||||
},
|
||||
|
@ -68,13 +70,13 @@ var JetVersion = Class.refactor(CapVersion, {
|
|||
* Method: listenToJetpackEvents
|
||||
*/
|
||||
listenToEvents: function() {
|
||||
this.previous();
|
||||
this.parent();
|
||||
},
|
||||
/*
|
||||
* Method: initializeEditorSwitches
|
||||
*/
|
||||
initializeEditorSwitches: function() {
|
||||
this.previous();
|
||||
this.parent();
|
||||
this.switch_manifest_el = $(this.options.switch_manifest_id);
|
||||
if (this.switch_manifest_el) {
|
||||
this.switch_manifest_el.addEvent('click', this.switchToManifest.bind(this));
|
||||
|
@ -93,7 +95,7 @@ var JetVersion = Class.refactor(CapVersion, {
|
|||
* get all version editable fields from DOM and set parameters in model
|
||||
*/
|
||||
updateFromDOM: function() {
|
||||
this.previous();
|
||||
this.parent();
|
||||
this.data.version_manifest = this.manifest_el.getContent();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,14 +1,35 @@
|
|||
<input type="text" name="add_dependency" id="add_dependency"/>
|
||||
<button id="add_dependecy_action">+</button>
|
||||
{% with version.capabilities.all as modules %}
|
||||
{% if modules %}
|
||||
{% with version.capabilities.all as capabilities %}
|
||||
{% if capabilities %}
|
||||
<ul class="UI_File_Listing">
|
||||
{% for mod in modules %}
|
||||
{% if mod %}
|
||||
<li class="UI_File_Normal" id="{# TODO: mod|dependency_link_id #}">
|
||||
<a title="" href="#">{{ mod.name }} <span></span></a>
|
||||
{% for capversion in capabilities %}
|
||||
{% if capversion %}{% with capversion.capability as cap %}
|
||||
<li class="UI_File_Normal">
|
||||
<a title="" href="#" class='capability_dependency' id="dependency_{{ cap.slug }}">{{ cap.name }} {{ capversion.fullname }}<span></span></a>
|
||||
<script type="text/javascript">
|
||||
window.addEvent('domready', function() {
|
||||
var cap = new CapDependency({
|
||||
slug: "{{ cap.slug }}",
|
||||
name: "{{ cap.name }}",
|
||||
creator: "{{ cap.creator }}",
|
||||
version_create_url: "{{ cap.get_version_create_url }}",
|
||||
version: {
|
||||
author: "{{ capversion.author }}",
|
||||
name: "{{ capversion.name }}",
|
||||
description: "{{ capversion.description }}",
|
||||
content: "{{ capversion.content }}",
|
||||
is_base: {{ capversion.is_base|yesno:"true,false" }},
|
||||
edit_url: '{{ capversion.get_absolute_url }}',
|
||||
update_url: '{{ capversion.get_update_url }}',
|
||||
switch_content_id: 'dependency_{{ cap.slug }}',
|
||||
content_el: {element: 'dependency_content_{{ cap.slug }}'},
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endwith %}{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
|
|
@ -2,11 +2,12 @@
|
|||
{% load jetpack_extras %}
|
||||
{% block head %}
|
||||
<link rel="stylesheet" href="/media/jetpack/css/UI.Editor.css" type="text/css" media="screen" />
|
||||
{# <link rel="stylesheet" href="/media/bespin/BespinEmbedded.css" type="text/css" media="screen" /> #}
|
||||
{#<link rel="stylesheet" href="/media/bespin/BespinEmbedded.css" type="text/css" media="screen" />#}
|
||||
{# <script src="/media/bespin/BespinEmbedded.js"></script> #}
|
||||
<script src="/media/jetpack/js/Create.js"></script>
|
||||
<script src="/media/jetpack/js/Editor.js"></script>
|
||||
<script src="/media/jetpack/js/Capability.js"></script>
|
||||
<script src="/media/jetpack/js/CapDependency.js"></script>
|
||||
{# <script src="/media/jetpack/js/Bespin.js"></script>#}
|
||||
<script type="text/javascript">
|
||||
var settings = {
|
||||
|
|
|
@ -66,13 +66,7 @@
|
|||
<span class="UI_Sidebar_Toggler_Icon"></span>
|
||||
</a></h3>
|
||||
<div class="UI_Sidebar_ItemCont">
|
||||
<ul class="UI_File_Listing">
|
||||
{% for cap in version.capabilities.all %}
|
||||
<li class="UI_File_Normal" id="{{ cap|dependency_link_id }}">
|
||||
<a title="" href="#">{{ cap.name }} <span></span></a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% include "_dependency_list.html" %}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
@ -137,6 +131,10 @@
|
|||
<textarea id="version_content" class="UI_Editor_Area bespin" data-bespinoptions='{ "stealFocus":true }' name='version_content'>{{ version.content }}</textarea>
|
||||
<textarea id='version_manifest' class="UI_Editor_Area bespin" name='version_manifest'>{{ version.manifest }}</textarea>
|
||||
<textarea id='version_description' class='UI_Editor_Area bespin'>{{ version.description }}</textarea>
|
||||
{% for cap in version.capabilities.all %}
|
||||
<textarea id="dependency_content_{{ cap.slug }}" class="UI_Editor_Area bespin" name="dependency_content_{{ cap.slug }}">{{ cap.version.content }}</textarea>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -10,7 +10,7 @@ def tab_link_id(item, value):
|
|||
slug = item.slug if item else ''
|
||||
return "%s_%s" % (slug, value)
|
||||
|
||||
|
||||
# this switched of temporarily
|
||||
@register.filter
|
||||
def dependency_link_id(item):
|
||||
try:
|
||||
|
|
|
@ -201,7 +201,8 @@ def capability_update(r, slug):
|
|||
if not capability.can_be_updated_by(r.user):
|
||||
return HttpResponseNotAllowed(HttpResponse(""))
|
||||
|
||||
capability.description = r.POST.get('capability_description')
|
||||
if 'capability_description' in r.POST:
|
||||
capability.description = r.POST.get('capability_description')
|
||||
if 'capability_public_permission' in r.POST:
|
||||
capability.public_permission = r.POST.get('capability_public_permission')
|
||||
if 'capability_group_permission' in r.POST:
|
||||
|
@ -246,9 +247,11 @@ def capability_version_update(r, slug, version, counter):
|
|||
return HttpResponseNotAllowed(HttpResponse(""))
|
||||
|
||||
version.author = r.user
|
||||
version.name = r.POST.get("version_name", version.name)
|
||||
if "version_name" in r.POST:
|
||||
version.name = r.POST.get("version_name", version.name)
|
||||
version.content = r.POST.get("version_content", version.content)
|
||||
version.description = r.POST.get("version_description", version.description)
|
||||
if "version_description" in r.POST:
|
||||
version.description = r.POST.get("version_description", version.description)
|
||||
version.status = r.POST.get("version_status", version.status)
|
||||
version.is_base = r.POST.get("version_is_base", version.is_base)
|
||||
version.save()
|
||||
|
|
Загрузка…
Ссылка в новой задаче