From: Aleksander Ɓukasz Date: Wed, 5 Jun 2013 13:13:53 +0000 (+0200) Subject: wip: Getting rid of tabsManager module; using tab view instead X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/9088c2ab96934ee0318e55dadf3573f3325201ff wip: Getting rid of tabsManager module; using tab view instead --- diff --git a/modules.js b/modules.js index 32010a0..4c24259 100644 --- a/modules.js +++ b/modules.js @@ -8,7 +8,6 @@ define(function(require) { rng: require('modules/rng'), skelton: require('modules/skelton'), sourceEditor: require('modules/sourceEditor'), - tabsManager: require('modules/tabsManager'), visualEditor: require('modules/visualEditor'), documentCanvas: require('modules/documentCanvas/documentCanvas'), diff --git a/modules/rng.js b/modules/rng.js index 0106f03..623d4ff 100644 --- a/modules/rng.js +++ b/modules/rng.js @@ -1,10 +1,12 @@ -define(function() { +define(['views/tabs/tabs'], function(tabs) { return function(sandbox) { 'use strict'; + var mainTabs = (new tabs.View()).render(); + function addTab(title, slug, view) { - sandbox.getModule('tabsManager').addTab(title, slug, view); + mainTabs.addTab(title, slug, view); } /* Events handling */ @@ -13,44 +15,17 @@ return function(sandbox) { eventHandlers.skelton = { ready: function() { - sandbox.getModule('tabsManager').start(); - }, - 'cmd.save': function() { - var editorSlugs = ['visual', 'source']; - var slug = sandbox.getModule('tabsManager').getCurrentSlug(); - if(_.contains(editorSlugs, slug)) { - var editor = sandbox.getModule(slug+'Editor'); - if(editor.isDirty()) { - sandbox.getModule('data').commitDocument(editor.getDocument(), slug + '_edit'); - editor.setDirty(false); - } - } - sandbox.getModule('data').saveDocument(); - } - }; - - eventHandlers.tabsManager = { - ready: function() { - sandbox.getModule('skelton').setMainView(sandbox.getModule('tabsManager').getView()); + sandbox.getModule('skelton').setMainView(mainTabs.getAsView()); + _.each(['visualEditor', 'sourceEditor', 'rng2'], function(moduleName) { sandbox.getModule(moduleName).start(); }); }, - leaving: function(slug) { - if(slug === 'source' || slug === 'visual') { - var editor = sandbox.getModule(slug+'Editor'); - if(editor.isDirty()) { - sandbox.getModule('data').commitDocument(editor.getDocument(), slug + '_edit'); - editor.setDirty(false); - } - } - }, - showed: function(slug) { - if(slug === 'visual') - sandbox.getModule('visualEditor').onShowed(); + 'cmd.save': function() { + //todo } }; - + eventHandlers.sourceEditor = { ready: function() { addTab(gettext('Source'), 'source', sandbox.getModule('sourceEditor').getView()); diff --git a/modules/tabsManager.js b/modules/tabsManager.js deleted file mode 100644 index 70058a9..0000000 --- a/modules/tabsManager.js +++ /dev/null @@ -1,33 +0,0 @@ -define(['views/tabs/tabs'], function(tabsView) { - -return function(sandbox) { - - var view = new tabsView.View(); - view.on('leaving', function(slug) { - sandbox.publish('leaving', slug); - }); - view.on('tabSelected', function(slug) { - sandbox.publish('showed', slug); - }); - - return { - start: function() { - view.render(); - sandbox.publish('ready'); - }, - - getView: function() { - return view.$el; - }, - - addTab: function(title, slug, contentView) { - view.addTab(title, slug, contentView); - - }, - getCurrentSlug: function() { - return view.selectedTab; - } - } -}; - -}); \ No newline at end of file diff --git a/views/tabs/tabs.js b/views/tabs/tabs.js index dcd3e96..c4d7697 100644 --- a/views/tabs/tabs.js +++ b/views/tabs/tabs.js @@ -31,6 +31,7 @@ define([ if(this.options.stacked) { this.nodes.tabBar.addClass('nav-stacked nav-pills'); } + return this; }, addTab: function(title, slug, content) { @@ -61,6 +62,10 @@ define([ } }, + getAsView: function() { + return this.$el; + }, + /* Events */ _onTabTitleClicked: function(e) {