5 'libs/text!./mainLayout.html',
6 'libs/text!./editingLayout.html',
7 'libs/text!./diffLayout.html',
8 ], function(layout, vbox, tabs, mainLayoutTemplate, visualEditingLayoutTemplate, diffLayoutTemplate) {
12 return function(sandbox) {
14 function addMainTab(title, slug, view) {
15 views.mainTabs.addTab(title, slug, view);
19 highlightDocumentElement: function(element, origin) {
20 ///'nodeBreadCrumbs', 'nodeFamilyTree'
21 ['documentCanvas', ].forEach(function(moduleName) {
22 if(!origin || moduleName != origin)
23 sandbox.getModule(moduleName).highlightElement(element);
26 dimDocumentElement: function(element, origin) {
27 //'nodeBreadCrumbs', 'nodeFamilyTree'
28 ['documentCanvas'].forEach(function(moduleName) {
29 if(!origin || moduleName != origin)
30 sandbox.getModule(moduleName).dimElement(element);
33 jumpToDocumentElement: function(element) {
34 sandbox.getModule('documentCanvas').jumpToElement(element);
36 updateCurrentNodeElement: function(nodeElement) {
37 sandbox.getModule('nodePane').setNodeElement(nodeElement);
38 sandbox.getModule('nodeFamilyTree').setElement(nodeElement);
39 //sandbox.getModule('nodeBreadCrumbs').setNodeElement(nodeElement);
41 updateCurrentTextElement: function(textElement) {
42 sandbox.getModule('nodeFamilyTree').setElement(textElement);
44 resetDocument: function(document, reason) {
46 if(reason === 'source_edit')
47 modules = ['documentCanvas', 'metadataEditor'];
48 else if (reason === 'edit')
49 modules = ['sourceEditor'];
50 else if (reason === 'revert')
51 modules = ['documentCanvas', 'metadataEditor', 'sourceEditor'];
53 modules.forEach(function(moduleName) {
54 sandbox.getModule(moduleName).setDocument(document);
61 mainLayout: new layout.Layout(mainLayoutTemplate),
62 mainTabs: (new tabs.View()).render(),
63 visualEditing: new layout.Layout(visualEditingLayoutTemplate),
64 visualEditingSidebar: (new tabs.View({stacked: true})).render(),
65 currentNodePaneLayout: new vbox.VBox(),
66 diffLayout: new layout.Layout(diffLayoutTemplate)
69 views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView());
70 addMainTab('Edytor', 'editor', views.visualEditing.getAsView());
71 addMainTab(gettext('Source'), 'sourceEditor', '');
72 addMainTab('Historia', 'history', views.diffLayout.getAsView());
74 sandbox.getDOM().append(views.mainLayout.getAsView());
76 views.visualEditingSidebar.addTab({icon: 'pencil'}, 'edit', views.currentNodePaneLayout.getAsView());
81 var eventHandlers = {};
83 eventHandlers.sourceEditor = {
85 addMainTab(gettext('Source'), 'sourceEditor', sandbox.getModule('sourceEditor').getView());
86 sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());
90 eventHandlers.data = {
92 views.mainLayout.setView('mainView', views.mainTabs.getAsView());
94 _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory', 'diffViewer'], function(moduleName) {
95 sandbox.getModule(moduleName).start();
98 documentChanged: function(document, reason) {
99 commands.resetDocument(document, reason);
101 savingStarted: function() {
102 sandbox.getModule('mainBar').setCommandEnabled('save', false);
103 sandbox.getModule('indicator').showMessage(gettext('Saving...'));
105 savingEnded: function(status) {
106 sandbox.getModule('mainBar').setCommandEnabled('save', true);
107 sandbox.getModule('indicator').clearMessage({message:'Dokument zapisany'});
109 restoringStarted: function(event) {
110 sandbox.getModule('mainBar').setCommandEnabled('save', false);
111 sandbox.getModule('indicator').showMessage(gettext('Restoring version ') + event.version + '...');
113 historyItemAdded: function(item) {
114 sandbox.getModule('documentHistory').addHistory([item], {animate: true});
116 diffFetched: function(diff) {
117 sandbox.getModule('diffViewer').setDiff(diff);
119 documentReverted: function(event) {
120 commands.resetDocument(event.document, 'revert');
121 sandbox.getModule('mainBar').setCommandEnabled('save', true);
122 sandbox.getModule('indicator').clearMessage({message:'Wersja ' + event.reverted_version + ' przywrócona'});
123 sandbox.getModule('mainBar').setVersion(event.current_version);
127 eventHandlers.mainBar = {
129 sandbox.getModule('mainBar').setVersion(sandbox.getModule('data').getDocumentVersion());
130 views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
132 'cmd.save': function() {
133 synchronizeTab(views.mainTabs.getCurrentSlug());
134 sandbox.getModule('data').saveDocument();
138 eventHandlers.indicator = {
140 views.mainLayout.setView('messages', sandbox.getModule('indicator').getView());
146 eventHandlers.documentCanvas = {
148 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
149 views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());
152 currentTextElementSet: function(textElement) {
153 commands.updateCurrentTextElement(textElement);
156 currentNodeElementSet: function(nodeElement) {
157 commands.updateCurrentNodeElement(nodeElement);
160 currentNodeElementChanged: function(nodeElement) {
161 commands.updateCurrentNodeElement(nodeElement);
164 nodeHovered: function(canvasNode) {
165 commands.highlightDocumentNode(canvasNode);
168 nodeBlured: function(canvasNode) {
169 commands.dimDocumentNode(canvasNode);
173 eventHandlers.nodePane = {
175 views.currentNodePaneLayout.appendView(sandbox.getModule('nodePane').getView());
178 nodeElementChange: function(attr, value) {
179 sandbox.getModule('documentCanvas').modifyCurrentNodeElement(attr, value);
183 eventHandlers.metadataEditor = {
185 sandbox.getModule('metadataEditor').setDocument(sandbox.getModule('data').getDocument());
186 views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
190 eventHandlers.nodeFamilyTree = {
192 views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());
194 elementEntered: function(element) {
195 commands.highlightDocumentElement(element, 'nodeFamilyTree');
197 elementLeft: function(element) {
198 commands.dimDocumentElement(element, 'nodeFamilyTree');
200 elementClicked: function(element) {
201 commands.jumpToDocumentElement(element);
205 eventHandlers.documentToolbar = {
207 views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());
209 command: function(cmd, params) {
210 sandbox.getModule('documentCanvas').command(cmd, params);
214 eventHandlers.nodeBreadCrumbs = {
216 views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());
218 elementEntered: function(element) {
219 commands.highlightDocumentElement(element, 'nodeBreadCrumbs');
221 elementLeft: function(element) {
222 commands.dimDocumentElement(element, 'nodeBreadCrumbs');
224 elementClicked: function(element) {
225 commands.jumpToDocumentElement(element);
229 eventHandlers.documentHistory = {
231 sandbox.getModule('documentHistory').addHistory(sandbox.getModule('data').getHistory());
232 views.diffLayout.setView('left', sandbox.getModule('documentHistory').getView());
234 compare: function(ver1, ver2) {
235 sandbox.getModule('data').fetchDiff(ver1, ver2);
237 restoreVersion: function(event) {
238 sandbox.getModule('data').restoreVersion(event);
240 displayVersion: function(event) {
241 window.open('/' + gettext('editor') + '/' + sandbox.getModule('data').getDocumentId() + '?version=' + event.version, _.uniqueId());
245 eventHandlers.diffViewer = {
247 views.diffLayout.setView('right', sandbox.getModule('diffViewer').getView());
255 sandbox.getModule('data').start();
257 handleEvent: function(moduleName, eventName, args) {
259 wysiwigHandler.handleEvent(moduleName, eventName, args);
260 else if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
261 eventHandlers[moduleName][eventName].apply(eventHandlers, args);