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', 'nodeFamilyTree'].forEach(function(moduleName) {
22 if(!origin || moduleName != origin)
23 sandbox.getModule(moduleName).highlightElement(element);
26 dimDocumentElement: function(element, origin) {
27 //'nodeBreadCrumbs', 'nodeFamilyTree'
28 ['documentCanvas', 'nodeFamilyTree'].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 sandbox.getModule('data').saveDocument();
137 eventHandlers.indicator = {
139 views.mainLayout.setView('messages', sandbox.getModule('indicator').getView());
145 eventHandlers.documentCanvas = {
147 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
148 views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());
151 currentTextElementSet: function(textElement) {
152 commands.updateCurrentTextElement(textElement);
155 currentNodeElementSet: function(nodeElement) {
156 commands.updateCurrentNodeElement(nodeElement);
159 currentNodeElementChanged: function(nodeElement) {
160 commands.updateCurrentNodeElement(nodeElement);
163 nodeHovered: function(canvasNode) {
164 commands.highlightDocumentNode(canvasNode);
167 nodeBlured: function(canvasNode) {
168 commands.dimDocumentNode(canvasNode);
172 eventHandlers.nodePane = {
174 views.currentNodePaneLayout.appendView(sandbox.getModule('nodePane').getView());
177 nodeElementChange: function(attr, value) {
178 sandbox.getModule('documentCanvas').modifyCurrentNodeElement(attr, value);
182 eventHandlers.metadataEditor = {
184 sandbox.getModule('metadataEditor').setDocument(sandbox.getModule('data').getDocument());
185 views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
189 eventHandlers.nodeFamilyTree = {
191 views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());
193 nodeEntered: function(node) {
194 commands.highlightDocumentElement(node, 'nodeFamilyTree');
196 nodeLeft: function(node) {
197 commands.dimDocumentElement(node, 'nodeFamilyTree');
199 nodeClicked: function(node) {
200 commands.jumpToDocumentElement(node);
204 eventHandlers.documentToolbar = {
206 views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());
208 command: function(cmd, params) {
209 sandbox.getModule('documentCanvas').command(cmd, params);
213 eventHandlers.nodeBreadCrumbs = {
215 views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());
217 elementEntered: function(element) {
218 commands.highlightDocumentElement(element, 'nodeBreadCrumbs');
220 elementLeft: function(element) {
221 commands.dimDocumentElement(element, 'nodeBreadCrumbs');
223 elementClicked: function(element) {
224 commands.jumpToDocumentElement(element);
228 eventHandlers.documentHistory = {
230 sandbox.getModule('documentHistory').addHistory(sandbox.getModule('data').getHistory());
231 views.diffLayout.setView('left', sandbox.getModule('documentHistory').getView());
233 compare: function(ver1, ver2) {
234 sandbox.getModule('data').fetchDiff(ver1, ver2);
236 restoreVersion: function(event) {
237 sandbox.getModule('data').restoreVersion(event);
239 displayVersion: function(event) {
240 window.open('/' + gettext('editor') + '/' + sandbox.getModule('data').getDocumentId() + '?version=' + event.version, _.uniqueId());
244 eventHandlers.diffViewer = {
246 views.diffLayout.setView('right', sandbox.getModule('diffViewer').getView());
254 sandbox.getModule('data').start();
256 handleEvent: function(moduleName, eventName, args) {
258 wysiwigHandler.handleEvent(moduleName, eventName, args);
259 else if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
260 eventHandlers[moduleName][eventName].apply(eventHandlers, args);