X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fcore%2Fxoslib%2Fstatic%2Fjs%2Fxoslib%2Fxos-backbone.js;h=1ca13070ddb4330adcec7c438a8901039a330783;hb=058ff324def456d1e4f2d85069b91f6cfc1108eb;hp=e990e186297b6ccc4619a6b6380100946430447a;hpb=3d5761043a144a81b04023c5fba94a163a799819;p=plstackapi.git diff --git a/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js b/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js index e990e18..1ca1307 100644 --- a/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js +++ b/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js @@ -6,6 +6,7 @@ if (! window.XOSLIB_LOADED ) { SLICEROLE_API = "/plstackapi/slice_roles/"; NODE_API = "/plstackapi/nodes/"; SITE_API = "/plstackapi/sites/"; + SITEDEPLOYMENT_API = "/plstackapi/sitedeployments/"; USER_API = "/plstackapi/users/"; USERDEPLOYMENT_API = "/plstackapi/user_deployments/"; DEPLOYMENT_API = "/plstackapi/deployments/"; @@ -18,6 +19,11 @@ if (! window.XOSLIB_LOADED ) { SLICEPRIVILEGE_API = "/plstackapi/slice_privileges/"; NETWORKDEPLOYMENT_API = "/plstackapi/networkdeployments/"; FLAVOR_API = "/plstackapi/flavors/"; + CONTROLLER_API = "/plstackapi/controllers/"; + + /* removed + CONTROLLERSITEDEPLOYMENT_API = "/plstackapi/controllersitedeploymentses"; + */ /* changed as a side effect of the big rename SLICEDEPLOYMENT_API = "/plstackapi/slice_deployments/"; @@ -28,8 +34,16 @@ if (! window.XOSLIB_LOADED ) { USERDEPLOYMENT_API = "/plstackapi/userdeployments/"; SLICEPLUS_API = "/xoslib/slicesplus/"; + TENANTVIEW_API = "/xoslib/tenantview/" XOSModel = Backbone.Model.extend({ + relatedCollections: [], + foreignCollections: [], + foreignFields: {}, + m2mFields: {}, + readonlyFields: [], + detailLinkFields: [], + /* from backbone-tastypie.js */ //idAttribute: 'resource_uri', @@ -146,6 +160,10 @@ if (! window.XOSLIB_LOADED ) { relatedCollections: [], foreignCollections: [], + foreignFields: {}, + m2mFields: {}, + readonlyFields: [], + detailLinkFields: [], sorted: function() { //console.log("sorted " + this.modelName); @@ -301,18 +319,12 @@ if (! window.XOSLIB_LOADED ) { var url = this.urlRoot || ( models && models.length && models[0].urlRoot ); url && ( url += ( url.length > 0 && url.charAt( url.length - 1 ) === '/' ) ? '' : '/' ); - // Build a url to retrieve a set of models. This assume the last part of each model's idAttribute - // (set to 'resource_uri') contains the model's id. - if ( models && models.length ) { - var ids = _.map( models, function( model ) { - var parts = _.compact( model.id.split('/') ); - return parts[ parts.length - 1 ]; - }); - url += 'set/' + ids.join(';') + '/'; - } - url && ( url += "?no_hyperlinks=1" ); + if (this.currentUserCanSee) { + url && ( url += "¤t_user_can_see=1" ); + } + return url; }, @@ -327,9 +339,26 @@ if (! window.XOSLIB_LOADED ) { }, }); + function get_defaults(modelName) { + if ((typeof xosdefaults !== "undefined") && xosdefaults[modelName]) { + return xosdefaults[modelName]; + } + return undefined; + } + + function extend_defaults(modelName, stuff) { + defaults = get_defaults(modelName); + if (defaults) { + return $.extend({}, defaults, stuff); + } else { + return stuff; + } + } + function define_model(lib, attrs) { modelName = attrs.modelName; modelClassName = modelName; + collectionClass = attrs.collectionClass || XOSCollection; collectionClassName = modelName + "Collection"; if (!attrs.addFields) { @@ -352,7 +381,7 @@ if (! window.XOSLIB_LOADED ) { for (key in attrs) { value = attrs[key]; - if ($.inArray(key, ["urlRoot", "modelName", "collectionName", "listFields", "addFields", "detailFields", "detailLinkFields", "foreignFields", "inputType", "relatedCollections", "foreignCollections"])>=0) { + if ($.inArray(key, ["urlRoot", "modelName", "collectionName", "listFields", "addFields", "detailFields", "detailLinkFields", "foreignFields", "inputType", "relatedCollections", "foreignCollections", "defaults"])>=0) { modelAttrs[key] = value; collectionAttrs[key] = value; } @@ -361,10 +390,14 @@ if (! window.XOSLIB_LOADED ) { } } - if ((typeof xosdefaults !== "undefined") && xosdefaults[modelName]) { - modelAttrs["defaults"] = xosdefaults[modelName]; + if (!modelAttrs.defaults) { + modelAttrs.defaults = get_defaults(modelName); } +// if ((typeof xosdefaults !== "undefined") && xosdefaults[modelName]) { +// modelAttrs["defaults"] = xosdefaults[modelName]; +// } + if ((typeof xosvalidators !== "undefined") && xosvalidators[modelName]) { modelAttrs["validators"] = xosvalidators[modelName]; } @@ -373,7 +406,7 @@ if (! window.XOSLIB_LOADED ) { collectionAttrs["model"] = lib[modelName]; - lib[collectionClassName] = XOSCollection.extend(collectionAttrs); + lib[collectionClassName] = collectionClass.extend(collectionAttrs); lib[collectionName] = new lib[collectionClassName](); lib.allCollectionNames.push(collectionName); @@ -397,6 +430,41 @@ if (! window.XOSLIB_LOADED ) { } }; + /* defining the models + + modelName - name of the model. + + relatedCollections - collections which should be drawn as an inline + list when the detail view is displayed. + Format: : where + is the name of the field + in the collection that points back to the + collection in the detail view. + + foreignCollections - collections which are used in idToName() calls + when presenting the data to the user. Used to + create a listento event. Somewhat + redundant with foreignFields. + + foreignFields - :. Used to + automatically map ids into humanReadableNames + when presenting data to the user. + + m2mfields - :. Used to + populate choices in picker lists. Simalar to + foreignFields. + + listFields - fields to display in lists + + detailFields - fields to display in detail views + + addFields - fields to display in popup add windows + + inputType - by default, "detailFields" will be displayed + as text input controls. This will let you display + a checkbox or a picker instead. + */ + define_model(this, {urlRoot: SLIVER_API, relatedCollections: {"networkSlivers": "sliver"}, foreignCollections: ["slices", "deployments", "images", "nodes", "users", "flavors"], @@ -454,13 +522,22 @@ if (! window.XOSLIB_LOADED ) { }); define_model(this, {urlRoot: SITE_API, - relatedCollections: {"users": "site", "slices": "site", "nodes": "site"}, + relatedCollections: {"users": "site", "slices": "site", "nodes": "site", "siteDeployments": "site"}, modelName: "site", listFields: ["backend_status", "id", "name", "site_url", "enabled", "login_base", "is_public", "abbreviated_name"], detailFields: ["backend_status", "name", "abbreviated_name", "url", "enabled", "is_public", "login_base"], inputType: {"enabled": "checkbox", "is_public": "checkbox"}, }); + define_model(this, {urlRoot: SITEDEPLOYMENT_API, + foreignCollections: ["sites", "deployments", "controllers"], + foreignFields: {"site": "sites", "deployment": "deployments", "controller": "controllers"}, + modelName: "siteDeployment", + listFields: ["backend_status", "id", "site", "deployment", "controller", "availability_zone"], + detailFields: ["backend_status", "site", "deployment", "controller", "availability_zone"], + inputType: {"enabled": "checkbox", "is_public": "checkbox"}, + }); + define_model(this, {urlRoot: USER_API, relatedCollections: {"slicePrivileges": "user", "slices": "owner"}, foreignCollections: ["sites"], @@ -488,8 +565,8 @@ if (! window.XOSLIB_LOADED ) { define_model(this, {urlRoot: NETWORKTEMPLATE_API, modelName: "networkTemplate", - listFields: ["backend_status", "id", "name", "visibility", "translation", "sharedNetworkName", "sharedNetworkId"], - detailFields: ["backend_status", "name", "description", "visibility", "translation", "sharedNetworkName", "sharedNetworkId"], + listFields: ["backend_status", "id", "name", "visibility", "translation", "shared_network_name", "shared_network_id"], + detailFields: ["backend_status", "name", "description", "visibility", "translation", "shared_network_name", "shared_network_id"], }); define_model(this, {urlRoot: NETWORK_API, @@ -522,6 +599,22 @@ if (! window.XOSLIB_LOADED ) { inputType: {"default": "checkbox", "deployments": "picker"}, }); + define_model(this, {urlRoot: CONTROLLER_API, + modelName: "controller", + listFields: ["backend_status", "id", "name", "version", "backend_type"], + detailFields: ["backend_status", "name", "version", "backend_type", "auth_url", "admin_user", "admin_password", "admin_tenant"], + }); + + /* removed + define_model(this, {urlRoot: CONTROLLERSITEDEPLOYMENT_API, + modelName: "controllerSiteDeployment", + foreignCollections: ["site_deployments", "controllers"], + foreignFields: {"site_deployment": "siteDeployments", "controller": "controllers"}, + listFields: ["backend_status", "id", "site_deployment", "controller", "tenant_id"], + detailFields: ["backend_status", "site_deployment", "controller", "tenant_id"], + }); + */ + /* DELETED in site-controller branch define_model(this, {urlRoot: NETWORKDEPLOYMENT_API, @@ -549,7 +642,7 @@ if (! window.XOSLIB_LOADED ) { END stuff deleted in site-controller branch */ - /* not deleted, but seems obsolete and should be replaced by ManyToMany + /* not deleted, but obsolete since it has degenerated to a ManyToMany with no other fields define_model(this, {urlRoot: IMAGEDEPLOYMENTS_API, modelName: "imageDeployment", @@ -563,9 +656,41 @@ if (! window.XOSLIB_LOADED ) { // enhanced REST // XXX this really needs to somehow be combined with Slice, to avoid duplication define_model(this, {urlRoot: SLICEPLUS_API, - relatedCollections: {'slivers': "slice"}, - modelName: "slicePlus", - collectionName: "slicesPlus"}); + relatedCollections: {"slivers": "slice", "slicePrivileges": "slice", "networks": "owner"}, + foreignCollections: ["services", "sites"], + foreignFields: {"service": "services", "site": "sites"}, + listFields: ["backend_status", "id", "name", "enabled", "description", "slice_url", "site", "max_slivers", "service"], + detailFields: ["backend_status", "name", "site", "enabled", "description", "slice_url", "max_slivers"], + inputType: {"enabled": "checkbox"}, + modelName: "slicePlus", + collectionName: "slicesPlus", + defaults: extend_defaults("slice", {"network_ports": "", "site_allocation": []}), + xosValidate: function(attrs, options) { + errors = XOSModel.prototype.xosValidate(this, attrs, options); + // validate that slice.name starts with site.login_base + site = attrs.site || this.site; + if ((site!=undefined) && (attrs.name!=undefined)) { + site = xos.sites.get(site); + if (attrs.name.indexOf(site.attributes.login_base+"_") != 0) { + errors = errors || {}; + errors["name"] = "must start with " + site.attributes.login_base + "_"; + } + } + return errors; + }, + }); + + define_model(this, {urlRoot: TENANTVIEW_API, + modelName: "tenantview", + collectionName: "tenantview", + listFields: [], + detailFields: [], + }); + + /* by default, have slicePlus only fetch the slices the user can see */ + this.slicesPlus.currentUserCanSee = true; + + this.tenant = function() { return this.tenantview.models[0].attributes; }; this.listObjects = function() { return this.allCollectionNames; };