(function() {
'use strict';
+ /* globals requirejs, RNG_BOOTSTRAP_DATA */
+
requirejs.config({
baseUrl: '/static/editor/src/editor',
documentHistory: require('modules/documentHistory/documentHistory'),
diffViewer: require('modules/diffViewer/diffViewer')
- }
+ };
});
\ No newline at end of file
define([
+ 'libs/jquery',
'./saveDialog',
'wlxml/wlxml'
-], function(saveDialog, wlxml) {
+], function($, saveDialog, wlxml) {
'use strict';
return function(sandbox) {
+ /* global gettext */
var document_id = sandbox.getBootstrappedData().document_id;
var document_version = sandbox.getBootstrappedData().version;
function readCookie(name) {
- var nameEQ = escape(name) + "=";
+ /* global escape, unescape */
+ var nameEQ = escape(name) + '=';
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
- while (c.charAt(0) == ' ') c = c.substring(1, c.length);
- if (c.indexOf(nameEQ) === 0) return unescape(c.substring(nameEQ.length, c.length));
+ while (c.charAt(0) === ' ') {
+ c = c.substring(1, c.length);
+ }
+ if (c.indexOf(nameEQ) === 0) {
+ return unescape(c.substring(nameEQ.length, c.length));
+ }
}
return null;
}
crossDomain: false,
beforeSend: function(xhr, settings) {
if (!(/^(GET|HEAD|OPTIONS|TRACE)$/.test(settings.type))) {
- xhr.setRequestHeader("X-CSRFToken", readCookie('csrftoken'));
+ xhr.setRequestHeader('X-CSRFToken', readCookie('csrftoken'));
}
}
});
method: 'get',
url: '/' + gettext('editor') + '/' + document_id + '/history',
success: function(data) {
- history = data;
+ history = data;
sandbox.publish('historyItemAdded', data.slice(-1)[0]);
},
});
getDocument: function() {
return wlxmlDocument;
},
- commitDocument: function(newDocument, reason) {
- // doc = newDocument;
- // sandbox.publish('documentChanged', doc, reason);
- },
saveDocument: function() {
var dialog = saveDialog.create();
},
error: function() {event.error(); sandbox.publish('savingEnded', 'error');}
});
- console.log('save');
});
dialog.on('cancel', function() {
});
reloadHistory();
sandbox.publish('documentReverted', data);
},
- });
+ });
}
},
getDocumentId: function() {
define([
'libs/text!./saveDialog.html',
'libs/underscore',
-'libs/backbone',
-'libs/jquery'
-], function(saveDialogTemplate, _, Backbone, $) {
+'libs/backbone'
+], function(saveDialogTemplate, _, Backbone) {
+
+ 'use strict';
var DialogView = Backbone.View.extend({
template: _.template(saveDialogTemplate),
_.bindAll(this);
this.actionsDisabled = false;
},
- show: function() {
+ show: function() {
this.setElement(this.template());
this.$el.modal({backdrop: 'static'});
this.$el.modal('show');
});
},
close: function(e) {
- if(e)
+ if(e) {
e.preventDefault();
+ }
if(!this.actionsDisabled) {
this.$el.modal('hide');
this.$el.remove();
var itemViews = [];
- dom.find('.btn.compare').click(function(e) {
+ dom.find('.btn.compare').click(function() {
var selected = historyItems.getSelected();
sandbox.publish('compare', selected[0], selected[1]);
});
- dom.find('.btn.restore').click(function(e) {
+ dom.find('.btn.restore').click(function() {
var dialog = restoreDialog.create();
dialog.on('restore', function(event) {
sandbox.publish('restoreVersion', {version: historyItems.getSelected()[0], description: event.data.description});
dialog.show();
});
- dom.find('.btn.display').click(function(e) {
+ dom.find('.btn.display').click(function() {
sandbox.publish('displayVersion', {version: historyItems.getSelected()[0]});
});
var toggleItemViews = function(toggle) {
itemViews.forEach(function(view) {
- if(!historyItems.isSelected(view.item))
+ if(!historyItems.isSelected(view.item)) {
view.toggle(toggle);
+ }
});
};
this.dimItem();
} else if(historyItems.select(this.item)) {
this.highlightItem();
- }
+ }
};
ItemView.prototype.highlightItem = function() {
this.dom.addClass('highlighted');
define([
'libs/text!./templates/restoreDialog.html',
'libs/underscore',
-'libs/backbone',
-'libs/jquery'
-], function(restoreDialogTemplate, _, Backbone, $) {
+'libs/backbone'
+], function(restoreDialogTemplate, _, Backbone) {
+
+ 'use strict';
+
var DialogView = Backbone.View.extend({
template: _.template(restoreDialogTemplate),
_.bindAll(this);
this.actionsDisabled = false;
},
- show: function() {
+ show: function() {
this.setElement(this.template());
this.$el.modal({backdrop: 'static'});
this.$el.modal('show');
});
},
close: function(e) {
- if(e)
+ if(e) {
e.preventDefault();
+ }
if(!this.actionsDisabled) {
this.$el.modal('hide');
this.$el.remove();
return function(sandbox) {
var view = {
- dom: $(_.template(template)()),
- setup: function() {
-
- }
+ dom: $(_.template(template)())
};
return {
});
this.metaTable.on('keydown', '[contenteditable]', function(e) {
- console.log(e.which);
- if(e.which === 13) {
+ if(e.which === 13) {
if($(document.activeElement).hasClass('rng-module-metadataEditor-metaItemKey')) {
metaTable.find('.rng-module-metadataEditor-metaItemValue').focus();
} else {
var onKeyUp = function(e) {
- if(e.which !== 13)
+ if(e.which !== 13) {
sandbox.publish('metadataChanged', view.getMetadata());
+ }
};
this.metaTable.on('keyup', '[contenteditable]', _.throttle(onKeyUp, 500));
},
getMetadata: function() {
var toret = {};
this.node.find('tr').each(function() {
- var tr = $(this);
var inputs = $(this).find('td [contenteditable]');
var key = $(inputs[0]).text();
var value = $(inputs[1]).text();
setMetadata: function(metadata) {
var view = this;
this.metaTable.find('tr').remove();
- _.each(_.keys(metadata), function(key) {
+ _.each(_.keys(metadata), function(key) {
view._addMetaRow(key, metadata[key]);
});
},
-define(['libs/jquery'], function($) {
+define(['libs/jquery', 'libs/underscore'], function($, _) {
'use strict';
meta.append('\n\t<dc:'+key+'>' + metadata[key] + '</dc:'+key+'>');
});
meta.append('\n');
+ /* globals vkbeautify */
return vkbeautify.xml(meta.html());
}
};
var view = {
dom: $('<div>' + template({node:null, parents: null}) + '</div>'),
setup: function() {
- var view = this;
this.dom.on('mouseenter', 'a', function(e) {
var target = $(e.target);
sandbox.publish('elementEntered', target.data('element'));
return idx;
}
return -1;
- }
+ };
var startListening = function(document) {
listens = true;
view.setElement();
}
}, this);
- }
+ };
var view = {
dom: $('<div>' + template({contents: null, parent: null}) + '</div>'),
setup: function() {
- var view = this;
this.dom.on('click', 'a', function(e) {
var target = $(e.target);
sandbox.publish('nodeClicked', target.data('element'));
},
setElement: function(element) {
element = element || this.currentNodeElement;
- console.log('familyTree sets node');
var textElement = element.getText ? element : null,
nodeElement = element.getText ? element.parent() : element, // TODO: better type detection
nodeElementParent = nodeElement.parent(),
nodeContents.forEach(function(child) {
if(child.getText) {
var text = child.getText();
- if(!text)
+ if(!text) {
text = '<pusty tekst>';
+ }
else {
if(text.length > 13) {
text = text.substr(0,13) + '...';
this.dom.append($(template({parent: parent, contents: contents})));
if(parent) {
- this.dom.find('.rng-module-nodeFamilyTree-parent').data('element', nodeElementParent)
+ this.dom.find('.rng-module-nodeFamilyTree-parent').data('element', nodeElementParent);
}
this.dom.find('li a').each(function(idx, a) {
$(a).data('element', nodeContents[idx]);
if(!listens) {
startListening(element.document);
}
- if(!(element.sameNode(view.currentNodeElement)))
+ if(!(element.sameNode(view.currentNodeElement))) {
view.setElement(element);
+ }
},
getView: function() {
return view.dom;
setNodeElement: function(wlxmlNodeElement) {
view.find('.rng-module-nodePane-tagSelect').val(wlxmlNodeElement.getTagName());
- var escapedClassName = (wlxmlNodeElement.getClass() || '').replace(/\./g, '-')
+ var escapedClassName = (wlxmlNodeElement.getClass() || '').replace(/\./g, '-');
view.find('.rng-module-nodePane-classSelect').val(escapedClassName);
var widget = metaWidget.create({attrs:wlxmlNodeElement.getMetaAttributes()});
define([
+'libs/underscore',
'fnpjs/layout',
'fnpjs/vbox',
'views/tabs/tabs',
'libs/text!./mainLayout.html',
'libs/text!./editingLayout.html',
'libs/text!./diffLayout.html',
-], function(layout, vbox, tabs, mainLayoutTemplate, visualEditingLayoutTemplate, diffLayoutTemplate) {
+], function(_, layout, vbox, tabs, mainLayoutTemplate, visualEditingLayoutTemplate, diffLayoutTemplate) {
'use strict';
return function(sandbox) {
+
+ /* globals gettext */
function addMainTab(title, slug, view) {
views.mainTabs.addTab(title, slug, view);
highlightDocumentElement: function(element, origin) {
///'nodeBreadCrumbs', 'nodeFamilyTree'
['documentCanvas', 'nodeFamilyTree'].forEach(function(moduleName) {
- if(!origin || moduleName != origin)
+ if(!origin || moduleName !== origin) {
sandbox.getModule(moduleName).highlightElement(element);
+ }
});
},
dimDocumentElement: function(element, origin) {
//'nodeBreadCrumbs', 'nodeFamilyTree'
['documentCanvas', 'nodeFamilyTree'].forEach(function(moduleName) {
- if(!origin || moduleName != origin)
+ if(!origin || moduleName !== origin) {
sandbox.getModule(moduleName).dimElement(element);
+ }
});
},
jumpToDocumentElement: function(element) {
},
resetDocument: function(document, reason) {
var modules = [];
- if(reason === 'source_edit')
+ if(reason === 'source_edit') {
modules = ['documentCanvas', 'metadataEditor'];
- else if (reason === 'edit')
+ }
+ else if (reason === 'edit') {
modules = ['sourceEditor'];
- else if (reason === 'revert')
+ }
+ else if (reason === 'revert') {
modules = ['documentCanvas', 'metadataEditor', 'sourceEditor'];
+ }
modules.forEach(function(moduleName) {
sandbox.getModule(moduleName).setDocument(document);
sandbox.getModule('indicator').showMessage(gettext('Saving...'));
},
savingEnded: function(status) {
+ void(status);
sandbox.getModule('mainBar').setCommandEnabled('save', true);
sandbox.getModule('indicator').clearMessage({message:'Dokument zapisany'});
},
},
elementClicked: function(element) {
commands.jumpToDocumentElement(element);
- }
+ }
};
eventHandlers.documentHistory = {
sandbox.getModule('data').start();
},
handleEvent: function(moduleName, eventName, args) {
- if('')
- wysiwigHandler.handleEvent(moduleName, eventName, args);
- else if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
+ if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
eventHandlers[moduleName][eventName].apply(eventHandlers, args);
}
}
-define(function() {
+define(['libs/jquery'], function($) {
'use strict';
sandbox.publish('documentSet');
documentIsDirty = false;
}
- }
+ };
view.onHide = function() {
if(documentEditedHere) {
documentEditedHere = false;
wlxmlDocument.loadXML(editor.getValue());
}
- }
+ };
+ /* globals ace */
var editor = ace.edit(view.find('#rng-sourceEditor-editor')[0]),
session = editor.getSession();
- editor.setTheme("ace/theme/chrome");
- session.setMode("ace/mode/xml")
+ editor.setTheme('ace/theme/chrome');
+ session.setMode('ace/mode/xml');
session.setUseWrapMode(true);
$('textarea', view).on('keyup', function() {
'use strict';
return {
- modules: {},
+ modules: {},
initModules: ['rng'],
permissions: {
'skelton': ['getDOM'],
'rng': ['getModule', 'handleEvents', 'getDOM']
}
-}
+};
});
\ No newline at end of file
define([
+'libs/jquery',
'libs/text!./templates/main.html',
'libs/text!./templates/handle.html',
'libs/underscore',
'libs/backbone'
-], function(mainTemplate, handleTemplate, _, Backbone) {
+], function($, mainTemplate, handleTemplate, _, Backbone) {
'use strict';
var View = Backbone.View.extend({
var text = (typeof title === 'string') ? title : (title.text || '');
var icon = title.icon || null;
- if(!this.tabExists(slug))
+ if(!this.tabExists(slug)) {
this.nodes.tabBar.append(this.handleTemplate({text: text, icon: icon, slug: slug}));
- if(!this.selectedTab)
+ }
+ if(!this.selectedTab) {
this.selectTab(slug);
+ }
},
selectTab: function(slug) {
if(this.selectedTab) {
var toDetach = this.contents[this.selectedTab];
- if(toDetach.onHide)
+ if(toDetach.onHide) {
toDetach.onHide();
+ }
toDetach.detach();
}
this.nodes.content.append(this.contents[slug]);
_onTabTitleClicked: function(e) {
e.preventDefault();
var target = $(e.target);
- if(target.is('i'))
+ if(target.is('i')) {
target = target.parent();
+ }
var slug = target.attr('href').substr(1);
this.selectTab(slug);
}