5 'libs/text!./mainLayout.html',
\r
6 'libs/text!./editingLayout.html',
\r
7 ], function(layout, vbox, tabs, mainLayoutTemplate, visualEditingLayoutTemplate) {
\r
11 return function(sandbox) {
\r
13 function addMainTab(title, slug, view) {
\r
14 views.mainTabs.addTab(title, slug, view);
\r
18 sourceEditor: false,
\r
19 documentCanvas: false,
\r
20 metadataEditor: false,
\r
23 var synchronizeTab = function(slug) {
\r
24 function tabIsDirty(slug) {
\r
25 if(slug === 'editor' && (dirty.documentCanvas || dirty.metadataEditor))
\r
27 if(slug === 'sourceEditor' && dirty.sourceEditor)
\r
32 if(tabIsDirty(slug)) {
\r
34 if(slug === 'sourceEditor') {
\r
35 doc = sandbox.getModule('sourceEditor').getDocument();
\r
36 reason = 'source_edit';
\r
38 if(slug === 'editor') {
\r
39 var doc = dirty.documentCanvas ? sandbox.getModule('documentCanvas').getDocument() : sandbox.getModule('data').getDocument();
\r
40 if(dirty.metadataEditor) {
\r
41 doc = sandbox.getModule('metadataEditor').attachMetadata(doc);
\r
45 sandbox.getModule('data').commitDocument(doc, reason);
\r
50 highlightDocumentNode: function(wlxmlNode, origin) {
\r
51 ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {
\r
52 if(!origin || moduleName != origin)
\r
53 sandbox.getModule(moduleName).highlightNode(wlxmlNode)
\r
56 dimDocumentNode: function(wlxmlNode, origin) {
\r
57 ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {
\r
58 if(!origin || moduleName != origin)
\r
59 sandbox.getModule(moduleName).dimNode(wlxmlNode)
\r
62 selectNode: function(wlxmlNode, origin) {
\r
63 sandbox.getModule('documentCanvas').selectNode(wlxmlNode);
\r
64 sandbox.getModule('nodePane').setNode(wlxmlNode);
\r
65 sandbox.getModule('nodeFamilyTree').setNode(wlxmlNode);
\r
66 sandbox.getModule('nodeBreadCrumbs').setNode(wlxmlNode);
\r
73 mainLayout: new layout.Layout(mainLayoutTemplate),
\r
74 mainTabs: (new tabs.View()).render(),
\r
75 visualEditing: new layout.Layout(visualEditingLayoutTemplate),
\r
76 visualEditingSidebar: (new tabs.View({stacked: true})).render(),
\r
77 currentNodePaneLayout: new vbox.VBox()
\r
80 views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView());
\r
81 addMainTab('Edytor', 'editor', views.visualEditing.getAsView());
\r
83 sandbox.getDOM().append(views.mainLayout.getAsView());
\r
85 views.visualEditingSidebar.addTab({icon: 'pencil'}, 'edit', views.currentNodePaneLayout.getAsView());
\r
87 views.mainTabs.on('tabSelected', function(event) {
\r
88 if(event.prevSlug) {
\r
89 synchronizeTab(event.prevSlug);
\r
93 /* Events handling */
\r
95 var eventHandlers = {};
\r
97 eventHandlers.sourceEditor = {
\r
99 addMainTab(gettext('Source'), 'sourceEditor', sandbox.getModule('sourceEditor').getView());
\r
100 sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());
\r
102 xmlChanged: function() {
\r
103 dirty.sourceEditor = true;
\r
105 documentSet: function() {
\r
106 dirty.sourceEditor = false;
\r
110 eventHandlers.data = {
\r
111 ready: function() {
\r
112 views.mainLayout.setView('mainView', views.mainTabs.getAsView());
\r
114 _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory'], function(moduleName) {
\r
115 sandbox.getModule(moduleName).start();
\r
118 documentChanged: function(document, reason) {
\r
120 if(reason === 'source_edit')
\r
121 modules = ['documentCanvas', 'metadataEditor'];
\r
122 else if (reason === 'edit')
\r
123 modules = ['sourceEditor'];
\r
125 modules.forEach(function(moduleName) {
\r
126 sandbox.getModule(moduleName).setDocument(document);
\r
129 savingStarted: function() {
\r
130 sandbox.getModule('mainBar').setCommandEnabled('save', false);
\r
131 sandbox.getModule('indicator').showMessage(gettext('Saving...'));
\r
133 savingEnded: function(status) {
\r
134 sandbox.getModule('mainBar').setCommandEnabled('save', true);
\r
135 sandbox.getModule('indicator').clearMessage();
\r
137 historyItemAdded: function(item) {
\r
138 sandbox.getModule('documentHistory').addHistory([item], {animate: true});
\r
142 eventHandlers.mainBar = {
\r
143 ready: function() {
\r
144 views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
\r
146 'cmd.save': function() {
\r
147 synchronizeTab(views.mainTabs.getCurrentSlug());
\r
148 sandbox.getModule('data').saveDocument();
\r
152 eventHandlers.indicator = {
\r
153 ready: function() {
\r
154 views.mainLayout.setView('messages', sandbox.getModule('indicator').getView());
\r
160 eventHandlers.documentCanvas = {
\r
161 ready: function() {
\r
162 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
\r
163 views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());
\r
165 documentSet: function() {
\r
166 dirty.documentCanvas = false;
\r
169 nodeSelected: function(wlxmlNode) {
\r
170 commands.selectNode(wlxmlNode);
\r
173 contentChanged: function() {
\r
174 dirty.documentCanvas = true;
\r
177 nodeHovered: function(wlxmlNode) {
\r
178 commands.highlightDocumentNode(wlxmlNode);
\r
181 nodeBlured: function(wlxmlNode) {
\r
182 commands.dimDocumentNode(wlxmlNode);
\r
186 eventHandlers.nodePane = {
\r
187 ready: function() {
\r
188 views.currentNodePaneLayout.appendView(sandbox.getModule('nodePane').getView());
\r
191 nodeChanged: function(attr, value) {
\r
192 sandbox.getModule('documentCanvas').modifyCurrentNode(attr, value);
\r
196 eventHandlers.metadataEditor = {
\r
197 ready: function() {
\r
198 sandbox.getModule('metadataEditor').setDocument(sandbox.getModule('data').getDocument());
\r
199 views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
\r
201 metadataChanged: function(metadata) {
\r
202 dirty.metadataEditor = true;
\r
204 metadataSet: function() {
\r
205 dirty.metadataEditor = false;
\r
209 eventHandlers.nodeFamilyTree = {
\r
210 ready: function() {
\r
211 views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());
\r
213 nodeEntered: function(wlxmlNode) {
\r
214 commands.highlightDocumentNode(wlxmlNode, 'nodeFamilyTree');
\r
216 nodeLeft: function(wlxmlNode) {
\r
217 commands.dimDocumentNode(wlxmlNode, 'nodeFamilyTree');
\r
219 nodeSelected: function(wlxmlNode) {
\r
220 commands.selectNode(wlxmlNode);
\r
224 eventHandlers.documentToolbar = {
\r
225 ready: function() {
\r
226 views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());
\r
228 toggleGrid: function(toggle) {
\r
229 sandbox.getModule('documentCanvas').toggleGrid(toggle);
\r
231 newNodeRequested: function(wlxmlTag, wlxmlClass) {
\r
232 if(window.getSelection().isCollapsed) {
\r
233 sandbox.getModule('documentCanvas').insertNewNode(wlxmlTag, wlxmlClass);
\r
235 sandbox.getModule('documentCanvas').wrapSelectionWithNewNode(wlxmlTag, wlxmlClass);
\r
240 eventHandlers.nodeBreadCrumbs = {
\r
241 ready: function() {
\r
242 views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());
\r
244 nodeHighlighted: function(wlxmlNode) {
\r
245 commands.highlightDocumentNode(wlxmlNode, 'nodeBreadCrumbs');
\r
247 nodeDimmed: function(wlxmlNode) {
\r
248 commands.dimDocumentNode(wlxmlNode, 'nodeBreadCrumbs');
\r
250 nodeSelected: function(wlxmlNode) {
\r
251 commands.selectNode(wlxmlNode);
\r
255 eventHandlers.documentHistory = {
\r
256 ready: function() {
\r
257 sandbox.getModule('documentHistory').addHistory(sandbox.getModule('data').getHistory());
\r
258 addMainTab('Historia', 'history', sandbox.getModule('documentHistory').getView());
\r
265 start: function() {
\r
266 sandbox.getModule('data').start();
\r
268 handleEvent: function(moduleName, eventName, args) {
\r
270 wysiwigHandler.handleEvent(moduleName, eventName, args);
\r
271 else if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
\r
272 eventHandlers[moduleName][eventName].apply(eventHandlers, args);
\r