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 === 'revert') {
52 modules = ['documentCanvas', 'metadataEditor', 'sourceEditor'];
54 modules.forEach(function(moduleName) {
55 sandbox.getModule(moduleName).setDocument(document);
62 mainLayout: new layout.Layout(mainLayoutTemplate),
63 mainTabs: (new tabs.View()).render(),
64 visualEditing: new layout.Layout(visualEditingLayoutTemplate),
65 visualEditingSidebar: (new tabs.View({stacked: true})).render(),
66 currentNodePaneLayout: new vbox.VBox(),
67 diffLayout: new layout.Layout(diffLayoutTemplate)
70 views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView());
71 addMainTab('Edytor', 'editor', views.visualEditing.getAsView());
72 addMainTab(gettext('Source'), 'sourceEditor', '');
73 addMainTab('Historia', 'history', views.diffLayout.getAsView());
75 sandbox.getDOM().append(views.mainLayout.getAsView());
77 views.visualEditingSidebar.addTab({icon: 'pencil'}, 'edit', views.currentNodePaneLayout.getAsView());
82 var eventHandlers = {};
84 eventHandlers.sourceEditor = {
86 addMainTab(gettext('Source'), 'sourceEditor', sandbox.getModule('sourceEditor').getView());
87 sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());
91 eventHandlers.data = {
93 views.mainLayout.setView('mainView', views.mainTabs.getAsView());
95 _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory', 'diffViewer'], function(moduleName) {
96 sandbox.getModule(moduleName).start();
99 savingStarted: function() {
100 sandbox.getModule('mainBar').setCommandEnabled('save', false);
101 sandbox.getModule('indicator').showMessage(gettext('Saving...'));
103 savingEnded: function(status) {
105 sandbox.getModule('mainBar').setCommandEnabled('save', true);
106 sandbox.getModule('indicator').clearMessage({message:'Dokument zapisany'});
108 restoringStarted: function(event) {
109 sandbox.getModule('mainBar').setCommandEnabled('save', false);
110 sandbox.getModule('indicator').showMessage(gettext('Restoring version ') + event.version + '...');
112 historyItemAdded: function(item) {
113 sandbox.getModule('documentHistory').addHistory([item], {animate: true});
115 diffFetched: function(diff) {
116 sandbox.getModule('diffViewer').setDiff(diff);
118 documentReverted: function(event) {
119 commands.resetDocument(event.document, 'revert');
120 sandbox.getModule('mainBar').setCommandEnabled('save', true);
121 sandbox.getModule('indicator').clearMessage({message:'Wersja ' + event.reverted_version + ' przywrócona'});
122 sandbox.getModule('mainBar').setVersion(event.current_version);
126 eventHandlers.mainBar = {
128 sandbox.getModule('mainBar').setVersion(sandbox.getModule('data').getDocumentVersion());
129 views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
131 'cmd.save': function() {
132 sandbox.getModule('data').saveDocument();
136 eventHandlers.indicator = {
138 views.mainLayout.setView('messages', sandbox.getModule('indicator').getView());
144 eventHandlers.documentCanvas = {
146 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
147 views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());
150 currentTextElementSet: function(textElement) {
151 commands.updateCurrentTextElement(textElement);
154 currentNodeElementSet: function(nodeElement) {
155 commands.updateCurrentNodeElement(nodeElement);
158 currentNodeElementChanged: function(nodeElement) {
159 commands.updateCurrentNodeElement(nodeElement);
162 nodeHovered: function(canvasNode) {
163 commands.highlightDocumentNode(canvasNode);
166 nodeBlured: function(canvasNode) {
167 commands.dimDocumentNode(canvasNode);
171 eventHandlers.nodePane = {
173 views.currentNodePaneLayout.appendView(sandbox.getModule('nodePane').getView());
176 nodeElementChange: function(attr, value) {
177 sandbox.getModule('documentCanvas').modifyCurrentNodeElement(attr, value);
181 eventHandlers.metadataEditor = {
183 sandbox.getModule('metadataEditor').setDocument(sandbox.getModule('data').getDocument());
184 views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
188 eventHandlers.nodeFamilyTree = {
190 views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());
192 nodeEntered: function(node) {
193 commands.highlightDocumentElement(node, 'nodeFamilyTree');
195 nodeLeft: function(node) {
196 commands.dimDocumentElement(node, 'nodeFamilyTree');
198 nodeClicked: function(node) {
199 commands.jumpToDocumentElement(node);
203 eventHandlers.documentToolbar = {
205 views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());
207 command: function(cmd, params) {
208 sandbox.getModule('documentCanvas').command(cmd, params);
212 eventHandlers.nodeBreadCrumbs = {
214 views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());
216 elementEntered: function(element) {
217 commands.highlightDocumentElement(element, 'nodeBreadCrumbs');
219 elementLeft: function(element) {
220 commands.dimDocumentElement(element, 'nodeBreadCrumbs');
222 elementClicked: function(element) {
223 commands.jumpToDocumentElement(element);
227 eventHandlers.documentHistory = {
229 sandbox.getModule('documentHistory').addHistory(sandbox.getModule('data').getHistory());
230 views.diffLayout.setView('left', sandbox.getModule('documentHistory').getView());
232 compare: function(ver1, ver2) {
233 sandbox.getModule('data').fetchDiff(ver1, ver2);
235 restoreVersion: function(event) {
236 sandbox.getModule('data').restoreVersion(event);
238 displayVersion: function(event) {
239 window.open('/' + gettext('editor') + '/' + sandbox.getModule('data').getDocumentId() + '?version=' + event.version, _.uniqueId());
243 eventHandlers.diffViewer = {
245 views.diffLayout.setView('right', sandbox.getModule('diffViewer').getView());
253 sandbox.getModule('data').start();
255 handleEvent: function(moduleName, eventName, args) {
256 if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
257 eventHandlers[moduleName][eventName].apply(eventHandlers, args);