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) {
96 sandbox.getModule('mainBar').setCommandEnabled('save', true);
97 sandbox.getModule('indicator').clearMessage({message:'Dokument zapisany'});
99 restoringStarted: function(event) {
100 sandbox.getModule('mainBar').setCommandEnabled('save', false);
101 sandbox.getModule('indicator').showMessage(gettext('Restoring version ') + event.version + '...');
103 historyItemAdded: function(item) {
104 sandbox.getModule('documentHistory').addHistory([item], {animate: true});
106 diffFetched: function(diff) {
107 sandbox.getModule('diffViewer').setDiff(diff);
109 documentReverted: function(event) {
110 sandbox.getModule('mainBar').setCommandEnabled('save', true);
111 sandbox.getModule('indicator').clearMessage({message:'Wersja ' + event.reverted_version + ' przywrócona'});
112 sandbox.getModule('mainBar').setVersion(event.current_version);
116 eventHandlers.mainBar = {
118 sandbox.getModule('mainBar').setVersion(sandbox.getModule('data').getDocumentVersion());
119 views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
121 'cmd.save': function() {
122 sandbox.getModule('data').saveDocument();
126 eventHandlers.indicator = {
128 views.mainLayout.setView('messages', sandbox.getModule('indicator').getView());
134 eventHandlers.documentCanvas = {
136 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
137 views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());
140 currentTextElementSet: function(textElement) {
141 commands.updateCurrentTextElement(textElement);
144 currentNodeElementSet: function(nodeElement) {
145 commands.updateCurrentNodeElement(nodeElement);
148 currentNodeElementChanged: function(nodeElement) {
149 commands.updateCurrentNodeElement(nodeElement);
152 nodeHovered: function(canvasNode) {
153 commands.highlightDocumentNode(canvasNode);
156 nodeBlured: function(canvasNode) {
157 commands.dimDocumentNode(canvasNode);
161 eventHandlers.nodePane = {
163 views.currentNodePaneLayout.appendView(sandbox.getModule('nodePane').getView());
166 nodeElementChange: function(attr, value) {
167 sandbox.getModule('documentCanvas').modifyCurrentNodeElement(attr, value);
171 eventHandlers.metadataEditor = {
173 sandbox.getModule('metadataEditor').setDocument(sandbox.getModule('data').getDocument());
174 views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
178 eventHandlers.nodeFamilyTree = {
180 views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());
182 nodeEntered: function(node) {
183 commands.highlightDocumentElement(node, 'nodeFamilyTree');
185 nodeLeft: function(node) {
186 commands.dimDocumentElement(node, 'nodeFamilyTree');
188 nodeClicked: function(node) {
189 commands.jumpToDocumentElement(node);
193 eventHandlers.documentToolbar = {
195 views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());
197 command: function(cmd, params) {
198 sandbox.getModule('documentCanvas').command(cmd, params);
202 eventHandlers.nodeBreadCrumbs = {
204 views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());
206 elementEntered: function(element) {
207 commands.highlightDocumentElement(element, 'nodeBreadCrumbs');
209 elementLeft: function(element) {
210 commands.dimDocumentElement(element, 'nodeBreadCrumbs');
212 elementClicked: function(element) {
213 commands.jumpToDocumentElement(element);
217 eventHandlers.documentHistory = {
219 sandbox.getModule('documentHistory').addHistory(sandbox.getModule('data').getHistory());
220 views.diffLayout.setView('left', sandbox.getModule('documentHistory').getView());
222 compare: function(ver1, ver2) {
223 sandbox.getModule('data').fetchDiff(ver1, ver2);
225 restoreVersion: function(event) {
226 sandbox.getModule('data').restoreVersion(event);
228 displayVersion: function(event) {
230 window.open('/' + gettext('editor') + '/' + sandbox.getModule('data').getDocumentId() + '?version=' + event.version, _.uniqueId());
234 eventHandlers.diffViewer = {
236 views.diffLayout.setView('right', sandbox.getModule('diffViewer').getView());
244 sandbox.getModule('data').start();
246 handleEvent: function(moduleName, eventName, args) {
247 if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
248 eventHandlers[moduleName][eventName].apply(eventHandlers, args);