launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #06424
[Merge] lp:~rvb/maas/maas-js-utils into lp:maas
Raphaël Badin has proposed merging lp:~rvb/maas/maas-js-utils into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~rvb/maas/maas-js-utils/+merge/93799
This branch creates the js module Y.maas.utils. It now only contains the utility method getTabIndex that returns a valid index given a string parameter a tabview; or null if the passed-in argument cannot be converted to a valid tab index.
Drive-by fixes:
- rename some template files so that they have more meaning full names
- add ./twistd.log and ./twisted/plugins/dropin.cache to .bzrignore
--
https://code.launchpad.net/~rvb/maas/maas-js-utils/+merge/93799
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/maas-js-utils into lp:maas.
=== modified file '.bzrignore'
--- .bzrignore 2012-02-10 11:55:55 +0000
+++ .bzrignore 2012-02-20 11:11:35 +0000
@@ -18,3 +18,5 @@
./pserv.pid
./TAGS
./tags
+./twistd.log
+./twisted/plugins/dropin.cache
=== added file 'src/maasserver/static/js/tests/test_utils.html'
--- src/maasserver/static/js/tests/test_utils.html 1970-01-01 00:00:00 +0000
+++ src/maasserver/static/js/tests/test_utils.html 2012-02-20 11:11:35 +0000
@@ -0,0 +1,30 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+ <head>
+ <title>Test maas.utils</title>
+
+ <!-- YUI and test setup -->
+ <script type="text/javascript" src="../yui/tests/yui/yui-min.js"></script>
+ <script type="text/javascript" src="../testing/testrunner.js"></script>
+ <script type="text/javascript" src="../testing/testing.js"></script>
+ <!-- The module under test -->
+ <script type="text/javascript" src="../utils.js"></script>
+ <!-- The test suite -->
+ <script type="text/javascript" src="test_utils.js"></script>
+ </head>
+ <body>
+ <span id="suite">maas.utils.tests</span>
+ <div id="placeholder"></div>
+ <script type="text/x-template" id="tabs_template"></script>
+ <div id="tabs">
+ <ul>
+ <li><a href="#tab1">Tab1</a></li>
+ <li><a href="#tab2">Tab2</a></li>
+ </ul>
+ <div>
+ <div id="tab1">Tab1 content</div>
+ <div id="tab2">Tab2 content</div>
+ </div>
+ </script>
+ </body>
+</html>
=== added file 'src/maasserver/static/js/tests/test_utils.js'
--- src/maasserver/static/js/tests/test_utils.js 1970-01-01 00:00:00 +0000
+++ src/maasserver/static/js/tests/test_utils.js 2012-02-20 11:11:35 +0000
@@ -0,0 +1,62 @@
+/* Copyright 2012 Canonical Ltd. This software is licensed under the
+ * GNU Affero General Public License version 3 (see the file LICENSE).
+ */
+
+YUI({ useBrowserConsole: true }).add('maas.utils.tests', function(Y) {
+
+Y.log('loading mass.utils.tests');
+var namespace = Y.namespace('maas.utils.tests');
+
+var module = Y.maas.utils;
+var suite = new Y.Test.Suite("maas.utils Tests");
+
+var tabs_template = Y.one('#tabs_template').getContent();
+
+suite.add(new Y.maas.testing.TestCase({
+ name: 'test-utils',
+
+ createTabs: function() {
+ // Create a tab with 2 tabs (valid indexes: 0 or 1).
+ Y.one("body").append(Y.Node.create(tabs_template));
+ var tabs = new Y.TabView({srcNode: '#tabs'});
+ tabs.render();
+ return tabs;
+ },
+
+ testgetTabIndex_index_empty: function() {
+ var tabs = this.createTabs();
+ var index = module.getTabIndex('', tabs);
+ Y.Assert.isNull(index);
+ },
+
+ testgetTabIndex_index_invalid: function() {
+ var tabs = this.createTabs();
+ var index = module.getTabIndex('invalid!', tabs);
+ Y.Assert.isNull(index);
+ },
+
+ testgetTabIndex_index_too_big: function() {
+ var tabs = this.createTabs();
+ var index = module.getTabIndex('2', tabs);
+ Y.Assert.isNull(index);
+ },
+
+ testgetTabIndex_index_neg: function() {
+ var tabs = this.createTabs();
+ var index = module.getTabIndex('-1', tabs);
+ Y.Assert.isNull(index);
+ },
+
+ testgetTabIndex_index_ok: function() {
+ var tabs = this.createTabs();
+ var index = module.getTabIndex('0', tabs);
+ Y.Assert.areEqual(0, index);
+ }
+
+}));
+
+namespace.suite = suite;
+
+}, '0.1', {'requires': [
+ 'tabview', 'node', 'test', 'maas.testing', 'maas.utils']}
+);
=== added file 'src/maasserver/static/js/utils.js'
--- src/maasserver/static/js/utils.js 1970-01-01 00:00:00 +0000
+++ src/maasserver/static/js/utils.js 2012-02-20 11:11:35 +0000
@@ -0,0 +1,35 @@
+/* Copyright 2012 Canonical Ltd. This software is licensed under the
+ * GNU Affero General Public License version 3 (see the file LICENSE).
+ *
+ * Maas utilities.
+ *
+ * @module Y.mass.utils
+ */
+
+YUI.add('maas.utils', function(Y) {
+
+Y.log('loading mass.utils');
+var module = Y.namespace('maas.utils');
+
+/**
+ * Return a valid tab (integer) index if the string 'index' contains a valid
+ * tab index for the given 'tabview'. Otherwise, return 'null'.
+ *
+ * @method getTabIndex
+ */
+module.getTabIndex = function(index, tabview) {
+ var tab_index = parseInt(index, 10);
+ var valid_tab_index = (
+ Y.Lang.isValue(tab_index) &&
+ tab_index >= 0 &&
+ tab_index < tabview.size());
+ if (valid_tab_index) {
+ return tab_index;
+ }
+ else {
+ return null;
+ }
+};
+
+}, '0.1', {'requires': ['base']}
+);
=== modified file 'src/maasserver/templates/maasserver/js-conf.html'
--- src/maasserver/templates/maasserver/js-conf.html 2012-02-09 14:29:09 +0000
+++ src/maasserver/templates/maasserver/js-conf.html 2012-02-20 11:11:35 +0000
@@ -21,4 +21,5 @@
<script src="{{ STATIC_URL }}js/node_add.js"></script>
<script src="{{ STATIC_URL }}js/node.js"></script>
<script src="{{ STATIC_URL }}js/prefs.js"></script>
+<script src="{{ STATIC_URL }}js/utils.js"></script>
<script src="{{ STATIC_URL }}js/node_views.js"></script>
=== modified file 'src/maasserver/templates/maasserver/prefs.html'
--- src/maasserver/templates/maasserver/prefs.html 2012-02-15 17:22:22 +0000
+++ src/maasserver/templates/maasserver/prefs.html 2012-02-20 11:11:35 +0000
@@ -7,20 +7,16 @@
{% block head %}
<script type="text/javascript">
<!--
- YUI().use('tabview', 'maas.prefs', function (Y) {
+ YUI().use('tabview', 'maas.prefs', 'maas.utils', function (Y) {
var tabview = new Y.TabView({
srcNode: '#prefs'
});
tabview.render();
// Select the tab with index {{ tab }} (which is taken from the
// query string and set by the Django view).
- var tab_index = parseInt('{{ tab }}');
- var valid_tab_index = (
- Y.Lang.isValue(tab_index) &&
- tab_index >= 0 &&
- tab_index < tabview.size());
- if (valid_tab_index) {
- tabview.selectChild(tab_index);
+ var valid_tab_index = Y.maas.utils.getTabIndex('{{ tab }}', tabview);
+ if (Y.Lang.isValue(valid_tab_index)) {
+ tabview.selectChild(valid_tab_index);
}
var profile_widget = new Y.maas.prefs.TokenWidget(
=== modified file 'src/maasserver/templates/maasserver/settings.html'
--- src/maasserver/templates/maasserver/settings.html 2012-02-17 14:32:49 +0000
+++ src/maasserver/templates/maasserver/settings.html 2012-02-20 11:11:35 +0000
@@ -8,19 +8,15 @@
{% block head %}
<script type="text/javascript">
<!--
- YUI().use('tabview', 'io-form', function (Y) {
+ YUI().use('tabview', 'maas.utils', 'io-form', function (Y) {
var tabview = new Y.TabView({
srcNode: '#settings'
});
tabview.render();
// Select the tab with index {{ tab }}.
- var tab_index = parseInt('{{ tab }}');
- var valid_tab_index = (
- Y.Lang.isValue(tab_index) &&
- tab_index >= 0 &&
- tab_index < tabview.size());
- if (valid_tab_index) {
- tabview.selectChild(tab_index);
+ var valid_tab_index = Y.maas.utils.getTabIndex('{{ tab }}', tabview);
+ if (Y.Lang.isValue(valid_tab_index)) {
+ tabview.selectChild(valid_tab_index);
}
});
=== renamed file 'templates/module.html' => 'templates/test_module.html'
=== renamed file 'templates/test.js' => 'templates/test_module.js'
=== renamed file 'templates/test.py' => 'templates/test_module.py'