-define([\r
-'fnpjs/layout',\r
-'views/tabs/tabs',\r
-'libs/text!./rng/mainLayout.html'\r
-], function(layout, tabs, mainLayoutTemplate) {\r
-\r
-return function(sandbox) {\r
- 'use strict';\r
- \r
- var mainTabs = (new tabs.View()).render();\r
- var mainLayout = new layout.Layout(mainLayoutTemplate);\r
- sandbox.getDOM().append(mainLayout.getAsView());\r
- \r
- function addTab(title, slug, view) {\r
- mainTabs.addTab(title, slug, view);\r
- }\r
- \r
- /* Events handling */\r
- \r
- var eventHandlers = {};\r
- \r
- eventHandlers.sourceEditor = {\r
- ready: function() {\r
- addTab(gettext('Source'), 'source', sandbox.getModule('sourceEditor').getView());\r
- sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());\r
- }\r
- };\r
- \r
- eventHandlers.visualEditor = {\r
- ready: function() {\r
- sandbox.getModule('visualEditor').setDocument(sandbox.getModule('data').getDocument());\r
- addTab(gettext('Visual'), 'visual', sandbox.getModule('visualEditor').getView());\r
- \r
- }\r
- };\r
- \r
- eventHandlers.data = {\r
- ready: function() {\r
- mainLayout.setView('mainView', mainTabs.getAsView());\r
- \r
- _.each(['visualEditor', 'sourceEditor', 'rng2', 'mainBar', 'indicator'], function(moduleName) {\r
- sandbox.getModule(moduleName).start();\r
- });\r
- },\r
- documentChanged: function(document, reason) {\r
- var slug = (reason === 'visual_edit' ? 'source' : 'visual');\r
- sandbox.getModule(slug+'Editor').setDocument(document);\r
- },\r
- savingStarted: function() {\r
- sandbox.getModule('mainBar').setCommandEnabled('save', false);\r
- sandbox.getModule('indicator').showMessage(gettext('Saving...'));\r
- },\r
- savingEnded: function(status) {\r
- sandbox.getModule('mainBar').setCommandEnabled('save', true);\r
- sandbox.getModule('indicator').clearMessage();\r
- }\r
- }\r
- \r
- eventHandlers.rng2 = {\r
- ready: function() {\r
- addTab('rng2 test', 'rng2test', sandbox.getModule('rng2').getView());\r
- \r
- }\r
- }\r
- \r
- eventHandlers.mainBar = {\r
- ready: function() {\r
- mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());\r
- },\r
- 'cmd.save': function() {\r
- sandbox.getModule('data').fakeSave();\r
- }\r
- }\r
- \r
- eventHandlers.indicator = {\r
- ready: function() {\r
- mainLayout.setView('messages', sandbox.getModule('indicator').getView());\r
- }\r
- }\r
- \r
- /* api */\r
- \r
- return {\r
- start: function() {\r
- sandbox.getModule('data').start();\r
- },\r
- handleEvent: function(moduleName, eventName, args) {\r
- if('')\r
- wysiwigHandler.handleEvent(moduleName, eventName, args);\r
- else if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {\r
- eventHandlers[moduleName][eventName].apply(eventHandlers, args);\r
- }\r
- }\r
- }\r
-};\r
-\r
-});
\ No newline at end of file