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'], 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
136 eventHandlers.mainBar = {
\r
137 ready: function() {
\r
138 views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
\r
140 'cmd.save': function() {
\r
141 synchronizeTab(views.mainTabs.getCurrentSlug());
\r
142 sandbox.getModule('data').saveDocument();
\r
146 eventHandlers.indicator = {
\r
147 ready: function() {
\r
148 views.mainLayout.setView('messages', sandbox.getModule('indicator').getView());
\r
154 eventHandlers.documentCanvas = {
\r
155 ready: function() {
\r
156 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
\r
157 views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());
\r
159 documentSet: function() {
\r
160 dirty.documentCanvas = false;
\r
163 nodeSelected: function(wlxmlNode) {
\r
164 commands.selectNode(wlxmlNode);
\r
167 contentChanged: function() {
\r
168 dirty.documentCanvas = true;
\r
171 nodeHovered: function(wlxmlNode) {
\r
172 commands.highlightDocumentNode(wlxmlNode);
\r
175 nodeBlured: function(wlxmlNode) {
\r
176 commands.dimDocumentNode(wlxmlNode);
\r
180 eventHandlers.nodePane = {
\r
181 ready: function() {
\r
182 views.currentNodePaneLayout.appendView(sandbox.getModule('nodePane').getView());
\r
185 nodeChanged: function(attr, value) {
\r
186 sandbox.getModule('documentCanvas').modifyCurrentNode(attr, value);
\r
190 eventHandlers.metadataEditor = {
\r
191 ready: function() {
\r
192 sandbox.getModule('metadataEditor').setDocument(sandbox.getModule('data').getDocument());
\r
193 views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
\r
195 metadataChanged: function(metadata) {
\r
196 dirty.metadataEditor = true;
\r
198 metadataSet: function() {
\r
199 dirty.metadataEditor = false;
\r
203 eventHandlers.nodeFamilyTree = {
\r
204 ready: function() {
\r
205 views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());
\r
207 nodeEntered: function(wlxmlNode) {
\r
208 commands.highlightDocumentNode(wlxmlNode, 'nodeFamilyTree');
\r
210 nodeLeft: function(wlxmlNode) {
\r
211 commands.dimDocumentNode(wlxmlNode, 'nodeFamilyTree');
\r
213 nodeSelected: function(wlxmlNode) {
\r
214 commands.selectNode(wlxmlNode);
\r
218 eventHandlers.documentToolbar = {
\r
219 ready: function() {
\r
220 views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());
\r
222 toggleGrid: function(toggle) {
\r
223 sandbox.getModule('documentCanvas').toggleGrid(toggle);
\r
225 newNodeRequested: function(wlxmlTag, wlxmlClass) {
\r
226 if(window.getSelection().isCollapsed) {
\r
227 sandbox.getModule('documentCanvas').insertNewNode(wlxmlTag, wlxmlClass);
\r
229 sandbox.getModule('documentCanvas').wrapSelectionWithNewNode(wlxmlTag, wlxmlClass);
\r
234 eventHandlers.nodeBreadCrumbs = {
\r
235 ready: function() {
\r
236 views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());
\r
238 nodeHighlighted: function(wlxmlNode) {
\r
239 commands.highlightDocumentNode(wlxmlNode, 'nodeBreadCrumbs');
\r
241 nodeDimmed: function(wlxmlNode) {
\r
242 commands.dimDocumentNode(wlxmlNode, 'nodeBreadCrumbs');
\r
244 nodeSelected: function(wlxmlNode) {
\r
245 commands.selectNode(wlxmlNode);
\r
252 start: function() {
\r
253 sandbox.getModule('data').start();
\r
255 handleEvent: function(moduleName, eventName, args) {
\r
257 wysiwigHandler.handleEvent(moduleName, eventName, args);
\r
258 else if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
\r
259 eventHandlers[moduleName][eventName].apply(eventHandlers, args);
\r