1 rng.modules.rng = function(sandbox) {
\r
3 function addTab(title, slug, view) {
\r
4 sandbox.getModule('tabsManager').addTab(title, slug, view);
\r
7 /* Events handling */
\r
11 eventHandlers.skelton = {
\r
13 sandbox.getModule('tabsManager').start();
\r
15 'cmd.save': function() {
\r
16 var editorSlugs = ['visual', 'source'];
\r
17 var slug = sandbox.getModule('tabsManager').getCurrentSlug();
\r
18 if(_.contains(editorSlugs, slug)) {
\r
19 var editor = sandbox.getModule(slug+'Editor');
\r
20 if(editor.isDirty()) {
\r
21 sandbox.getModule('data').commitDocument(editor.getDocument(), slug + '_edit');
\r
22 editor.setDirty(false);
\r
25 sandbox.getModule('data').saveDocument();
\r
29 eventHandlers.tabsManager = {
\r
31 sandbox.getModule('skelton').setMainView(sandbox.getModule('tabsManager').getView());
\r
32 _.each(['visualEditor', 'sourceEditor'], function(moduleName) {
\r
33 sandbox.getModule(moduleName).start();
\r
36 leaving: function(slug) {
\r
37 if(slug === 'source' || slug === 'visual') {
\r
38 var editor = sandbox.getModule(slug+'Editor');
\r
39 if(editor.isDirty()) {
\r
40 sandbox.getModule('data').commitDocument(editor.getDocument(), slug + '_edit');
\r
41 editor.setDirty(false);
\r
45 showed: function(slug) {
\r
46 if(slug === 'visual')
\r
47 sandbox.getModule('visualEditor').onShowed();
\r
51 eventHandlers.sourceEditor = {
\r
53 addTab(gettext('Source'), 'source', sandbox.getModule('sourceEditor').getView());
\r
54 sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());
\r
58 eventHandlers.visualEditor = {
\r
60 sandbox.getModule('visualEditor').setDocument(sandbox.getModule('data').getDocument());
\r
61 addTab(gettext('Visual'), 'visual', sandbox.getModule('visualEditor').getView());
\r
66 eventHandlers.data = {
\r
68 sandbox.getModule('skelton').start();
\r
70 documentChanged: function(document, reason) {
\r
71 var slug = (reason === 'visual_edit' ? 'source' : 'visual');
\r
72 sandbox.getModule(slug+'Editor').setDocument(document);
\r
81 sandbox.getModule('data').start();
\r
83 handleEvent: function(moduleName, eventName, args) {
\r
84 if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
\r
85 eventHandlers[moduleName][eventName].apply(eventHandlers, args);
\r