5 'libs/text!./mainLayout.html',
\r
6 'libs/text!./editingLayout.html',
\r
7 ], function(layout, vbox, tabs, mainLayoutTemplate, visualEditingLayoutTemplate) {
\r
9 return function(sandbox) {
\r
12 function addMainTab(title, slug, view) {
\r
13 views.mainTabs.addTab(title, slug, view);
\r
16 function tabIsDirty(slug) {
\r
17 if(slug === 'editor' && (dirty.documentCanvas || dirty.metadataEditor))
\r
19 if(slug === 'sourceEditor' && dirty.sourceEditor)
\r
25 sourceEditor: false,
\r
26 documentCanvas: false,
\r
27 metadataEditor: false,
\r
30 var synchronizeTab = function(slug) {
\r
31 if(tabIsDirty(slug)) {
\r
32 if(slug === 'sourceEditor') {
\r
33 sandbox.getModule('data').commitDocument(sandbox.getModule('sourceEditor').getDocument(), 'source_edit');
\r
35 if(slug === 'editor') {
\r
36 var doc = dirty.documentCanvas ? sandbox.getModule('documentCanvas').getDocument() : sandbox.getModule('data').getDocument();
\r
37 if(dirty.metadataEditor) {
\r
38 doc = sandbox.getModule('metadataEditor').attachMetadata(doc);
\r
40 sandbox.getModule('data').commitDocument(doc, 'edit');
\r
46 highlightDocumentNode: function(wlxmlNode, origin) {
\r
47 ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {
\r
48 if(!origin || moduleName != origin)
\r
49 sandbox.getModule(moduleName).highlightNode(wlxmlNode)
\r
52 dimDocumentNode: function(wlxmlNode, origin) {
\r
53 ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {
\r
54 if(!origin || moduleName != origin)
\r
55 sandbox.getModule(moduleName).dimNode(wlxmlNode)
\r
58 selectNode: function(wlxmlNode, origin) {
\r
59 sandbox.getModule('documentCanvas').selectNode(wlxmlNode);
\r
60 sandbox.getModule('nodePane').setNode(wlxmlNode);
\r
61 sandbox.getModule('nodeFamilyTree').setNode(wlxmlNode);
\r
62 sandbox.getModule('nodeBreadCrumbs').setNode(wlxmlNode);
\r
69 mainLayout: new layout.Layout(mainLayoutTemplate),
\r
70 mainTabs: (new tabs.View()).render(),
\r
71 visualEditing: new layout.Layout(visualEditingLayoutTemplate),
\r
72 visualEditingSidebar: (new tabs.View({stacked: true})).render(),
\r
73 currentNodePaneLayout: new vbox.VBox()
\r
76 views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView());
\r
77 addMainTab('Edytor', 'editor', views.visualEditing.getAsView());
\r
79 sandbox.getDOM().append(views.mainLayout.getAsView());
\r
81 views.visualEditingSidebar.addTab({icon: 'pencil'}, 'edit', views.currentNodePaneLayout.getAsView());
\r
83 views.mainTabs.on('tabSelected', function(event) {
\r
84 if(event.prevSlug) {
\r
85 synchronizeTab(event.prevSlug);
\r
89 /* Events handling */
\r
91 var eventHandlers = {};
\r
93 eventHandlers.sourceEditor = {
\r
95 addMainTab(gettext('Source'), 'sourceEditor', sandbox.getModule('sourceEditor').getView());
\r
96 sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());
\r
98 xmlChanged: function() {
\r
99 dirty.sourceEditor = true;
\r
101 documentSet: function() {
\r
102 dirty.sourceEditor = false;
\r
106 eventHandlers.data = {
\r
107 ready: function() {
\r
108 views.mainLayout.setView('mainView', views.mainTabs.getAsView());
\r
110 _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator'], function(moduleName) {
\r
111 sandbox.getModule(moduleName).start();
\r
114 documentChanged: function(document, reason) {
\r
116 if(reason === 'source_edit')
\r
117 modules = ['documentCanvas', 'metadataEditor'];
\r
118 else if (reason === 'edit')
\r
119 modules = ['sourceEditor'];
\r
121 modules.forEach(function(moduleName) {
\r
122 sandbox.getModule(moduleName).setDocument(document);
\r
125 savingStarted: function() {
\r
126 sandbox.getModule('mainBar').setCommandEnabled('save', false);
\r
127 sandbox.getModule('indicator').showMessage(gettext('Saving...'));
\r
129 savingEnded: function(status) {
\r
130 sandbox.getModule('mainBar').setCommandEnabled('save', true);
\r
131 sandbox.getModule('indicator').clearMessage();
\r
135 eventHandlers.mainBar = {
\r
136 ready: function() {
\r
137 views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
\r
139 'cmd.save': function() {
\r
140 synchronizeTab(views.mainTabs.getCurrentSlug());
\r
141 sandbox.getModule('data').saveDocument();
\r
145 eventHandlers.indicator = {
\r
146 ready: function() {
\r
147 views.mainLayout.setView('messages', sandbox.getModule('indicator').getView());
\r
153 eventHandlers.documentCanvas = {
\r
154 ready: function() {
\r
155 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
\r
156 views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());
\r
158 documentSet: function() {
\r
159 dirty.documentCanvas = false;
\r
162 nodeSelected: function(wlxmlNode) {
\r
163 commands.selectNode(wlxmlNode);
\r
166 contentChanged: function() {
\r
167 dirty.documentCanvas = true;
\r
170 nodeHovered: function(wlxmlNode) {
\r
171 commands.highlightDocumentNode(wlxmlNode);
\r
174 nodeBlured: function(wlxmlNode) {
\r
175 commands.dimDocumentNode(wlxmlNode);
\r
179 eventHandlers.nodePane = {
\r
180 ready: function() {
\r
181 views.currentNodePaneLayout.appendView(sandbox.getModule('nodePane').getView());
\r
184 nodeChanged: function(attr, value) {
\r
185 sandbox.getModule('documentCanvas').modifyCurrentNode(attr, value);
\r
189 eventHandlers.metadataEditor = {
\r
190 ready: function() {
\r
191 sandbox.getModule('metadataEditor').setDocument(sandbox.getModule('data').getDocument());
\r
192 views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
\r
194 metadataChanged: function(metadata) {
\r
195 dirty.metadataEditor = true;
\r
197 metadataSet: function() {
\r
198 dirty.metadataEditor = false;
\r
202 eventHandlers.nodeFamilyTree = {
\r
203 ready: function() {
\r
204 views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());
\r
206 nodeEntered: function(wlxmlNode) {
\r
207 commands.highlightDocumentNode(wlxmlNode, 'nodeFamilyTree');
\r
209 nodeLeft: function(wlxmlNode) {
\r
210 commands.dimDocumentNode(wlxmlNode, 'nodeFamilyTree');
\r
212 nodeSelected: function(wlxmlNode) {
\r
213 commands.selectNode(wlxmlNode);
\r
217 eventHandlers.documentToolbar = {
\r
218 ready: function() {
\r
219 views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());
\r
221 toggleGrid: function(toggle) {
\r
222 sandbox.getModule('documentCanvas').toggleGrid(toggle);
\r
224 newNodeRequested: function(wlxmlTag, wlxmlClass) {
\r
225 if(window.getSelection().isCollapsed) {
\r
226 sandbox.getModule('documentCanvas').insertNewNode(wlxmlTag, wlxmlClass);
\r
228 sandbox.getModule('documentCanvas').wrapSelectionWithNewNode(wlxmlTag, wlxmlClass);
\r
233 eventHandlers.nodeBreadCrumbs = {
\r
234 ready: function() {
\r
235 views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());
\r
237 nodeHighlighted: function(wlxmlNode) {
\r
238 commands.highlightDocumentNode(wlxmlNode, 'nodeBreadCrumbs');
\r
240 nodeDimmed: function(wlxmlNode) {
\r
241 commands.dimDocumentNode(wlxmlNode, 'nodeBreadCrumbs');
\r
243 nodeSelected: function(wlxmlNode) {
\r
244 commands.selectNode(wlxmlNode);
\r
251 start: function() {
\r
252 sandbox.getModule('data').start();
\r
254 handleEvent: function(moduleName, eventName, args) {
\r
256 wysiwigHandler.handleEvent(moduleName, eventName, args);
\r
257 else if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
\r
258 eventHandlers[moduleName][eventName].apply(eventHandlers, args);
\r