5 'libs/text!./mainLayout.html',
\r
6 'libs/text!./editingLayout.html',
\r
7 ], function(layout, vbox, tabs, mainLayoutTemplate, editingLayoutTemplate) {
\r
9 return function(sandbox) {
\r
12 var mainTabs = (new tabs.View()).render();
\r
13 var mainLayout = new layout.Layout(mainLayoutTemplate);
\r
14 var editingLayout = new layout.Layout(editingLayoutTemplate);
\r
16 sandbox.getDOM().append(mainLayout.getAsView());
\r
18 function addTab(title, slug, view) {
\r
19 mainTabs.addTab(title, slug, view);
\r
22 /* Events handling */
\r
24 var eventHandlers = {};
\r
26 eventHandlers.sourceEditor = {
\r
28 addTab(gettext('Source'), 'source', sandbox.getModule('sourceEditor').getView());
\r
29 sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());
\r
33 eventHandlers.visualEditor = {
\r
35 sandbox.getModule('visualEditor').setDocument(sandbox.getModule('data').getDocument());
\r
36 addTab(gettext('Visual'), 'visual', sandbox.getModule('visualEditor').getView());
\r
41 eventHandlers.data = {
\r
43 mainLayout.setView('mainView', mainTabs.getAsView());
\r
45 _.each(['visualEditor', 'sourceEditor', 'documentCanvas', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'mainBar', 'indicator'], function(moduleName) {
\r
46 sandbox.getModule(moduleName).start();
\r
49 documentChanged: function(document, reason) {
\r
50 var slug = (reason === 'visual_edit' ? 'source' : 'visual');
\r
51 sandbox.getModule(slug+'Editor').setDocument(document);
\r
53 savingStarted: function() {
\r
54 sandbox.getModule('mainBar').setCommandEnabled('save', false);
\r
55 sandbox.getModule('indicator').showMessage(gettext('Saving...'));
\r
57 savingEnded: function(status) {
\r
58 sandbox.getModule('mainBar').setCommandEnabled('save', true);
\r
59 sandbox.getModule('indicator').clearMessage();
\r
63 eventHandlers.rng2 = {
\r
65 addTab('rng2 test', 'rng2test', sandbox.getModule('rng2').getView());
\r
70 eventHandlers.mainBar = {
\r
72 mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
\r
74 'cmd.save': function() {
\r
75 sandbox.getModule('data').fakeSave();
\r
79 eventHandlers.indicator = {
\r
81 mainLayout.setView('messages', sandbox.getModule('indicator').getView());
\r
86 var sidebar = (new tabs.View({stacked: true})).render();
\r
87 var box = new vbox.VBox();
\r
88 editingLayout.setView('rightColumn', sidebar.getAsView());
\r
89 addTab('rng2 test', 'rng2test', editingLayout.getAsView());
\r
91 eventHandlers.documentCanvas = {
\r
93 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
\r
94 editingLayout.setView('leftColumn', sandbox.getModule('documentCanvas').getView());
\r
97 nodeSelected: function(node) {
\r
98 sandbox.getModule('nodePane').setNode(node);
\r
99 sandbox.getModule('nodeFamilyTree').setNode(node);
\r
102 contentChanged: function() {
\r
106 nodeHovered: function(node) {
\r
110 nodeBlured: function(node) {
\r
115 eventHandlers.nodePane = {
\r
116 ready: function() {
\r
117 //sidebar.addTab({icon: 'pencil'}, 'nodePane', sandbox.getModule('nodePane').getView());
\r
118 box.appendView(sandbox.getModule('nodePane').getView());
\r
119 sidebar.addTab({icon: 'pencil'}, 'edit', box.getAsView());
\r
122 nodeChanged: function(attr, value) {
\r
123 sandbox.getModule('documentCanvas').modifyCurrentNode(attr, value);
\r
127 eventHandlers.metadataEditor = {
\r
128 ready: function() {
\r
129 sandbox.getModule('metadataEditor').setMetadata(sandbox.getModule('data').getDocument());
\r
130 sidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
\r
134 eventHandlers.nodeFamilyTree = {
\r
135 ready: function() {
\r
136 //sidebar.addTab({icon: 'home'}, 'family', sandbox.getModule('nodeFamilyTree').getView());
\r
137 box.appendView(sandbox.getModule('nodeFamilyTree').getView());
\r
139 nodeEntered: function(id) {
\r
140 sandbox.getModule('documentCanvas').highlightNode(id);
\r
142 nodeLeft: function(id) {
\r
143 sandbox.getModule('documentCanvas').dimNode(id);
\r
145 nodeSelected: function(id) {
\r
146 sandbox.getModule('documentCanvas').selectNode(id);
\r
153 start: function() {
\r
154 sandbox.getModule('data').start();
\r
156 handleEvent: function(moduleName, eventName, args) {
\r
158 wysiwigHandler.handleEvent(moduleName, eventName, args);
\r
159 else if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
\r
160 eventHandlers[moduleName][eventName].apply(eventHandlers, args);
\r