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', '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
110 contentChanged: function() {
\r
114 nodeHovered: function(node) {
\r
115 sandbox.getModule('nodeFamilyTree').highlightNode(node.attr('id'));
\r
118 nodeBlured: function(node) {
\r
119 sandbox.getModule('nodeFamilyTree').dimNode(node.attr('id'));
\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(id) {
\r
145 sandbox.getModule('documentCanvas').highlightNode(id);
\r
147 nodeLeft: function(id) {
\r
148 sandbox.getModule('documentCanvas').dimNode(id);
\r
150 nodeSelected: function(id) {
\r
151 sandbox.getModule('documentCanvas').selectNode(id);
\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
174 start: function() {
\r
175 sandbox.getModule('data').start();
\r
177 handleEvent: function(moduleName, eventName, args) {
\r
179 wysiwigHandler.handleEvent(moduleName, eventName, args);
\r
180 else if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
\r
181 eventHandlers[moduleName][eventName].apply(eventHandlers, args);
\r