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
33 if(slug === 'sourceEditor') {
\r
34 sandbox.getModule('data').commitDocument(sandbox.getModule('sourceEditor').getDocument(), 'source_edit');
\r
36 if(slug === 'editor') {
\r
37 var doc = dirty.documentCanvas ? sandbox.getModule('documentCanvas').getDocument() : sandbox.getModule('data').getDocument();
\r
38 if(dirty.metadataEditor) {
\r
39 doc = sandbox.getModule('metadataEditor').attachMetadata(doc);
\r
41 sandbox.getModule('data').commitDocument(doc, 'edit');
\r
47 highlightDocumentNode: function(wlxmlNode, origin) {
\r
48 ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {
\r
49 if(!origin || moduleName != origin)
\r
50 sandbox.getModule(moduleName).highlightNode(wlxmlNode)
\r
53 dimDocumentNode: function(wlxmlNode, origin) {
\r
54 ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {
\r
55 if(!origin || moduleName != origin)
\r
56 sandbox.getModule(moduleName).dimNode(wlxmlNode)
\r
59 selectNode: function(wlxmlNode, origin) {
\r
60 sandbox.getModule('documentCanvas').selectNode(wlxmlNode);
\r
61 sandbox.getModule('nodePane').setNode(wlxmlNode);
\r
62 sandbox.getModule('nodeFamilyTree').setNode(wlxmlNode);
\r
63 sandbox.getModule('nodeBreadCrumbs').setNode(wlxmlNode);
\r
70 mainLayout: new layout.Layout(mainLayoutTemplate),
\r
71 mainTabs: (new tabs.View()).render(),
\r
72 visualEditing: new layout.Layout(visualEditingLayoutTemplate),
\r
73 visualEditingSidebar: (new tabs.View({stacked: true})).render(),
\r
74 currentNodePaneLayout: new vbox.VBox()
\r
77 views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView());
\r
78 addMainTab('Edytor', 'editor', views.visualEditing.getAsView());
\r
80 sandbox.getDOM().append(views.mainLayout.getAsView());
\r
82 views.visualEditingSidebar.addTab({icon: 'pencil'}, 'edit', views.currentNodePaneLayout.getAsView());
\r
84 views.mainTabs.on('tabSelected', function(event) {
\r
85 if(event.prevSlug) {
\r
86 synchronizeTab(event.prevSlug);
\r
90 /* Events handling */
\r
92 var eventHandlers = {};
\r
94 eventHandlers.sourceEditor = {
\r
96 addMainTab(gettext('Source'), 'sourceEditor', sandbox.getModule('sourceEditor').getView());
\r
97 sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());
\r
99 xmlChanged: function() {
\r
100 dirty.sourceEditor = true;
\r
102 documentSet: function() {
\r
103 dirty.sourceEditor = false;
\r
107 eventHandlers.data = {
\r
108 ready: function() {
\r
109 views.mainLayout.setView('mainView', views.mainTabs.getAsView());
\r
111 _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory'], function(moduleName) {
\r
112 sandbox.getModule(moduleName).start();
\r
115 documentChanged: function(document, reason) {
\r
117 if(reason === 'source_edit')
\r
118 modules = ['documentCanvas', 'metadataEditor'];
\r
119 else if (reason === 'edit')
\r
120 modules = ['sourceEditor'];
\r
122 modules.forEach(function(moduleName) {
\r
123 sandbox.getModule(moduleName).setDocument(document);
\r
126 savingStarted: function() {
\r
127 sandbox.getModule('mainBar').setCommandEnabled('save', false);
\r
128 sandbox.getModule('indicator').showMessage(gettext('Saving...'));
\r
130 savingEnded: function(status) {
\r
131 sandbox.getModule('mainBar').setCommandEnabled('save', true);
\r
132 sandbox.getModule('indicator').clearMessage();
\r
134 historyItemAdded: function(item) {
\r
135 sandbox.getModule('documentHistory').addHistory([item]);
\r
139 eventHandlers.mainBar = {
\r
140 ready: function() {
\r
141 views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
\r
143 'cmd.save': function() {
\r
144 synchronizeTab(views.mainTabs.getCurrentSlug());
\r
145 sandbox.getModule('data').saveDocument();
\r
149 eventHandlers.indicator = {
\r
150 ready: function() {
\r
151 views.mainLayout.setView('messages', sandbox.getModule('indicator').getView());
\r
157 eventHandlers.documentCanvas = {
\r
158 ready: function() {
\r
159 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
\r
160 views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());
\r
162 documentSet: function() {
\r
163 dirty.documentCanvas = false;
\r
166 nodeSelected: function(wlxmlNode) {
\r
167 commands.selectNode(wlxmlNode);
\r
170 contentChanged: function() {
\r
171 dirty.documentCanvas = true;
\r
174 nodeHovered: function(wlxmlNode) {
\r
175 commands.highlightDocumentNode(wlxmlNode);
\r
178 nodeBlured: function(wlxmlNode) {
\r
179 commands.dimDocumentNode(wlxmlNode);
\r
183 eventHandlers.nodePane = {
\r
184 ready: function() {
\r
185 views.currentNodePaneLayout.appendView(sandbox.getModule('nodePane').getView());
\r
188 nodeChanged: function(attr, value) {
\r
189 sandbox.getModule('documentCanvas').modifyCurrentNode(attr, value);
\r
193 eventHandlers.metadataEditor = {
\r
194 ready: function() {
\r
195 sandbox.getModule('metadataEditor').setDocument(sandbox.getModule('data').getDocument());
\r
196 views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
\r
198 metadataChanged: function(metadata) {
\r
199 dirty.metadataEditor = true;
\r
201 metadataSet: function() {
\r
202 dirty.metadataEditor = false;
\r
206 eventHandlers.nodeFamilyTree = {
\r
207 ready: function() {
\r
208 views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());
\r
210 nodeEntered: function(wlxmlNode) {
\r
211 commands.highlightDocumentNode(wlxmlNode, 'nodeFamilyTree');
\r
213 nodeLeft: function(wlxmlNode) {
\r
214 commands.dimDocumentNode(wlxmlNode, 'nodeFamilyTree');
\r
216 nodeSelected: function(wlxmlNode) {
\r
217 commands.selectNode(wlxmlNode);
\r
221 eventHandlers.documentToolbar = {
\r
222 ready: function() {
\r
223 views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());
\r
225 toggleGrid: function(toggle) {
\r
226 sandbox.getModule('documentCanvas').toggleGrid(toggle);
\r
228 newNodeRequested: function(wlxmlTag, wlxmlClass) {
\r
229 if(window.getSelection().isCollapsed) {
\r
230 sandbox.getModule('documentCanvas').insertNewNode(wlxmlTag, wlxmlClass);
\r
232 sandbox.getModule('documentCanvas').wrapSelectionWithNewNode(wlxmlTag, wlxmlClass);
\r
237 eventHandlers.nodeBreadCrumbs = {
\r
238 ready: function() {
\r
239 views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());
\r
241 nodeHighlighted: function(wlxmlNode) {
\r
242 commands.highlightDocumentNode(wlxmlNode, 'nodeBreadCrumbs');
\r
244 nodeDimmed: function(wlxmlNode) {
\r
245 commands.dimDocumentNode(wlxmlNode, 'nodeBreadCrumbs');
\r
247 nodeSelected: function(wlxmlNode) {
\r
248 commands.selectNode(wlxmlNode);
\r
252 eventHandlers.documentHistory = {
\r
253 ready: function() {
\r
254 sandbox.getModule('documentHistory').addHistory(sandbox.getModule('data').getHistory());
\r
255 addMainTab('Historia', 'history', sandbox.getModule('documentHistory').getView());
\r
262 start: function() {
\r
263 sandbox.getModule('data').start();
\r
265 handleEvent: function(moduleName, eventName, args) {
\r
267 wysiwigHandler.handleEvent(moduleName, eventName, args);
\r
268 else if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
\r
269 eventHandlers[moduleName][eventName].apply(eventHandlers, args);
\r