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.mainBar = {
\r
69 views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
\r
71 'cmd.save': function() {
\r
72 sandbox.getModule('data').fakeSave();
\r
76 eventHandlers.indicator = {
\r
78 views.mainLayout.setView('messages', sandbox.getModule('indicator').getView());
\r
84 eventHandlers.documentCanvas = {
\r
86 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
\r
87 views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());
\r
90 nodeSelected: function(node) {
\r
91 sandbox.getModule('nodePane').setNode(node);
\r
92 sandbox.getModule('nodeFamilyTree').setNode(node);
\r
93 sandbox.getModule('nodeBreadCrumbs').setNode(node);
\r
96 contentChanged: function() {
\r
100 nodeHovered: function(node) {
\r
101 sandbox.getModule('documentCanvas').highlightNode(node.attr('id'));
\r
102 sandbox.getModule('nodeFamilyTree').highlightNode(node.attr('id'));
\r
103 sandbox.getModule('nodeBreadCrumbs').highlightNode(node.attr('id'));
\r
107 nodeBlured: function(node) {
\r
108 sandbox.getModule('documentCanvas').dimNode(node.attr('id'));
\r
109 sandbox.getModule('nodeFamilyTree').dimNode(node.attr('id'));
\r
110 sandbox.getModule('nodeBreadCrumbs').dimNode(node.attr('id'));
\r
114 eventHandlers.nodePane = {
\r
115 ready: function() {
\r
116 views.currentNodePaneLayout.appendView(sandbox.getModule('nodePane').getView());
\r
119 nodeChanged: function(attr, value) {
\r
120 sandbox.getModule('documentCanvas').modifyCurrentNode(attr, value);
\r
124 eventHandlers.metadataEditor = {
\r
125 ready: function() {
\r
126 sandbox.getModule('metadataEditor').setMetadata(sandbox.getModule('data').getDocument());
\r
127 views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
\r
131 eventHandlers.nodeFamilyTree = {
\r
132 ready: function() {
\r
133 views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());
\r
135 nodeEntered: function(id) {
\r
136 sandbox.getModule('documentCanvas').highlightNode(id);
\r
138 nodeLeft: function(id) {
\r
139 sandbox.getModule('documentCanvas').dimNode(id);
\r
141 nodeSelected: function(id) {
\r
142 sandbox.getModule('documentCanvas').selectNode(id);
\r
146 eventHandlers.documentToolbar = {
\r
147 ready: function() {
\r
148 views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());
\r
150 toggleGrid: function(toggle) {
\r
151 sandbox.getModule('documentCanvas').toggleGrid(toggle);
\r
153 newNodeRequested: function(wlxmlTag, wlxmlClass) {
\r
154 if(window.getSelection().isCollapsed) {
\r
155 sandbox.getModule('documentCanvas').insertNewNode(wlxmlTag, wlxmlClass);
\r
157 sandbox.getModule('documentCanvas').wrapSelectionWithNewNode(wlxmlTag, wlxmlClass);
\r
162 eventHandlers.nodeBreadCrumbs = {
\r
163 ready: function() {
\r
164 views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());
\r
166 nodeHighlighted: function(id) {
\r
167 sandbox.getModule('documentCanvas').highlightNode(id);
\r
169 nodeDimmed: function(id) {
\r
170 sandbox.getModule('documentCanvas').dimNode(id);
\r
172 nodeSelected: function(id) {
\r
173 sandbox.getModule('documentCanvas').selectNode(id);
\r
180 start: function() {
\r
181 sandbox.getModule('data').start();
\r
183 handleEvent: function(moduleName, eventName, args) {
\r
185 wysiwigHandler.handleEvent(moduleName, eventName, args);
\r
186 else if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
\r
187 eventHandlers[moduleName][eventName].apply(eventHandlers, args);
\r