wip: Getting rid of tabsManager module; using tab view instead
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 5 Jun 2013 13:13:53 +0000 (15:13 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 5 Jun 2013 13:13:53 +0000 (15:13 +0200)
modules.js
modules/rng.js
modules/tabsManager.js [deleted file]
views/tabs/tabs.js

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