5 'libs/text!./mainLayout.html',
\r
6 'libs/text!./editingLayout.html',
\r
7 'libs/text!./diffLayout.html',
\r
8 ], function(layout, vbox, tabs, mainLayoutTemplate, visualEditingLayoutTemplate, diffLayoutTemplate) {
\r
12 return function(sandbox) {
\r
14 function addMainTab(title, slug, view) {
\r
15 views.mainTabs.addTab(title, slug, view);
\r
19 sourceEditor: false,
\r
20 documentCanvas: false,
\r
21 metadataEditor: false,
\r
24 var synchronizeTab = function(slug) {
\r
25 function tabIsDirty(slug) {
\r
26 if(slug === 'editor' && (dirty.documentCanvas || dirty.metadataEditor))
\r
28 if(slug === 'sourceEditor' && dirty.sourceEditor)
\r
33 if(tabIsDirty(slug)) {
\r
35 if(slug === 'sourceEditor') {
\r
36 doc = sandbox.getModule('sourceEditor').getDocument();
\r
37 reason = 'source_edit';
\r
38 dirty.sourceEditor = false;
\r
40 if(slug === 'editor') {
\r
41 var doc = dirty.documentCanvas ? sandbox.getModule('documentCanvas').getDocument() : sandbox.getModule('data').getDocument();
\r
42 if(dirty.metadataEditor) {
\r
43 doc = sandbox.getModule('metadataEditor').attachMetadata(doc);
\r
46 dirty.documentCanvas = dirty.metadataEditor = false;
\r
48 sandbox.getModule('data').commitDocument(doc, reason);
\r
53 highlightDocumentNode: function(wlxmlNode, origin) {
\r
54 ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {
\r
55 if(!origin || moduleName != origin)
\r
56 sandbox.getModule(moduleName).highlightNode(wlxmlNode)
\r
59 dimDocumentNode: function(wlxmlNode, origin) {
\r
60 ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {
\r
61 if(!origin || moduleName != origin)
\r
62 sandbox.getModule(moduleName).dimNode(wlxmlNode)
\r
65 selectNode: function(wlxmlNode, origin) {
\r
66 sandbox.getModule('documentCanvas').selectNode(wlxmlNode);
\r
67 sandbox.getModule('nodePane').setNode(wlxmlNode);
\r
68 sandbox.getModule('nodeFamilyTree').setNode(wlxmlNode);
\r
69 sandbox.getModule('nodeBreadCrumbs').setNode(wlxmlNode);
\r
72 resetDocument: function(document, reason) {
\r
74 if(reason === 'source_edit')
\r
75 modules = ['documentCanvas', 'metadataEditor'];
\r
76 else if (reason === 'edit')
\r
77 modules = ['sourceEditor'];
\r
78 else if (reason === 'revert')
\r
79 modules = ['documentCanvas', 'metadataEditor', 'sourceEditor'];
\r
81 modules.forEach(function(moduleName) {
\r
82 sandbox.getModule(moduleName).setDocument(document);
\r
89 mainLayout: new layout.Layout(mainLayoutTemplate),
\r
90 mainTabs: (new tabs.View()).render(),
\r
91 visualEditing: new layout.Layout(visualEditingLayoutTemplate),
\r
92 visualEditingSidebar: (new tabs.View({stacked: true})).render(),
\r
93 currentNodePaneLayout: new vbox.VBox(),
\r
94 diffLayout: new layout.Layout(diffLayoutTemplate)
\r
97 views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView());
\r
98 addMainTab('Edytor', 'editor', views.visualEditing.getAsView());
\r
99 addMainTab(gettext('Source'), 'sourceEditor', '');
\r
100 addMainTab('Historia', 'history', views.diffLayout.getAsView());
\r
102 sandbox.getDOM().append(views.mainLayout.getAsView());
\r
104 views.visualEditingSidebar.addTab({icon: 'pencil'}, 'edit', views.currentNodePaneLayout.getAsView());
\r
106 views.mainTabs.on('tabSelected', function(event) {
\r
107 if(event.prevSlug) {
\r
108 synchronizeTab(event.prevSlug);
\r
112 /* Events handling */
\r
114 var eventHandlers = {};
\r
116 eventHandlers.sourceEditor = {
\r
117 ready: function() {
\r
118 addMainTab(gettext('Source'), 'sourceEditor', sandbox.getModule('sourceEditor').getView());
\r
119 sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());
\r
121 xmlChanged: function() {
\r
122 dirty.sourceEditor = true;
\r
124 documentSet: function() {
\r
125 dirty.sourceEditor = false;
\r
129 eventHandlers.data = {
\r
130 ready: function() {
\r
131 views.mainLayout.setView('mainView', views.mainTabs.getAsView());
\r
133 _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory', 'diffViewer'], function(moduleName) {
\r
134 sandbox.getModule(moduleName).start();
\r
137 documentChanged: function(document, reason) {
\r
138 commands.resetDocument(document, reason);
\r
140 savingStarted: function() {
\r
141 sandbox.getModule('mainBar').setCommandEnabled('save', false);
\r
142 sandbox.getModule('indicator').showMessage(gettext('Saving...'));
\r
144 savingEnded: function(status) {
\r
145 sandbox.getModule('mainBar').setCommandEnabled('save', true);
\r
146 sandbox.getModule('indicator').clearMessage({message:'Dokument zapisany'});
\r
148 restoringStarted: function(event) {
\r
149 sandbox.getModule('mainBar').setCommandEnabled('save', false);
\r
150 sandbox.getModule('indicator').showMessage(gettext('Restoring version ') + event.version + '...');
\r
152 historyItemAdded: function(item) {
\r
153 sandbox.getModule('documentHistory').addHistory([item], {animate: true});
\r
155 diffFetched: function(diff) {
\r
156 sandbox.getModule('diffViewer').setDiff(diff);
\r
158 documentReverted: function(event) {
\r
159 commands.resetDocument(event.document, 'revert');
\r
160 sandbox.getModule('mainBar').setCommandEnabled('save', true);
\r
161 sandbox.getModule('indicator').clearMessage({message:'Wersja ' + event.reverted_version + ' przywrócona'});
\r
162 sandbox.getModule('mainBar').setVersion(event.current_version);
\r
166 eventHandlers.mainBar = {
\r
167 ready: function() {
\r
168 sandbox.getModule('mainBar').setVersion(sandbox.getModule('data').getDocumentVersion());
\r
169 views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
\r
171 'cmd.save': function() {
\r
172 synchronizeTab(views.mainTabs.getCurrentSlug());
\r
173 sandbox.getModule('data').saveDocument();
\r
177 eventHandlers.indicator = {
\r
178 ready: function() {
\r
179 views.mainLayout.setView('messages', sandbox.getModule('indicator').getView());
\r
185 eventHandlers.documentCanvas = {
\r
186 ready: function() {
\r
187 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
\r
188 views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());
\r
190 documentSet: function() {
\r
191 dirty.documentCanvas = false;
\r
194 nodeSelected: function(wlxmlNode) {
\r
195 commands.selectNode(wlxmlNode);
\r
198 contentChanged: function() {
\r
199 dirty.documentCanvas = true;
\r
202 nodeHovered: function(wlxmlNode) {
\r
203 commands.highlightDocumentNode(wlxmlNode);
\r
206 nodeBlured: function(wlxmlNode) {
\r
207 commands.dimDocumentNode(wlxmlNode);
\r
211 eventHandlers.nodePane = {
\r
212 ready: function() {
\r
213 views.currentNodePaneLayout.appendView(sandbox.getModule('nodePane').getView());
\r
216 nodeChanged: function(attr, value) {
\r
217 sandbox.getModule('documentCanvas').modifyCurrentNode(attr, value);
\r
221 eventHandlers.metadataEditor = {
\r
222 ready: function() {
\r
223 sandbox.getModule('metadataEditor').setDocument(sandbox.getModule('data').getDocument());
\r
224 views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
\r
226 metadataChanged: function(metadata) {
\r
227 dirty.metadataEditor = true;
\r
229 metadataSet: function() {
\r
230 dirty.metadataEditor = false;
\r
234 eventHandlers.nodeFamilyTree = {
\r
235 ready: function() {
\r
236 views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());
\r
238 nodeEntered: function(wlxmlNode) {
\r
239 commands.highlightDocumentNode(wlxmlNode, 'nodeFamilyTree');
\r
241 nodeLeft: function(wlxmlNode) {
\r
242 commands.dimDocumentNode(wlxmlNode, 'nodeFamilyTree');
\r
244 nodeSelected: function(wlxmlNode) {
\r
245 commands.selectNode(wlxmlNode);
\r
249 eventHandlers.documentToolbar = {
\r
250 ready: function() {
\r
251 views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());
\r
253 toggleGrid: function(toggle) {
\r
254 sandbox.getModule('documentCanvas').toggleGrid(toggle);
\r
256 newNodeRequested: function(wlxmlTag, wlxmlClass) {
\r
257 if(window.getSelection().isCollapsed) {
\r
258 sandbox.getModule('documentCanvas').insertNewNode(wlxmlTag, wlxmlClass);
\r
260 sandbox.getModule('documentCanvas').wrapSelectionWithNewNode(wlxmlTag, wlxmlClass);
\r
265 eventHandlers.nodeBreadCrumbs = {
\r
266 ready: function() {
\r
267 views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());
\r
269 nodeHighlighted: function(wlxmlNode) {
\r
270 commands.highlightDocumentNode(wlxmlNode, 'nodeBreadCrumbs');
\r
272 nodeDimmed: function(wlxmlNode) {
\r
273 commands.dimDocumentNode(wlxmlNode, 'nodeBreadCrumbs');
\r
275 nodeSelected: function(wlxmlNode) {
\r
276 commands.selectNode(wlxmlNode);
\r
280 eventHandlers.documentHistory = {
\r
281 ready: function() {
\r
282 sandbox.getModule('documentHistory').addHistory(sandbox.getModule('data').getHistory());
\r
283 views.diffLayout.setView('left', sandbox.getModule('documentHistory').getView());
\r
285 compare: function(ver1, ver2) {
\r
286 sandbox.getModule('data').fetchDiff(ver1, ver2);
\r
288 restoreVersion: function(event) {
\r
289 sandbox.getModule('data').restoreVersion(event);
\r
291 displayVersion: function(event) {
\r
292 window.open('/' + gettext('editor') + '/' + sandbox.getModule('data').getDocumentId() + '?version=' + event.version, _.uniqueId());
\r
296 eventHandlers.diffViewer = {
\r
297 ready: function() {
\r
298 views.diffLayout.setView('right', sandbox.getModule('diffViewer').getView());
\r
305 start: function() {
\r
306 sandbox.getModule('data').start();
\r
308 handleEvent: function(moduleName, eventName, args) {
\r
310 wysiwigHandler.handleEvent(moduleName, eventName, args);
\r
311 else if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
\r
312 eventHandlers[moduleName][eventName].apply(eventHandlers, args);
\r