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 highlightDocumentNode: function(wlxmlNode, origin) {
\r
18 ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {
\r
19 if(!origin || moduleName != origin)
\r
20 sandbox.getModule(moduleName).highlightNode(wlxmlNode)
\r
23 dimDocumentNode: function(wlxmlNode, origin) {
\r
24 ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {
\r
25 if(!origin || moduleName != origin)
\r
26 sandbox.getModule(moduleName).dimNode(wlxmlNode)
\r
29 selectNode: function(wlxmlNode, origin) {
\r
30 sandbox.getModule('documentCanvas').selectNode(wlxmlNode);
\r
31 sandbox.getModule('nodePane').setNode(wlxmlNode);
\r
32 sandbox.getModule('nodeFamilyTree').setNode(wlxmlNode);
\r
33 sandbox.getModule('nodeBreadCrumbs').setNode(wlxmlNode);
\r
40 mainLayout: new layout.Layout(mainLayoutTemplate),
\r
41 mainTabs: (new tabs.View()).render(),
\r
42 visualEditing: new layout.Layout(visualEditingLayoutTemplate),
\r
43 visualEditingSidebar: (new tabs.View({stacked: true})).render(),
\r
44 currentNodePaneLayout: new vbox.VBox()
\r
47 views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView());
\r
48 addMainTab('Edytor', 'editor', views.visualEditing.getAsView());
\r
50 sandbox.getDOM().append(views.mainLayout.getAsView());
\r
52 views.visualEditingSidebar.addTab({icon: 'pencil'}, 'edit', views.currentNodePaneLayout.getAsView());
\r
55 /* Events handling */
\r
57 var eventHandlers = {};
\r
59 eventHandlers.sourceEditor = {
\r
61 addMainTab(gettext('Source'), 'source', sandbox.getModule('sourceEditor').getView());
\r
62 sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());
\r
66 eventHandlers.data = {
\r
68 views.mainLayout.setView('mainView', views.mainTabs.getAsView());
\r
70 _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator'], function(moduleName) {
\r
71 sandbox.getModule(moduleName).start();
\r
74 documentChanged: function(document, reason) {
\r
75 var slug = (reason === 'visual_edit' ? 'source' : 'visual');
\r
76 sandbox.getModule(slug+'Editor').setDocument(document);
\r
78 savingStarted: function() {
\r
79 sandbox.getModule('mainBar').setCommandEnabled('save', false);
\r
80 sandbox.getModule('indicator').showMessage(gettext('Saving...'));
\r
82 savingEnded: function(status) {
\r
83 sandbox.getModule('mainBar').setCommandEnabled('save', true);
\r
84 sandbox.getModule('indicator').clearMessage();
\r
88 eventHandlers.mainBar = {
\r
90 views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
\r
92 'cmd.save': function() {
\r
93 sandbox.getModule('data').fakeSave();
\r
97 eventHandlers.indicator = {
\r
99 views.mainLayout.setView('messages', sandbox.getModule('indicator').getView());
\r
105 eventHandlers.documentCanvas = {
\r
106 ready: function() {
\r
107 sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());
\r
108 views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());
\r
111 nodeSelected: function(wlxmlNode) {
\r
112 commands.selectNode(wlxmlNode);
\r
115 contentChanged: function() {
\r
119 nodeHovered: function(wlxmlNode) {
\r
120 commands.highlightDocumentNode(wlxmlNode);
\r
123 nodeBlured: function(wlxmlNode) {
\r
124 commands.dimDocumentNode(wlxmlNode);
\r
128 eventHandlers.nodePane = {
\r
129 ready: function() {
\r
130 views.currentNodePaneLayout.appendView(sandbox.getModule('nodePane').getView());
\r
133 nodeChanged: function(attr, value) {
\r
134 sandbox.getModule('documentCanvas').modifyCurrentNode(attr, value);
\r
138 eventHandlers.metadataEditor = {
\r
139 ready: function() {
\r
140 sandbox.getModule('metadataEditor').setMetadata(sandbox.getModule('data').getDocument());
\r
141 views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());
\r
145 eventHandlers.nodeFamilyTree = {
\r
146 ready: function() {
\r
147 views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());
\r
149 nodeEntered: function(wlxmlNode) {
\r
150 commands.highlightDocumentNode(wlxmlNode, 'nodeFamilyTree');
\r
152 nodeLeft: function(wlxmlNode) {
\r
153 commands.dimDocumentNode(wlxmlNode, 'nodeFamilyTree');
\r
155 nodeSelected: function(wlxmlNode) {
\r
156 commands.selectNode(wlxmlNode);
\r
160 eventHandlers.documentToolbar = {
\r
161 ready: function() {
\r
162 views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());
\r
164 toggleGrid: function(toggle) {
\r
165 sandbox.getModule('documentCanvas').toggleGrid(toggle);
\r
167 newNodeRequested: function(wlxmlTag, wlxmlClass) {
\r
168 if(window.getSelection().isCollapsed) {
\r
169 sandbox.getModule('documentCanvas').insertNewNode(wlxmlTag, wlxmlClass);
\r
171 sandbox.getModule('documentCanvas').wrapSelectionWithNewNode(wlxmlTag, wlxmlClass);
\r
176 eventHandlers.nodeBreadCrumbs = {
\r
177 ready: function() {
\r
178 views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());
\r
180 nodeHighlighted: function(wlxmlNode) {
\r
181 commands.highlightDocumentNode(wlxmlNode, 'nodeBreadCrumbs');
\r
183 nodeDimmed: function(wlxmlNode) {
\r
184 commands.dimDocumentNode(wlxmlNode, 'nodeBreadCrumbs');
\r
186 nodeSelected: function(wlxmlNode) {
\r
187 commands.selectNode(wlxmlNode);
\r
194 start: function() {
\r
195 sandbox.getModule('data').start();
\r
197 handleEvent: function(moduleName, eventName, args) {
\r
199 wysiwigHandler.handleEvent(moduleName, eventName, args);
\r
200 else if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
\r
201 eventHandlers[moduleName][eventName].apply(eventHandlers, args);
\r