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);
45 sandbox.getModule('documentToolbar').setNodeElement(nodeElement);
47 updateCurrentTextElement: function(textElement) {
48 sandbox.getModule('nodeFamilyTree').setElement(textElement);
54 mainLayout: new layout.Layout(mainLayoutTemplate),
55 mainTabs: (new tabs.View()).render(),
56 visualEditing: new layout.Layout(visualEditingLayoutTemplate),
57 visualEditingSidebar: (new tabs.View({stacked: true})).render(),
58 currentNodePaneLayout: new vbox.VBox(),
59 diffLayout: new layout.Layout(diffLayoutTemplate)
62 views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView());
63 addMainTab('Edytor', 'editor', views.visualEditing.getAsView());
64 addMainTab(gettext('Source'), 'sourceEditor', '');
65 addMainTab('Historia', 'history', views.diffLayout.getAsView());
67 sandbox.getDOM().append(views.mainLayout.getAsView());
69 views.visualEditingSidebar.addTab({icon: 'pencil'}, 'edit', views.currentNodePaneLayout.getAsView());
74 var eventHandlers = {};
76 eventHandlers.sourceEditor = {
78 addMainTab(gettext('Source'), 'sourceEditor', sandbox.getModule('sourceEditor').getView());
79 sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());
83 eventHandlers.data = {
85 views.mainLayout.setView('mainView', views.mainTabs.getAsView());
87 _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory', 'diffViewer'], function(moduleName) {
88 sandbox.getModule(moduleName).start();
91 savingStarted: function() {
92 sandbox.getModule('mainBar').setCommandEnabled('save', false);
93 sandbox.getModule('indicator').showMessage(gettext('Saving...'));
95 savingEnded: function(status, current_version) {
97 sandbox.getModule('mainBar').setCommandEnabled('save', true);
98 sandbox.getModule('indicator').clearMessage({message:'Dokument zapisany'});
99 sandbox.getModule('mainBar').setVersion(current_version);
101 restoringStarted: function(event) {
102 sandbox.getModule('mainBar').setCommandEnabled('save', false);
103 sandbox.getModule('indicator').showMessage(gettext('Restoring version ') + event.version + '...');
105 historyItemAdded: function(item) {
106 sandbox.getModule('documentHistory').addHistory([item], {animate: true});
108 diffFetched: function(diff) {
109 sandbox.getModule('diffViewer').setDiff(diff);
111 documentReverted: function(version) {
112 sandbox.getModule('mainBar').setCommandEnabled('save', true);
113 sandbox.getModule('indicator').clearMessage({message:'Wersja ' + version + ' przywrócona'});
114 sandbox.getModule('mainBar').setVersion(version);
118 eventHandlers.mainBar = {
120 sandbox.getModule('mainBar').setVersion(sandbox.getModule('data').getDocumentVersion());
121 views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
123 'cmd.save': function() {
124 sandbox.getModule('data').saveDocument();
128 eventHandlers.indicator = {
130 views.mainLayout.setView('messages', sandbox.getModule('indicator').getView());
136 eventHandlers.documentCanvas = {
138 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
139 views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());
142 currentTextElementSet: function(textElement) {
143 commands.updateCurrentTextElement(textElement);
146 currentNodeElementSet: function(nodeElement) {
147 commands.updateCurrentNodeElement(nodeElement);
150 currentNodeElementChanged: function(nodeElement) {
151 commands.updateCurrentNodeElement(nodeElement);
154 nodeHovered: function(canvasNode) {
155 commands.highlightDocumentNode(canvasNode);
158 nodeBlured: function(canvasNode) {
159 commands.dimDocumentNode(canvasNode);
163 eventHandlers.nodePane = {
165 views.currentNodePaneLayout.appendView(sandbox.getModule('nodePane').getView());
168 nodeElementChange: function(attr, value) {
169 sandbox.getModule('documentCanvas').modifyCurrentNodeElement(attr, value);
173 eventHandlers.metadataEditor = {
175 sandbox.getModule('metadataEditor').setDocument(sandbox.getModule('data').getDocument());
176 views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
180 eventHandlers.nodeFamilyTree = {
182 views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());
184 nodeEntered: function(node) {
185 commands.highlightDocumentElement(node, 'nodeFamilyTree');
187 nodeLeft: function(node) {
188 commands.dimDocumentElement(node, 'nodeFamilyTree');
190 nodeClicked: function(node) {
191 commands.jumpToDocumentElement(node);
195 eventHandlers.documentToolbar = {
197 views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());
199 command: function(cmd, params) {
200 sandbox.getModule('documentCanvas').command(cmd, params);
204 eventHandlers.nodeBreadCrumbs = {
206 views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());
208 elementEntered: function(element) {
209 commands.highlightDocumentElement(element, 'nodeBreadCrumbs');
211 elementLeft: function(element) {
212 commands.dimDocumentElement(element, 'nodeBreadCrumbs');
214 elementClicked: function(element) {
215 commands.jumpToDocumentElement(element);
219 eventHandlers.documentHistory = {
221 sandbox.getModule('documentHistory').addHistory(sandbox.getModule('data').getHistory());
222 views.diffLayout.setView('left', sandbox.getModule('documentHistory').getView());
224 compare: function(ver1, ver2) {
225 sandbox.getModule('data').fetchDiff(ver1, ver2);
227 restoreVersion: function(version) {
228 sandbox.getModule('data').restoreVersion(version);
230 displayVersion: function(event) {
232 window.open('/' + gettext('editor') + '/' + sandbox.getModule('data').getDocumentId() + '?version=' + event.version, _.uniqueId());
236 eventHandlers.diffViewer = {
238 views.diffLayout.setView('right', sandbox.getModule('diffViewer').getView());
246 sandbox.getModule('data').start();
248 handleEvent: function(moduleName, eventName, args) {
249 if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
250 eventHandlers[moduleName][eventName].apply(eventHandlers, args);