OLD | NEW |
1 /* | 1 /* |
2 This file is part of the Juju GUI, which lets users view and manage Juju | 2 This file is part of the Juju GUI, which lets users view and manage Juju |
3 environments within a graphical interface (https://launchpad.net/juju-gui). | 3 environments within a graphical interface (https://launchpad.net/juju-gui). |
4 Copyright (C) 2012-2013 Canonical Ltd. | 4 Copyright (C) 2012-2013 Canonical Ltd. |
5 | 5 |
6 This program is free software: you can redistribute it and/or modify it under | 6 This program is free software: you can redistribute it and/or modify it under |
7 the terms of the GNU Affero General Public License version 3, as published by | 7 the terms of the GNU Affero General Public License version 3, as published by |
8 the Free Software Foundation. | 8 the Free Software Foundation. |
9 | 9 |
10 This program is distributed in the hope that it will be useful, but WITHOUT | 10 This program is distributed in the hope that it will be useful, but WITHOUT |
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 | 837 |
838 @method checkForExistingService | 838 @method checkForExistingService |
839 @param {String} serviceName of the new service to deploy. | 839 @param {String} serviceName of the new service to deploy. |
840 @return {Boolean} true if it exists, false if doesn't. | 840 @return {Boolean} true if it exists, false if doesn't. |
841 */ | 841 */ |
842 utils.checkForExistingService = function(serviceName, db) { | 842 utils.checkForExistingService = function(serviceName, db) { |
843 var existingService = db.services.getById(serviceName); | 843 var existingService = db.services.getById(serviceName); |
844 return (existingService) ? true : false; | 844 return (existingService) ? true : false; |
845 }; | 845 }; |
846 | 846 |
| 847 utils.validateServiceName = function(serviceName, db) { |
| 848 if (!utils.checkForExistingService(serviceName, db)) { |
| 849 // Regex re-worked from juju-core to work properly in javascript |
| 850 // http://bazaar.launchpad.net/ |
| 851 // ~go-bot/juju-core/trunk/view/head:/names/service.go |
| 852 var regex = /[a-z][a-z0-9]*(?:-[a-z0-9]*[a-z][a-z0-9]*)*/, |
| 853 result = serviceName.match(regex); |
| 854 if (Y.Lang.isArray(result) && result[0] === serviceName) { |
| 855 return true; |
| 856 } |
| 857 } |
| 858 return false; |
| 859 }; |
| 860 |
847 utils.validate = function(values, schema) { | 861 utils.validate = function(values, schema) { |
848 var errors = {}; | 862 var errors = {}; |
849 | 863 |
850 /** | 864 /** |
851 * Translate a value into a string, translating non-values into an empty | 865 * Translate a value into a string, translating non-values into an empty |
852 * string. | 866 * string. |
853 * | 867 * |
854 * @method toString | 868 * @method toString |
855 * @param {Object} value The value to stringify. | 869 * @param {Object} value The value to stringify. |
856 * @return {String} The input value translated into a string. | 870 * @return {String} The input value translated into a string. |
(...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1813 'escape', | 1827 'escape', |
1814 'handlebars', | 1828 'handlebars', |
1815 'node', | 1829 'node', |
1816 'view', | 1830 'view', |
1817 'panel', | 1831 'panel', |
1818 'json-stringify', | 1832 'json-stringify', |
1819 'gallery-markdown', | 1833 'gallery-markdown', |
1820 'datatype-date-format' | 1834 'datatype-date-format' |
1821 ] | 1835 ] |
1822 }); | 1836 }); |
OLD | NEW |