Custom validation for Tenant View

Change-Id: Id5f51af2a142c72bd1947a1ea267e16f10a5864c
diff --git a/views/ngXosViews/tenant/src/js/createslice.js b/views/ngXosViews/tenant/src/js/createslice.js
index a522e49..699ae1d 100644
--- a/views/ngXosViews/tenant/src/js/createslice.js
+++ b/views/ngXosViews/tenant/src/js/createslice.js
@@ -35,7 +35,7 @@
             label: 'Save and continue editing',

             icon: 'ok', // refers to bootstraps glyphicon

             cb: (model, form) => { // receive the model

-              saveform(model,form);

+              saveform(model, form);

             },

             class: 'primary'

           },

@@ -43,8 +43,8 @@
             label: 'Save and add another',

             icon: 'ok', // refers to bootstraps glyphicon

             cb: (model, form) => {

-              saveform(model,form).then(()=> {

-                $state.go('createslice',{site : this.model.site,id : ''});

+              saveform(model, form).then(()=> {

+                $state.go('createslice', { site: this.model.site, id: ''});

               });

             },

             class: 'primary'

@@ -65,7 +65,27 @@
             type: 'string',

             hint: 'The Name of the Slice',

             validators: {

-              required: true

+              required: true,

+              custom: (value)=>{

+                if(this.model.site){

+                  var options_list = this.config.fields.site.options;

+                  var i;

+                  for (i=0;i<options_list.length;i++){

+                    if(options_list[i].id === this.model.site)

+                    {

+                      if(this.model.name) {

+                        return (this.model.name.toLowerCase().indexOf(options_list[i].label.toLowerCase()) === 0) ;

+                      }

+                      else{

+                        return false;

+                      }

+                    }

+                  }

+                }

+                else{

+                  return false;

+                }

+              }

             }

           },

           serviceClass: {

diff --git a/xos/core/xoslib/static/css/xosTenant.css b/xos/core/xoslib/static/css/xosTenant.css
index 1675325..2ef5d87 100644
--- a/xos/core/xoslib/static/css/xosTenant.css
+++ b/xos/core/xoslib/static/css/xosTenant.css
@@ -1 +1 @@
-#xosTenant a{margin-bottom:15px}
\ No newline at end of file
+#xosTenant [ui-view]{margin-bottom:100px}#xosTenant a{margin-bottom:15px}
\ No newline at end of file
diff --git a/xos/core/xoslib/static/js/xosTenant.js b/xos/core/xoslib/static/js/xosTenant.js
index 67db7e6..10093f7 100644
--- a/xos/core/xoslib/static/js/xosTenant.js
+++ b/xos/core/xoslib/static/js/xosTenant.js
@@ -1 +1 @@
-"use strict";angular.module("xos.tenant",["ngResource","ngCookies","ui.router","xos.helpers"]).config(["$stateProvider",function(e){e.state("site-list",{url:"/",template:"<site-list></site-list>"}).state("site",{url:"/site/:id",template:"<site-detail></site-detail>"}).state("createslice",{url:"/site/:site/slice/:id?",template:"<create-slice></create-slice>"})}]).config(["$httpProvider",function(e){e.interceptors.push("NoHyperlinks")}]).directive("siteList",function(){return{restrict:"E",scope:{},bindToController:!0,controllerAs:"vm",templateUrl:"templates/users-list.tpl.html",controller:["Sites","SlicesPlus",function(e,t){var i=this;this.tableConfig={columns:[{label:"Site",prop:"name",link:function(e){return"#/site/"+e.id}},{label:"Allocated",prop:"instance_total"},{label:"Ready",prop:"instance_total_ready"}]},e.query().$promise.then(function(e){return i.sites=e,t.query().$promise}).then(function(e){i.slices=e,i.site_list=i.returnData(i.sites,i.slices)})["catch"](function(e){throw new Error(e)}),this.returnData=function(e,t){var i,s=0,l=[];for(i=0;i<e.length;i++){var n=0,a=0;for(s=0;s<t.length;s++)null!=e[i].id&&null!=t[s].site&&e[i].id===t[s].site&&(n+=t[s].instance_total,a+=t[s].instance_total_ready);var o={id:e[i].id,name:e[i].name,instance_total:n,instance_total_ready:a};l.push(o)}return l}}]}}),angular.module("xos.tenant").run(["$templateCache",function(e){e.put("templates/createslice.html",'<!--<xos-table config="cs.tableConfig" data="cs.sites"></xos-table>-->\n<h2>Slice Details</h2>\n<hr></hr>\n<xos-form ng-model="cs.model" config="cs.config" ></xos-form>\n\n<!--<pre>-->\n<!--&lt;!&ndash;{{cs.users | json}}&ndash;&gt;-->\n\n<!--{{cs.users.name | json}}-->\n\n<!--</pre>-->'),e.put("templates/slicelist.html",'<!--<span ng-bind="siteNameSe"></span>-->\n<!--<xos-field></xos-field>-->\n<a class="addlink btn btn-info" ui-sref="createslice({site: sl.siteId})"><i class="glyphicon glyphicon-plus-sign"></i> Create Slice</a>\n<xos-table config="sl.tableConfig" data="sl.sliceList"></xos-table>\n<!--<div ui-view="sliceDetails"></div>-->\n<!--<pre>{{sl.users[0].site}}</pre>-->\n'),e.put("templates/users-list.tpl.html",'<xos-table config="vm.tableConfig" data="vm.site_list"></xos-table>')}]),angular.module("xos.tenant").directive("siteDetail",function(){return{restrict:"E",scope:{},bindToController:!0,controllerAs:"sl",templateUrl:"templates/slicelist.html",controller:["SlicesPlus","$stateParams",function(e,t){var i=this;this.siteId=t.id,this.tableConfig={columns:[{label:"Slice List",prop:"name",link:function(e){return"#/site/"+e.site+"/slice/"+e.id}},{label:"Allocated",prop:"instance_total"},{label:"Ready",prop:"instance_total_ready"}]},e.query({site:t.id}).$promise.then(function(e){i.sliceList=e})["catch"](function(e){throw new Error(e)})}]}}),angular.module("xos.tenant").directive("createSlice",function(){return{restrict:"E",scope:{},bindToController:!0,controllerAs:"cs",templateUrl:"templates/createslice.html",controller:["Slices","SlicesPlus","Sites","Images","$stateParams","$http","$state","$q","XosUserPrefs",function(e,t,i,s,l,n,a,o,r){var c=this;this.config={exclude:["site","password","last_login","mount_data_sets","default_flavor","creator","exposed_ports","networks","omf_friendly","omf_friendly","no_sync","no_policy","lazy_blocked","write_protect","deleted","backend_status","backend_register","policed","enacted","updated","created","validators","humanReadableName"],formName:"SliceDetails",feedback:{show:!1,message:"Form submitted successfully !!!",type:"success"},actions:[{label:"Save",icon:"ok",cb:function(e,t){u(e,t).then(function(){a.go("site",{id:c.model.site})})},"class":"success"},{label:"Save and continue editing",icon:"ok",cb:function(e,t){u(e,t)},"class":"primary"},{label:"Save and add another",icon:"ok",cb:function(e,t){u(e,t).then(function(){a.go("createslice",{site:c.model.site,id:""})})},"class":"primary"}],fields:{site:{label:"Site",type:"select",validators:{required:!0},hint:"The Site this Slice belongs to",options:[]},name:{label:"Name",type:"string",hint:"The Name of the Slice",validators:{required:!0}},serviceClass:{label:"ServiceClass",type:"select",validators:{required:!0},hint:"The Site this Slice belongs to",options:[{id:1,label:"Best effort"}]},enabled:{label:"Enabled",type:"boolean",hint:"Status for this Slice"},description:{label:"Description",type:"string",hint:"High level description of the slice and expected activities",validators:{required:!1,minlength:10}},service:{label:"Service",type:"select",validators:{required:!1},options:[{id:0,label:"--------"}]},slice_url:{label:"Slice url",type:"string",validators:{required:!1,minlength:10}},max_instances:{label:"Max Instances",type:"number",validators:{required:!1,min:0}},default_isolation:{label:"Default Isolation",type:"select",validators:{required:!1},options:[{id:"vm",label:"Virtual Machine"},{id:"container",label:"Container"},{id:"container_vm",label:"Container in VM"}]},default_image:{label:"Default image",type:"select",validators:{required:!1},options:[]},network:{label:"Network",type:"select",validators:{required:!1},options:[{id:"default",label:"Default"},{id:"host",label:"Host"},{id:"bridged",label:"Bridged"},{id:"noauto",label:"No Automatic Networks"}]}}};var d;s.query().$promise.then(function(e){c.users=e,d=c.users,c.optionValImg=c.setData(d,{field1:"id",field2:"name"}),c.config.fields.default_image.options=c.optionValImg})["catch"](function(e){throw new Error(e)}),this.setData=function(e,t){var i,s=[];for(i=0;i<e.length;i++){var l={id:e[i][t.field1],label:e[i][t.field2]};s.push(l)}return s},l.id?(delete this.config.fields.site,this.config.exclude.push("site"),e.get({id:l.id}).$promise.then(function(e){c.users=e,d=e,c.model=d})["catch"](function(e){throw new Error(e)})):(this.model={},r.getUserDetailsCookie().$promise.then(function(e){c.model.creator=e.current_user_id})["catch"](function(e){throw new Error(e)}),i.query().$promise.then(function(e){c.users_site=e,c.optionVal=c.setData(c.users_site,{field1:"id",field2:"name"}),c.config.fields.site.options=c.optionVal})["catch"](function(e){throw new Error(e)}));var u=function(t,i){var s=o.defer();if(delete t.networks,i.$valid){if(t.id)var l=e.update(t).$promise;else var l=e.save(t).$promise;l.then(function(e){c.model=e,c.config.feedback.show=!0,s.resolve(c.model)})["catch"](function(e){c.config.feedback.show=!0,c.config.feedback.type="danger",e.data&&e.data.detail?c.config.feedback.message=e.data.detail:c.config.feedback.message=e.statusText,s.reject(e)})}return s.promise}}]}}),angular.module("xos.tenant").run(["$location",function(e){e.path("/")}]);
\ No newline at end of file
+"use strict";angular.module("xos.tenant",["ngResource","ngCookies","ui.router","xos.helpers"]).config(["$stateProvider",function(e){e.state("site-list",{url:"/",template:"<site-list></site-list>"}).state("site",{url:"/site/:id",template:"<site-detail></site-detail>"}).state("createslice",{url:"/site/:site/slice/:id?",template:"<create-slice></create-slice>"})}]).config(["$httpProvider",function(e){e.interceptors.push("NoHyperlinks")}]).directive("siteList",function(){return{restrict:"E",scope:{},bindToController:!0,controllerAs:"vm",templateUrl:"templates/users-list.tpl.html",controller:["Sites","SlicesPlus",function(e,t){var i=this;this.tableConfig={columns:[{label:"Site",prop:"name",link:function(e){return"#/site/"+e.id}},{label:"Allocated",prop:"instance_total"},{label:"Ready",prop:"instance_total_ready"}]},e.query().$promise.then(function(e){return i.sites=e,t.query().$promise}).then(function(e){i.slices=e,i.site_list=i.returnData(i.sites,i.slices)})["catch"](function(e){throw new Error(e)}),this.returnData=function(e,t){var i,s=0,l=[];for(i=0;i<e.length;i++){var n=0,a=0;for(s=0;s<t.length;s++)null!=e[i].id&&null!=t[s].site&&e[i].id===t[s].site&&(n+=t[s].instance_total,a+=t[s].instance_total_ready);var o={id:e[i].id,name:e[i].name,instance_total:n,instance_total_ready:a};l.push(o)}return l}}]}}),angular.module("xos.tenant").run(["$templateCache",function(e){e.put("templates/createslice.html",'<!--<xos-table config="cs.tableConfig" data="cs.sites"></xos-table>-->\n<h2>Slice Details</h2>\n<hr></hr>\n<xos-form ng-model="cs.model" config="cs.config" ></xos-form>\n\n<!--<pre>-->\n<!--&lt;!&ndash;{{cs.users | json}}&ndash;&gt;-->\n\n<!--{{cs.users.name | json}}-->\n\n<!--</pre>-->'),e.put("templates/slicelist.html",'<!--<span ng-bind="siteNameSe"></span>-->\n<!--<xos-field></xos-field>-->\n<a class="addlink btn btn-info" ui-sref="createslice({site: sl.siteId})"><i class="glyphicon glyphicon-plus-sign"></i> Create Slice</a>\n<xos-table config="sl.tableConfig" data="sl.sliceList"></xos-table>\n<!--<div ui-view="sliceDetails"></div>-->\n<!--<pre>{{sl.users[0].site}}</pre>-->\n'),e.put("templates/users-list.tpl.html",'<xos-table config="vm.tableConfig" data="vm.site_list"></xos-table>')}]),angular.module("xos.tenant").directive("siteDetail",function(){return{restrict:"E",scope:{},bindToController:!0,controllerAs:"sl",templateUrl:"templates/slicelist.html",controller:["SlicesPlus","$stateParams",function(e,t){var i=this;this.siteId=t.id,this.tableConfig={columns:[{label:"Slice List",prop:"name",link:function(e){return"#/site/"+e.site+"/slice/"+e.id}},{label:"Allocated",prop:"instance_total"},{label:"Ready",prop:"instance_total_ready"}]},e.query({site:t.id}).$promise.then(function(e){i.sliceList=e})["catch"](function(e){throw new Error(e)})}]}}),angular.module("xos.tenant").directive("createSlice",function(){return{restrict:"E",scope:{},bindToController:!0,controllerAs:"cs",templateUrl:"templates/createslice.html",controller:["Slices","SlicesPlus","Sites","Images","$stateParams","$http","$state","$q","XosUserPrefs",function(e,t,i,s,l,n,a,o,r){var c=this;this.config={exclude:["site","password","last_login","mount_data_sets","default_flavor","creator","exposed_ports","networks","omf_friendly","omf_friendly","no_sync","no_policy","lazy_blocked","write_protect","deleted","backend_status","backend_register","policed","enacted","updated","created","validators","humanReadableName"],formName:"SliceDetails",feedback:{show:!1,message:"Form submitted successfully !!!",type:"success"},actions:[{label:"Save",icon:"ok",cb:function(e,t){u(e,t).then(function(){a.go("site",{id:c.model.site})})},"class":"success"},{label:"Save and continue editing",icon:"ok",cb:function(e,t){u(e,t)},"class":"primary"},{label:"Save and add another",icon:"ok",cb:function(e,t){u(e,t).then(function(){a.go("createslice",{site:c.model.site,id:""})})},"class":"primary"}],fields:{site:{label:"Site",type:"select",validators:{required:!0},hint:"The Site this Slice belongs to",options:[]},name:{label:"Name",type:"string",hint:"The Name of the Slice",validators:{required:!0,custom:function(e){if(!c.model.site)return!1;var t,i=c.config.fields.site.options;for(t=0;t<i.length;t++)if(i[t].id===c.model.site)return!!c.model.name&&0===c.model.name.toLowerCase().indexOf(i[t].label.toLowerCase())}}},serviceClass:{label:"ServiceClass",type:"select",validators:{required:!0},hint:"The Site this Slice belongs to",options:[{id:1,label:"Best effort"}]},enabled:{label:"Enabled",type:"boolean",hint:"Status for this Slice"},description:{label:"Description",type:"string",hint:"High level description of the slice and expected activities",validators:{required:!1,minlength:10}},service:{label:"Service",type:"select",validators:{required:!1},options:[{id:0,label:"--------"}]},slice_url:{label:"Slice url",type:"string",validators:{required:!1,minlength:10}},max_instances:{label:"Max Instances",type:"number",validators:{required:!1,min:0}},default_isolation:{label:"Default Isolation",type:"select",validators:{required:!1},options:[{id:"vm",label:"Virtual Machine"},{id:"container",label:"Container"},{id:"container_vm",label:"Container in VM"}]},default_image:{label:"Default image",type:"select",validators:{required:!1},options:[]},network:{label:"Network",type:"select",validators:{required:!1},options:[{id:"default",label:"Default"},{id:"host",label:"Host"},{id:"bridged",label:"Bridged"},{id:"noauto",label:"No Automatic Networks"}]}}};var d;s.query().$promise.then(function(e){c.users=e,d=c.users,c.optionValImg=c.setData(d,{field1:"id",field2:"name"}),c.config.fields.default_image.options=c.optionValImg})["catch"](function(e){throw new Error(e)}),this.setData=function(e,t){var i,s=[];for(i=0;i<e.length;i++){var l={id:e[i][t.field1],label:e[i][t.field2]};s.push(l)}return s},l.id?(delete this.config.fields.site,this.config.exclude.push("site"),e.get({id:l.id}).$promise.then(function(e){c.users=e,d=e,c.model=d})["catch"](function(e){throw new Error(e)})):(this.model={},r.getUserDetailsCookie().$promise.then(function(e){c.model.creator=e.current_user_id})["catch"](function(e){throw new Error(e)}),i.query().$promise.then(function(e){c.users_site=e,c.optionVal=c.setData(c.users_site,{field1:"id",field2:"name"}),c.config.fields.site.options=c.optionVal})["catch"](function(e){throw new Error(e)}));var u=function(t,i){var s=o.defer();if(delete t.networks,i.$valid){if(t.id)var l=e.update(t).$promise;else var l=e.save(t).$promise;l.then(function(e){c.model=e,c.config.feedback.show=!0,s.resolve(e)})["catch"](function(e){c.config.feedback.show=!0,c.config.feedback.type="danger",e.data&&e.data.detail?c.config.feedback.message=e.data.detail:c.config.feedback.message=e.statusText,s.reject(e)})}return s.promise}}]}}),angular.module("xos.tenant").run(["$location",function(e){e.path("/")}]);
\ No newline at end of file