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 mainLayout: new layout.Layout(mainLayoutTemplate),
\r
18 mainTabs: (new tabs.View()).render(),
\r
19 visualEditing: new layout.Layout(visualEditingLayoutTemplate),
\r
20 visualEditingSidebar: (new tabs.View({stacked: true})).render(),
\r
21 currentNodePaneLayout: new vbox.VBox()
\r
24 views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView());
\r
25 addMainTab('rng2 test', 'rng2test', views.visualEditing.getAsView());
\r
27 sandbox.getDOM().append(views.mainLayout.getAsView());
\r
29 views.visualEditingSidebar.addTab({icon: 'pencil'}, 'edit', views.currentNodePaneLayout.getAsView());
\r
34 /* Events handling */
\r
36 var eventHandlers = {};
\r
38 eventHandlers.sourceEditor = {
\r
40 addMainTab(gettext('Source'), 'source', sandbox.getModule('sourceEditor').getView());
\r
41 sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());
\r
45 eventHandlers.visualEditor = {
\r
47 sandbox.getModule('visualEditor').setDocument(sandbox.getModule('data').getDocument());
\r
48 addMainTab(gettext('Visual'), 'visual', sandbox.getModule('visualEditor').getView());
\r
53 eventHandlers.data = {
\r
55 views.mainLayout.setView('mainView', views.mainTabs.getAsView());
\r
57 _.each(['visualEditor', 'sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator'], function(moduleName) {
\r
58 sandbox.getModule(moduleName).start();
\r
61 documentChanged: function(document, reason) {
\r
62 var slug = (reason === 'visual_edit' ? 'source' : 'visual');
\r
63 sandbox.getModule(slug+'Editor').setDocument(document);
\r
65 savingStarted: function() {
\r
66 sandbox.getModule('mainBar').setCommandEnabled('save', false);
\r
67 sandbox.getModule('indicator').showMessage(gettext('Saving...'));
\r
69 savingEnded: function(status) {
\r
70 sandbox.getModule('mainBar').setCommandEnabled('save', true);
\r
71 sandbox.getModule('indicator').clearMessage();
\r
75 eventHandlers.rng2 = {
\r
77 addMainTab('rng2 test', 'rng2test', sandbox.getModule('rng2').getView());
\r
82 eventHandlers.mainBar = {
\r
84 views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
\r
86 'cmd.save': function() {
\r
87 sandbox.getModule('data').fakeSave();
\r
91 eventHandlers.indicator = {
\r
93 views.mainLayout.setView('messages', sandbox.getModule('indicator').getView());
\r
99 eventHandlers.documentCanvas = {
\r
100 ready: function() {
\r
101 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
\r
102 views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());
\r
105 nodeSelected: function(node) {
\r
106 sandbox.getModule('nodePane').setNode(node);
\r
107 sandbox.getModule('nodeFamilyTree').setNode(node);
\r
108 sandbox.getModule('nodeBreadCrumbs').setNode(node);
\r
111 contentChanged: function() {
\r
115 nodeHovered: function(node) {
\r
116 sandbox.getModule('documentCanvas').highlightNode(node.attr('id'));
\r
117 sandbox.getModule('nodeFamilyTree').highlightNode(node.attr('id'));
\r
118 sandbox.getModule('nodeBreadCrumbs').highlightNode(node.attr('id'));
\r
122 nodeBlured: function(node) {
\r
123 sandbox.getModule('documentCanvas').dimNode(node.attr('id'));
\r
124 sandbox.getModule('nodeFamilyTree').dimNode(node.attr('id'));
\r
125 sandbox.getModule('nodeBreadCrumbs').dimNode(node.attr('id'));
\r
129 eventHandlers.nodePane = {
\r
130 ready: function() {
\r
131 views.currentNodePaneLayout.appendView(sandbox.getModule('nodePane').getView());
\r
134 nodeChanged: function(attr, value) {
\r
135 sandbox.getModule('documentCanvas').modifyCurrentNode(attr, value);
\r
139 eventHandlers.metadataEditor = {
\r
140 ready: function() {
\r
141 sandbox.getModule('metadataEditor').setMetadata(sandbox.getModule('data').getDocument());
\r
142 views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
\r
146 eventHandlers.nodeFamilyTree = {
\r
147 ready: function() {
\r
148 views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());
\r
150 nodeEntered: function(id) {
\r
151 sandbox.getModule('documentCanvas').highlightNode(id);
\r
153 nodeLeft: function(id) {
\r
154 sandbox.getModule('documentCanvas').dimNode(id);
\r
156 nodeSelected: function(id) {
\r
157 sandbox.getModule('documentCanvas').selectNode(id);
\r
161 eventHandlers.documentToolbar = {
\r
162 ready: function() {
\r
163 views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());
\r
165 toggleGrid: function(toggle) {
\r
166 sandbox.getModule('documentCanvas').toggleGrid(toggle);
\r
168 newNodeRequested: function(wlxmlTag, wlxmlClass) {
\r
169 if(window.getSelection().isCollapsed) {
\r
170 sandbox.getModule('documentCanvas').insertNewNode(wlxmlTag, wlxmlClass);
\r
172 sandbox.getModule('documentCanvas').wrapSelectionWithNewNode(wlxmlTag, wlxmlClass);
\r
177 eventHandlers.nodeBreadCrumbs = {
\r
178 ready: function() {
\r
179 views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());
\r
181 nodeHighlighted: function(id) {
\r
182 sandbox.getModule('documentCanvas').highlightNode(id);
\r
184 nodeDimmed: function(id) {
\r
185 sandbox.getModule('documentCanvas').dimNode(id);
\r
187 nodeSelected: function(id) {
\r
188 sandbox.getModule('documentCanvas').selectNode(id);
\r
195 start: function() {
\r
196 sandbox.getModule('data').start();
\r
198 handleEvent: function(moduleName, eventName, args) {
\r
200 wysiwigHandler.handleEvent(moduleName, eventName, args);
\r
201 else if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
\r
202 eventHandlers[moduleName][eventName].apply(eventHandlers, args);
\r