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 highlightDocumentNode: function(wlxmlNode, origin) {
\r
18 ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {
\r
19 if(!origin || moduleName != origin)
\r
20 sandbox.getModule(moduleName).highlightNode(wlxmlNode)
\r
23 dimDocumentNode: function(wlxmlNode, origin) {
\r
24 ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {
\r
25 if(!origin || moduleName != origin)
\r
26 sandbox.getModule(moduleName).dimNode(wlxmlNode)
\r
33 mainLayout: new layout.Layout(mainLayoutTemplate),
\r
34 mainTabs: (new tabs.View()).render(),
\r
35 visualEditing: new layout.Layout(visualEditingLayoutTemplate),
\r
36 visualEditingSidebar: (new tabs.View({stacked: true})).render(),
\r
37 currentNodePaneLayout: new vbox.VBox()
\r
40 views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView());
\r
41 addMainTab('Edytor', 'editor', views.visualEditing.getAsView());
\r
43 sandbox.getDOM().append(views.mainLayout.getAsView());
\r
45 views.visualEditingSidebar.addTab({icon: 'pencil'}, 'edit', views.currentNodePaneLayout.getAsView());
\r
48 /* Events handling */
\r
50 var eventHandlers = {};
\r
52 eventHandlers.sourceEditor = {
\r
54 addMainTab(gettext('Source'), 'source', sandbox.getModule('sourceEditor').getView());
\r
55 sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());
\r
59 eventHandlers.data = {
\r
61 views.mainLayout.setView('mainView', views.mainTabs.getAsView());
\r
63 _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator'], function(moduleName) {
\r
64 sandbox.getModule(moduleName).start();
\r
67 documentChanged: function(document, reason) {
\r
68 var slug = (reason === 'visual_edit' ? 'source' : 'visual');
\r
69 sandbox.getModule(slug+'Editor').setDocument(document);
\r
71 savingStarted: function() {
\r
72 sandbox.getModule('mainBar').setCommandEnabled('save', false);
\r
73 sandbox.getModule('indicator').showMessage(gettext('Saving...'));
\r
75 savingEnded: function(status) {
\r
76 sandbox.getModule('mainBar').setCommandEnabled('save', true);
\r
77 sandbox.getModule('indicator').clearMessage();
\r
81 eventHandlers.mainBar = {
\r
83 views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
\r
85 'cmd.save': function() {
\r
86 sandbox.getModule('data').fakeSave();
\r
90 eventHandlers.indicator = {
\r
92 views.mainLayout.setView('messages', sandbox.getModule('indicator').getView());
\r
98 eventHandlers.documentCanvas = {
\r
100 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
\r
101 views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());
\r
104 nodeSelected: function(node) {
\r
105 sandbox.getModule('nodePane').setNode(node);
\r
106 sandbox.getModule('nodeFamilyTree').setNode(node);
\r
107 sandbox.getModule('nodeBreadCrumbs').setNode(node);
\r
110 contentChanged: function() {
\r
114 nodeHovered: function(wlxmlNode) {
\r
115 commands.highlightDocumentNode(wlxmlNode);
\r
118 nodeBlured: function(wlxmlNode) {
\r
119 commands.dimDocumentNode(wlxmlNode);
\r
123 eventHandlers.nodePane = {
\r
124 ready: function() {
\r
125 views.currentNodePaneLayout.appendView(sandbox.getModule('nodePane').getView());
\r
128 nodeChanged: function(attr, value) {
\r
129 sandbox.getModule('documentCanvas').modifyCurrentNode(attr, value);
\r
133 eventHandlers.metadataEditor = {
\r
134 ready: function() {
\r
135 sandbox.getModule('metadataEditor').setMetadata(sandbox.getModule('data').getDocument());
\r
136 views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
\r
140 eventHandlers.nodeFamilyTree = {
\r
141 ready: function() {
\r
142 views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());
\r
144 nodeEntered: function(wlxmlNode) {
\r
145 commands.highlightDocumentNode(wlxmlNode, 'nodeFamilyTree');
\r
147 nodeLeft: function(wlxmlNode) {
\r
148 commands.dimDocumentNode(wlxmlNode, 'nodeFamilyTree');
\r
150 nodeSelected: function(wlxmlNode) {
\r
151 sandbox.getModule('documentCanvas').selectNode(wlxmlNode);
\r
155 eventHandlers.documentToolbar = {
\r
156 ready: function() {
\r
157 views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());
\r
159 toggleGrid: function(toggle) {
\r
160 sandbox.getModule('documentCanvas').toggleGrid(toggle);
\r
162 newNodeRequested: function(wlxmlTag, wlxmlClass) {
\r
163 if(window.getSelection().isCollapsed) {
\r
164 sandbox.getModule('documentCanvas').insertNewNode(wlxmlTag, wlxmlClass);
\r
166 sandbox.getModule('documentCanvas').wrapSelectionWithNewNode(wlxmlTag, wlxmlClass);
\r
171 eventHandlers.nodeBreadCrumbs = {
\r
172 ready: function() {
\r
173 views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());
\r
175 nodeHighlighted: function(wlxmlNode) {
\r
176 commands.highlightDocumentNode(wlxmlNode, 'nodeBreadCrumbs');
\r
178 nodeDimmed: function(wlxmlNode) {
\r
179 commands.dimDocumentNode(wlxmlNode, 'nodeBreadCrumbs');
\r
181 nodeSelected: function(wlxmlNode) {
\r
182 sandbox.getModule('documentCanvas').selectNode(wlxmlNode);
\r
189 start: function() {
\r
190 sandbox.getModule('data').start();
\r
192 handleEvent: function(moduleName, eventName, args) {
\r
194 wysiwigHandler.handleEvent(moduleName, eventName, args);
\r
195 else if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
\r
196 eventHandlers[moduleName][eventName].apply(eventHandlers, args);
\r