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);
53 mainLayout: new layout.Layout(mainLayoutTemplate),
54 mainTabs: (new tabs.View()).render(),
55 visualEditing: new layout.Layout(visualEditingLayoutTemplate),
56 visualEditingSidebar: (new tabs.View({stacked: true})).render(),
57 currentNodePaneLayout: new vbox.VBox(),
58 diffLayout: new layout.Layout(diffLayoutTemplate)
61 views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView());
62 addMainTab('Edytor', 'editor', views.visualEditing.getAsView());
63 addMainTab(gettext('Source'), 'sourceEditor', '');
64 addMainTab('Historia', 'history', views.diffLayout.getAsView());
66 sandbox.getDOM().append(views.mainLayout.getAsView());
68 views.visualEditingSidebar.addTab({icon: 'pencil'}, 'edit', views.currentNodePaneLayout.getAsView());
73 var eventHandlers = {};
75 eventHandlers.sourceEditor = {
77 addMainTab(gettext('Source'), 'sourceEditor', sandbox.getModule('sourceEditor').getView());
78 sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());
82 eventHandlers.data = {
84 views.mainLayout.setView('mainView', views.mainTabs.getAsView());
86 _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory', 'diffViewer'], function(moduleName) {
87 sandbox.getModule(moduleName).start();
90 savingStarted: function() {
91 sandbox.getModule('mainBar').setCommandEnabled('save', false);
92 sandbox.getModule('indicator').showMessage(gettext('Saving...'));
94 savingEnded: function(status, current_version) {
96 sandbox.getModule('mainBar').setCommandEnabled('save', true);
97 sandbox.getModule('indicator').clearMessage({message:'Dokument zapisany'});
98 sandbox.getModule('mainBar').setVersion(current_version);
100 restoringStarted: function(event) {
101 sandbox.getModule('mainBar').setCommandEnabled('save', false);
102 sandbox.getModule('indicator').showMessage(gettext('Restoring version ') + event.version + '...');
104 historyItemAdded: function(item) {
105 sandbox.getModule('documentHistory').addHistory([item], {animate: true});
107 diffFetched: function(diff) {
108 sandbox.getModule('diffViewer').setDiff(diff);
110 documentReverted: function(event) {
111 sandbox.getModule('mainBar').setCommandEnabled('save', true);
112 sandbox.getModule('indicator').clearMessage({message:'Wersja ' + event.reverted_version + ' przywrócona'});
113 sandbox.getModule('mainBar').setVersion(event.current_version);
117 eventHandlers.mainBar = {
119 sandbox.getModule('mainBar').setVersion(sandbox.getModule('data').getDocumentVersion());
120 views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
122 'cmd.save': function() {
123 sandbox.getModule('data').saveDocument();
127 eventHandlers.indicator = {
129 views.mainLayout.setView('messages', sandbox.getModule('indicator').getView());
135 eventHandlers.documentCanvas = {
137 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
138 views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());
141 currentTextElementSet: function(textElement) {
142 commands.updateCurrentTextElement(textElement);
145 currentNodeElementSet: function(nodeElement) {
146 commands.updateCurrentNodeElement(nodeElement);
149 currentNodeElementChanged: function(nodeElement) {
150 commands.updateCurrentNodeElement(nodeElement);
153 nodeHovered: function(canvasNode) {
154 commands.highlightDocumentNode(canvasNode);
157 nodeBlured: function(canvasNode) {
158 commands.dimDocumentNode(canvasNode);
162 eventHandlers.nodePane = {
164 views.currentNodePaneLayout.appendView(sandbox.getModule('nodePane').getView());
167 nodeElementChange: function(attr, value) {
168 sandbox.getModule('documentCanvas').modifyCurrentNodeElement(attr, value);
172 eventHandlers.metadataEditor = {
174 sandbox.getModule('metadataEditor').setDocument(sandbox.getModule('data').getDocument());
175 views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
179 eventHandlers.nodeFamilyTree = {
181 views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());
183 nodeEntered: function(node) {
184 commands.highlightDocumentElement(node, 'nodeFamilyTree');
186 nodeLeft: function(node) {
187 commands.dimDocumentElement(node, 'nodeFamilyTree');
189 nodeClicked: function(node) {
190 commands.jumpToDocumentElement(node);
194 eventHandlers.documentToolbar = {
196 views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());
198 command: function(cmd, params) {
199 sandbox.getModule('documentCanvas').command(cmd, params);
203 eventHandlers.nodeBreadCrumbs = {
205 views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());
207 elementEntered: function(element) {
208 commands.highlightDocumentElement(element, 'nodeBreadCrumbs');
210 elementLeft: function(element) {
211 commands.dimDocumentElement(element, 'nodeBreadCrumbs');
213 elementClicked: function(element) {
214 commands.jumpToDocumentElement(element);
218 eventHandlers.documentHistory = {
220 sandbox.getModule('documentHistory').addHistory(sandbox.getModule('data').getHistory());
221 views.diffLayout.setView('left', sandbox.getModule('documentHistory').getView());
223 compare: function(ver1, ver2) {
224 sandbox.getModule('data').fetchDiff(ver1, ver2);
226 restoreVersion: function(event) {
227 sandbox.getModule('data').restoreVersion(event);
229 displayVersion: function(event) {
231 window.open('/' + gettext('editor') + '/' + sandbox.getModule('data').getDocumentId() + '?version=' + event.version, _.uniqueId());
235 eventHandlers.diffViewer = {
237 views.diffLayout.setView('right', sandbox.getModule('diffViewer').getView());
245 sandbox.getModule('data').start();
247 handleEvent: function(moduleName, eventName, args) {
248 if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
249 eventHandlers[moduleName][eventName].apply(eventHandlers, args);