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
39 if(slug === 'editor') {
\r
40 var doc = dirty.documentCanvas ? sandbox.getModule('documentCanvas').getDocument() : sandbox.getModule('data').getDocument();
\r
41 if(dirty.metadataEditor) {
\r
42 doc = sandbox.getModule('metadataEditor').attachMetadata(doc);
\r
46 sandbox.getModule('data').commitDocument(doc, reason);
\r
51 highlightDocumentNode: function(wlxmlNode, origin) {
\r
52 ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {
\r
53 if(!origin || moduleName != origin)
\r
54 sandbox.getModule(moduleName).highlightNode(wlxmlNode)
\r
57 dimDocumentNode: function(wlxmlNode, origin) {
\r
58 ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {
\r
59 if(!origin || moduleName != origin)
\r
60 sandbox.getModule(moduleName).dimNode(wlxmlNode)
\r
63 selectNode: function(wlxmlNode, origin) {
\r
64 sandbox.getModule('documentCanvas').selectNode(wlxmlNode);
\r
65 sandbox.getModule('nodePane').setNode(wlxmlNode);
\r
66 sandbox.getModule('nodeFamilyTree').setNode(wlxmlNode);
\r
67 sandbox.getModule('nodeBreadCrumbs').setNode(wlxmlNode);
\r
74 mainLayout: new layout.Layout(mainLayoutTemplate),
\r
75 mainTabs: (new tabs.View()).render(),
\r
76 visualEditing: new layout.Layout(visualEditingLayoutTemplate),
\r
77 visualEditingSidebar: (new tabs.View({stacked: true})).render(),
\r
78 currentNodePaneLayout: new vbox.VBox(),
\r
79 diffLayout: new layout.Layout(diffLayoutTemplate)
\r
82 views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView());
\r
83 addMainTab('Edytor', 'editor', views.visualEditing.getAsView());
\r
85 addMainTab('Historia', 'history', views.diffLayout.getAsView());
\r
87 sandbox.getDOM().append(views.mainLayout.getAsView());
\r
89 views.visualEditingSidebar.addTab({icon: 'pencil'}, 'edit', views.currentNodePaneLayout.getAsView());
\r
91 views.mainTabs.on('tabSelected', function(event) {
\r
92 if(event.prevSlug) {
\r
93 synchronizeTab(event.prevSlug);
\r
97 /* Events handling */
\r
99 var eventHandlers = {};
\r
101 eventHandlers.sourceEditor = {
\r
102 ready: function() {
\r
103 addMainTab(gettext('Source'), 'sourceEditor', sandbox.getModule('sourceEditor').getView());
\r
104 sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());
\r
106 xmlChanged: function() {
\r
107 dirty.sourceEditor = true;
\r
109 documentSet: function() {
\r
110 dirty.sourceEditor = false;
\r
114 eventHandlers.data = {
\r
115 ready: function() {
\r
116 views.mainLayout.setView('mainView', views.mainTabs.getAsView());
\r
118 _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory', 'diffViewer'], function(moduleName) {
\r
119 sandbox.getModule(moduleName).start();
\r
122 documentChanged: function(document, reason) {
\r
124 if(reason === 'source_edit')
\r
125 modules = ['documentCanvas', 'metadataEditor'];
\r
126 else if (reason === 'edit')
\r
127 modules = ['sourceEditor'];
\r
129 modules.forEach(function(moduleName) {
\r
130 sandbox.getModule(moduleName).setDocument(document);
\r
133 savingStarted: function() {
\r
134 sandbox.getModule('mainBar').setCommandEnabled('save', false);
\r
135 sandbox.getModule('indicator').showMessage(gettext('Saving...'));
\r
137 savingEnded: function(status) {
\r
138 sandbox.getModule('mainBar').setCommandEnabled('save', true);
\r
139 sandbox.getModule('indicator').clearMessage({message:'Dokument zapisany'});
\r
141 historyItemAdded: function(item) {
\r
142 sandbox.getModule('documentHistory').addHistory([item], {animate: true});
\r
144 diffFetched: function(diff) {
\r
145 sandbox.getModule('diffViewer').setDiff(diff);
\r
149 eventHandlers.mainBar = {
\r
150 ready: function() {
\r
151 views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
\r
153 'cmd.save': function() {
\r
154 synchronizeTab(views.mainTabs.getCurrentSlug());
\r
155 sandbox.getModule('data').saveDocument();
\r
159 eventHandlers.indicator = {
\r
160 ready: function() {
\r
161 views.mainLayout.setView('messages', sandbox.getModule('indicator').getView());
\r
167 eventHandlers.documentCanvas = {
\r
168 ready: function() {
\r
169 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
\r
170 views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());
\r
172 documentSet: function() {
\r
173 dirty.documentCanvas = false;
\r
176 nodeSelected: function(wlxmlNode) {
\r
177 commands.selectNode(wlxmlNode);
\r
180 contentChanged: function() {
\r
181 dirty.documentCanvas = true;
\r
184 nodeHovered: function(wlxmlNode) {
\r
185 commands.highlightDocumentNode(wlxmlNode);
\r
188 nodeBlured: function(wlxmlNode) {
\r
189 commands.dimDocumentNode(wlxmlNode);
\r
193 eventHandlers.nodePane = {
\r
194 ready: function() {
\r
195 views.currentNodePaneLayout.appendView(sandbox.getModule('nodePane').getView());
\r
198 nodeChanged: function(attr, value) {
\r
199 sandbox.getModule('documentCanvas').modifyCurrentNode(attr, value);
\r
203 eventHandlers.metadataEditor = {
\r
204 ready: function() {
\r
205 sandbox.getModule('metadataEditor').setDocument(sandbox.getModule('data').getDocument());
\r
206 views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
\r
208 metadataChanged: function(metadata) {
\r
209 dirty.metadataEditor = true;
\r
211 metadataSet: function() {
\r
212 dirty.metadataEditor = false;
\r
216 eventHandlers.nodeFamilyTree = {
\r
217 ready: function() {
\r
218 views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());
\r
220 nodeEntered: function(wlxmlNode) {
\r
221 commands.highlightDocumentNode(wlxmlNode, 'nodeFamilyTree');
\r
223 nodeLeft: function(wlxmlNode) {
\r
224 commands.dimDocumentNode(wlxmlNode, 'nodeFamilyTree');
\r
226 nodeSelected: function(wlxmlNode) {
\r
227 commands.selectNode(wlxmlNode);
\r
231 eventHandlers.documentToolbar = {
\r
232 ready: function() {
\r
233 views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());
\r
235 toggleGrid: function(toggle) {
\r
236 sandbox.getModule('documentCanvas').toggleGrid(toggle);
\r
238 newNodeRequested: function(wlxmlTag, wlxmlClass) {
\r
239 if(window.getSelection().isCollapsed) {
\r
240 sandbox.getModule('documentCanvas').insertNewNode(wlxmlTag, wlxmlClass);
\r
242 sandbox.getModule('documentCanvas').wrapSelectionWithNewNode(wlxmlTag, wlxmlClass);
\r
247 eventHandlers.nodeBreadCrumbs = {
\r
248 ready: function() {
\r
249 views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());
\r
251 nodeHighlighted: function(wlxmlNode) {
\r
252 commands.highlightDocumentNode(wlxmlNode, 'nodeBreadCrumbs');
\r
254 nodeDimmed: function(wlxmlNode) {
\r
255 commands.dimDocumentNode(wlxmlNode, 'nodeBreadCrumbs');
\r
257 nodeSelected: function(wlxmlNode) {
\r
258 commands.selectNode(wlxmlNode);
\r
262 eventHandlers.documentHistory = {
\r
263 ready: function() {
\r
264 sandbox.getModule('documentHistory').addHistory(sandbox.getModule('data').getHistory());
\r
265 views.diffLayout.setView('left', sandbox.getModule('documentHistory').getView());
\r
267 compare: function(ver1, ver2) {
\r
268 sandbox.getModule('data').fetchDiff(ver1, ver2);
\r
272 eventHandlers.diffViewer = {
\r
273 ready: function() {
\r
274 views.diffLayout.setView('right', sandbox.getModule('diffViewer').getView());
\r
281 start: function() {
\r
282 sandbox.getModule('data').start();
\r
284 handleEvent: function(moduleName, eventName, args) {
\r
286 wysiwigHandler.handleEvent(moduleName, eventName, args);
\r
287 else if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
\r
288 eventHandlers[moduleName][eventName].apply(eventHandlers, args);
\r