6 'libs/text!./mainLayout.html',
7 'libs/text!./editingLayout.html',
8 'libs/text!./diffLayout.html',
9 ], function(_, layout, vbox, tabs, mainLayoutTemplate, visualEditingLayoutTemplate, diffLayoutTemplate) {
13 return function(sandbox) {
17 function addMainTab(title, slug, view) {
18 views.mainTabs.addTab(title, slug, view);
22 highlightDocumentElement: function(element, origin) {
23 ///'nodeBreadCrumbs', 'nodeFamilyTree'
24 ['documentCanvas', 'nodeFamilyTree'].forEach(function(moduleName) {
25 if(!origin || moduleName !== origin) {
26 sandbox.getModule(moduleName).highlightElement(element);
30 dimDocumentElement: function(element, origin) {
31 //'nodeBreadCrumbs', 'nodeFamilyTree'
32 ['documentCanvas', 'nodeFamilyTree'].forEach(function(moduleName) {
33 if(!origin || moduleName !== origin) {
34 sandbox.getModule(moduleName).dimElement(element);
38 jumpToDocumentElement: function(element) {
39 sandbox.getModule('documentCanvas').jumpToElement(element);
41 updateCurrentNodeElement: function(nodeElement) {
42 sandbox.getModule('nodePane').setNodeElement(nodeElement);
43 sandbox.getModule('nodeFamilyTree').setElement(nodeElement);
44 sandbox.getModule('nodeBreadCrumbs').setNodeElement(nodeElement);
46 updateCurrentTextElement: function(textElement) {
47 sandbox.getModule('nodeFamilyTree').setElement(textElement);
49 resetDocument: function(document, reason) {
51 if(reason === 'source_edit') {
52 modules = ['documentCanvas', 'metadataEditor'];
54 else if (reason === 'edit') {
55 modules = ['sourceEditor'];
57 else if (reason === 'revert') {
58 modules = ['documentCanvas', 'metadataEditor', 'sourceEditor'];
61 modules.forEach(function(moduleName) {
62 sandbox.getModule(moduleName).setDocument(document);
69 mainLayout: new layout.Layout(mainLayoutTemplate),
70 mainTabs: (new tabs.View()).render(),
71 visualEditing: new layout.Layout(visualEditingLayoutTemplate),
72 visualEditingSidebar: (new tabs.View({stacked: true})).render(),
73 currentNodePaneLayout: new vbox.VBox(),
74 diffLayout: new layout.Layout(diffLayoutTemplate)
77 views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView());
78 addMainTab('Edytor', 'editor', views.visualEditing.getAsView());
79 addMainTab(gettext('Source'), 'sourceEditor', '');
80 addMainTab('Historia', 'history', views.diffLayout.getAsView());
82 sandbox.getDOM().append(views.mainLayout.getAsView());
84 views.visualEditingSidebar.addTab({icon: 'pencil'}, 'edit', views.currentNodePaneLayout.getAsView());
89 var eventHandlers = {};
91 eventHandlers.sourceEditor = {
93 addMainTab(gettext('Source'), 'sourceEditor', sandbox.getModule('sourceEditor').getView());
94 sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());
98 eventHandlers.data = {
100 views.mainLayout.setView('mainView', views.mainTabs.getAsView());
102 _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory', 'diffViewer'], function(moduleName) {
103 sandbox.getModule(moduleName).start();
106 documentChanged: function(document, reason) {
107 commands.resetDocument(document, reason);
109 savingStarted: function() {
110 sandbox.getModule('mainBar').setCommandEnabled('save', false);
111 sandbox.getModule('indicator').showMessage(gettext('Saving...'));
113 savingEnded: function(status) {
115 sandbox.getModule('mainBar').setCommandEnabled('save', true);
116 sandbox.getModule('indicator').clearMessage({message:'Dokument zapisany'});
118 restoringStarted: function(event) {
119 sandbox.getModule('mainBar').setCommandEnabled('save', false);
120 sandbox.getModule('indicator').showMessage(gettext('Restoring version ') + event.version + '...');
122 historyItemAdded: function(item) {
123 sandbox.getModule('documentHistory').addHistory([item], {animate: true});
125 diffFetched: function(diff) {
126 sandbox.getModule('diffViewer').setDiff(diff);
128 documentReverted: function(event) {
129 commands.resetDocument(event.document, 'revert');
130 sandbox.getModule('mainBar').setCommandEnabled('save', true);
131 sandbox.getModule('indicator').clearMessage({message:'Wersja ' + event.reverted_version + ' przywrócona'});
132 sandbox.getModule('mainBar').setVersion(event.current_version);
136 eventHandlers.mainBar = {
138 sandbox.getModule('mainBar').setVersion(sandbox.getModule('data').getDocumentVersion());
139 views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
141 'cmd.save': function() {
142 sandbox.getModule('data').saveDocument();
146 eventHandlers.indicator = {
148 views.mainLayout.setView('messages', sandbox.getModule('indicator').getView());
154 eventHandlers.documentCanvas = {
156 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
157 views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());
160 currentTextElementSet: function(textElement) {
161 commands.updateCurrentTextElement(textElement);
164 currentNodeElementSet: function(nodeElement) {
165 commands.updateCurrentNodeElement(nodeElement);
168 currentNodeElementChanged: function(nodeElement) {
169 commands.updateCurrentNodeElement(nodeElement);
172 nodeHovered: function(canvasNode) {
173 commands.highlightDocumentNode(canvasNode);
176 nodeBlured: function(canvasNode) {
177 commands.dimDocumentNode(canvasNode);
181 eventHandlers.nodePane = {
183 views.currentNodePaneLayout.appendView(sandbox.getModule('nodePane').getView());
186 nodeElementChange: function(attr, value) {
187 sandbox.getModule('documentCanvas').modifyCurrentNodeElement(attr, value);
191 eventHandlers.metadataEditor = {
193 sandbox.getModule('metadataEditor').setDocument(sandbox.getModule('data').getDocument());
194 views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
198 eventHandlers.nodeFamilyTree = {
200 views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());
202 nodeEntered: function(node) {
203 commands.highlightDocumentElement(node, 'nodeFamilyTree');
205 nodeLeft: function(node) {
206 commands.dimDocumentElement(node, 'nodeFamilyTree');
208 nodeClicked: function(node) {
209 commands.jumpToDocumentElement(node);
213 eventHandlers.documentToolbar = {
215 views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());
217 command: function(cmd, params) {
218 sandbox.getModule('documentCanvas').command(cmd, params);
222 eventHandlers.nodeBreadCrumbs = {
224 views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());
226 elementEntered: function(element) {
227 commands.highlightDocumentElement(element, 'nodeBreadCrumbs');
229 elementLeft: function(element) {
230 commands.dimDocumentElement(element, 'nodeBreadCrumbs');
232 elementClicked: function(element) {
233 commands.jumpToDocumentElement(element);
237 eventHandlers.documentHistory = {
239 sandbox.getModule('documentHistory').addHistory(sandbox.getModule('data').getHistory());
240 views.diffLayout.setView('left', sandbox.getModule('documentHistory').getView());
242 compare: function(ver1, ver2) {
243 sandbox.getModule('data').fetchDiff(ver1, ver2);
245 restoreVersion: function(event) {
246 sandbox.getModule('data').restoreVersion(event);
248 displayVersion: function(event) {
249 window.open('/' + gettext('editor') + '/' + sandbox.getModule('data').getDocumentId() + '?version=' + event.version, _.uniqueId());
253 eventHandlers.diffViewer = {
255 views.diffLayout.setView('right', sandbox.getModule('diffViewer').getView());
263 sandbox.getModule('data').start();
265 handleEvent: function(moduleName, eventName, args) {
266 if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
267 eventHandlers[moduleName][eventName].apply(eventHandlers, args);