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('Edytor', 'editor', 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.data = {
\r
47 views.mainLayout.setView('mainView', views.mainTabs.getAsView());
\r
49 _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator'], function(moduleName) {
\r
50 sandbox.getModule(moduleName).start();
\r
53 documentChanged: function(document, reason) {
\r
54 var slug = (reason === 'visual_edit' ? 'source' : 'visual');
\r
55 sandbox.getModule(slug+'Editor').setDocument(document);
\r
57 savingStarted: function() {
\r
58 sandbox.getModule('mainBar').setCommandEnabled('save', false);
\r
59 sandbox.getModule('indicator').showMessage(gettext('Saving...'));
\r
61 savingEnded: function(status) {
\r
62 sandbox.getModule('mainBar').setCommandEnabled('save', true);
\r
63 sandbox.getModule('indicator').clearMessage();
\r
67 eventHandlers.rng2 = {
\r
69 addMainTab('rng2 test', 'rng2test', sandbox.getModule('rng2').getView());
\r
74 eventHandlers.mainBar = {
\r
76 views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
\r
78 'cmd.save': function() {
\r
79 sandbox.getModule('data').fakeSave();
\r
83 eventHandlers.indicator = {
\r
85 views.mainLayout.setView('messages', sandbox.getModule('indicator').getView());
\r
91 eventHandlers.documentCanvas = {
\r
93 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
\r
94 views.visualEditing.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
100 sandbox.getModule('nodeBreadCrumbs').setNode(node);
\r
103 contentChanged: function() {
\r
107 nodeHovered: function(node) {
\r
108 sandbox.getModule('documentCanvas').highlightNode(node.attr('id'));
\r
109 sandbox.getModule('nodeFamilyTree').highlightNode(node.attr('id'));
\r
110 sandbox.getModule('nodeBreadCrumbs').highlightNode(node.attr('id'));
\r
114 nodeBlured: function(node) {
\r
115 sandbox.getModule('documentCanvas').dimNode(node.attr('id'));
\r
116 sandbox.getModule('nodeFamilyTree').dimNode(node.attr('id'));
\r
117 sandbox.getModule('nodeBreadCrumbs').dimNode(node.attr('id'));
\r
121 eventHandlers.nodePane = {
\r
122 ready: function() {
\r
123 views.currentNodePaneLayout.appendView(sandbox.getModule('nodePane').getView());
\r
126 nodeChanged: function(attr, value) {
\r
127 sandbox.getModule('documentCanvas').modifyCurrentNode(attr, value);
\r
131 eventHandlers.metadataEditor = {
\r
132 ready: function() {
\r
133 sandbox.getModule('metadataEditor').setMetadata(sandbox.getModule('data').getDocument());
\r
134 views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
\r
138 eventHandlers.nodeFamilyTree = {
\r
139 ready: function() {
\r
140 views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());
\r
142 nodeEntered: function(id) {
\r
143 sandbox.getModule('documentCanvas').highlightNode(id);
\r
145 nodeLeft: function(id) {
\r
146 sandbox.getModule('documentCanvas').dimNode(id);
\r
148 nodeSelected: function(id) {
\r
149 sandbox.getModule('documentCanvas').selectNode(id);
\r
153 eventHandlers.documentToolbar = {
\r
154 ready: function() {
\r
155 views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());
\r
157 toggleGrid: function(toggle) {
\r
158 sandbox.getModule('documentCanvas').toggleGrid(toggle);
\r
160 newNodeRequested: function(wlxmlTag, wlxmlClass) {
\r
161 if(window.getSelection().isCollapsed) {
\r
162 sandbox.getModule('documentCanvas').insertNewNode(wlxmlTag, wlxmlClass);
\r
164 sandbox.getModule('documentCanvas').wrapSelectionWithNewNode(wlxmlTag, wlxmlClass);
\r
169 eventHandlers.nodeBreadCrumbs = {
\r
170 ready: function() {
\r
171 views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());
\r
173 nodeHighlighted: function(id) {
\r
174 sandbox.getModule('documentCanvas').highlightNode(id);
\r
176 nodeDimmed: function(id) {
\r
177 sandbox.getModule('documentCanvas').dimNode(id);
\r
179 nodeSelected: function(id) {
\r
180 sandbox.getModule('documentCanvas').selectNode(id);
\r
187 start: function() {
\r
188 sandbox.getModule('data').start();
\r
190 handleEvent: function(moduleName, eventName, args) {
\r
192 wysiwigHandler.handleEvent(moduleName, eventName, args);
\r
193 else if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
\r
194 eventHandlers[moduleName][eventName].apply(eventHandlers, args);
\r