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
17 sourceEditor: false,
\r
18 documentCanvas: false,
\r
19 metadataEditor: false,
\r
23 highlightDocumentNode: function(wlxmlNode, origin) {
\r
24 ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {
\r
25 if(!origin || moduleName != origin)
\r
26 sandbox.getModule(moduleName).highlightNode(wlxmlNode)
\r
29 dimDocumentNode: function(wlxmlNode, origin) {
\r
30 ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {
\r
31 if(!origin || moduleName != origin)
\r
32 sandbox.getModule(moduleName).dimNode(wlxmlNode)
\r
35 selectNode: function(wlxmlNode, origin) {
\r
36 sandbox.getModule('documentCanvas').selectNode(wlxmlNode);
\r
37 sandbox.getModule('nodePane').setNode(wlxmlNode);
\r
38 sandbox.getModule('nodeFamilyTree').setNode(wlxmlNode);
\r
39 sandbox.getModule('nodeBreadCrumbs').setNode(wlxmlNode);
\r
46 mainLayout: new layout.Layout(mainLayoutTemplate),
\r
47 mainTabs: (new tabs.View()).render(),
\r
48 visualEditing: new layout.Layout(visualEditingLayoutTemplate),
\r
49 visualEditingSidebar: (new tabs.View({stacked: true})).render(),
\r
50 currentNodePaneLayout: new vbox.VBox()
\r
53 views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView());
\r
54 addMainTab('Edytor', 'editor', views.visualEditing.getAsView());
\r
56 sandbox.getDOM().append(views.mainLayout.getAsView());
\r
58 views.visualEditingSidebar.addTab({icon: 'pencil'}, 'edit', views.currentNodePaneLayout.getAsView());
\r
60 views.mainTabs.on('tabSelected', function(event) {
\r
61 if(event.prevSlug) {
\r
62 if(event.prevSlug === 'sourceEditor' && dirty.sourceEditor) {
\r
63 sandbox.getModule('data').commitDocument(sandbox.getModule('sourceEditor').getDocument(), 'source_edit');
\r
65 if(event.prevSlug === 'editor' && (dirty.documentCanvas || dirty.metadataEditor)) {
\r
66 var doc = dirty.documentCanvas ? sandbox.getModule('documentCanvas').getDocument() : sandbox.getModule('data').getDocument();
\r
67 if(dirty.metadataEditor) {
\r
68 doc = sandbox.getModule('metadataEditor').attachMetadata(doc);
\r
70 sandbox.getModule('data').commitDocument(doc, 'edit');
\r
76 /* Events handling */
\r
78 var eventHandlers = {};
\r
80 eventHandlers.sourceEditor = {
\r
82 addMainTab(gettext('Source'), 'sourceEditor', sandbox.getModule('sourceEditor').getView());
\r
83 sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());
\r
85 xmlChanged: function() {
\r
86 dirty.sourceEditor = true;
\r
88 documentSet: function() {
\r
89 dirty.sourceEditor = false;
\r
93 eventHandlers.data = {
\r
95 views.mainLayout.setView('mainView', views.mainTabs.getAsView());
\r
97 _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator'], function(moduleName) {
\r
98 sandbox.getModule(moduleName).start();
\r
101 documentChanged: function(document, reason) {
\r
103 if(reason === 'source_edit')
\r
104 modules = ['documentCanvas', 'metadataEditor'];
\r
105 else if (reason === 'edit')
\r
106 modules = ['sourceEditor'];
\r
108 modules.forEach(function(moduleName) {
\r
109 sandbox.getModule(moduleName).setDocument(document);
\r
112 savingStarted: function() {
\r
113 sandbox.getModule('mainBar').setCommandEnabled('save', false);
\r
114 sandbox.getModule('indicator').showMessage(gettext('Saving...'));
\r
116 savingEnded: function(status) {
\r
117 sandbox.getModule('mainBar').setCommandEnabled('save', true);
\r
118 sandbox.getModule('indicator').clearMessage();
\r
122 eventHandlers.mainBar = {
\r
123 ready: function() {
\r
124 views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
\r
126 'cmd.save': function() {
\r
127 sandbox.getModule('data').fakeSave();
\r
131 eventHandlers.indicator = {
\r
132 ready: function() {
\r
133 views.mainLayout.setView('messages', sandbox.getModule('indicator').getView());
\r
139 eventHandlers.documentCanvas = {
\r
140 ready: function() {
\r
141 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
\r
142 views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());
\r
144 documentSet: function() {
\r
145 dirty.documentCanvas = false;
\r
148 nodeSelected: function(wlxmlNode) {
\r
149 commands.selectNode(wlxmlNode);
\r
152 contentChanged: function() {
\r
153 dirty.documentCanvas = true;
\r
156 nodeHovered: function(wlxmlNode) {
\r
157 commands.highlightDocumentNode(wlxmlNode);
\r
160 nodeBlured: function(wlxmlNode) {
\r
161 commands.dimDocumentNode(wlxmlNode);
\r
165 eventHandlers.nodePane = {
\r
166 ready: function() {
\r
167 views.currentNodePaneLayout.appendView(sandbox.getModule('nodePane').getView());
\r
170 nodeChanged: function(attr, value) {
\r
171 sandbox.getModule('documentCanvas').modifyCurrentNode(attr, value);
\r
175 eventHandlers.metadataEditor = {
\r
176 ready: function() {
\r
177 sandbox.getModule('metadataEditor').setDocument(sandbox.getModule('data').getDocument());
\r
178 views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
\r
180 metadataChanged: function(metadata) {
\r
181 dirty.metadataEditor = true;
\r
183 metadataSet: function() {
\r
184 dirty.metadataEditor = false;
\r
188 eventHandlers.nodeFamilyTree = {
\r
189 ready: function() {
\r
190 views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());
\r
192 nodeEntered: function(wlxmlNode) {
\r
193 commands.highlightDocumentNode(wlxmlNode, 'nodeFamilyTree');
\r
195 nodeLeft: function(wlxmlNode) {
\r
196 commands.dimDocumentNode(wlxmlNode, 'nodeFamilyTree');
\r
198 nodeSelected: function(wlxmlNode) {
\r
199 commands.selectNode(wlxmlNode);
\r
203 eventHandlers.documentToolbar = {
\r
204 ready: function() {
\r
205 views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());
\r
207 toggleGrid: function(toggle) {
\r
208 sandbox.getModule('documentCanvas').toggleGrid(toggle);
\r
210 newNodeRequested: function(wlxmlTag, wlxmlClass) {
\r
211 if(window.getSelection().isCollapsed) {
\r
212 sandbox.getModule('documentCanvas').insertNewNode(wlxmlTag, wlxmlClass);
\r
214 sandbox.getModule('documentCanvas').wrapSelectionWithNewNode(wlxmlTag, wlxmlClass);
\r
219 eventHandlers.nodeBreadCrumbs = {
\r
220 ready: function() {
\r
221 views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());
\r
223 nodeHighlighted: function(wlxmlNode) {
\r
224 commands.highlightDocumentNode(wlxmlNode, 'nodeBreadCrumbs');
\r
226 nodeDimmed: function(wlxmlNode) {
\r
227 commands.dimDocumentNode(wlxmlNode, 'nodeBreadCrumbs');
\r
229 nodeSelected: function(wlxmlNode) {
\r
230 commands.selectNode(wlxmlNode);
\r
237 start: function() {
\r
238 sandbox.getModule('data').start();
\r
240 handleEvent: function(moduleName, eventName, args) {
\r
242 wysiwigHandler.handleEvent(moduleName, eventName, args);
\r
243 else if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
\r
244 eventHandlers[moduleName][eventName].apply(eventHandlers, args);
\r