9 list.prototype.add = function(element) {
10 if (!this.has(element)) {
11 this.elements.push(element);
15 list.prototype.del = function(element) {
16 if (this.has(element)) {
17 this.elements.splice(index, 1);
21 list.prototype.has = function(element) {
22 index = $.inArray( element, this.elements );
29 list.prototype.count = function() {
30 return this.elements.length;
35 * resources, users, leases
38 function resources() {
62 function slice(name) {
64 this.resources = new resources();
65 this.users = new users();
66 this.leases = new leases();
76 this.testbeds = new list();
77 this.slices = new list();
79 for (i = 0; i < this.user.slices.length; i++) {
80 this.slices[this.user.slices[i]] = new slice(this.user.slices[i]);
84 user.prototype.slice = function(name) {
85 return this.slices[name];
88 user.prototype.list = function() {
89 for (s in this.slices) {
91 if (typeof o != 'function') {
107 if ($.isEmptyObject(this.user)) {
108 //this.login(function() { return this.user; });
114 login: function(fn) {
115 $.post("/rest/user/",{'filters':{'user_hrn':'$user_hrn'}}, function( data ) {
116 myslice.user = new user(data[0]);
120 getSlices: function(name) {
124 refreshUser: function() {
130 //$('div#loading').show();
133 //setTimeout(function(){
134 //$('div#loading').hide();
135 //window.location.href = '/resources/' + this.slice + '?message=true';
140 $.post("/rest/slice/", { 'fields': ['resource','slice_hrn'], 'filters': { 'slice_hrn' : this.slice } }, function(data) {
145 if ('resource' in data[0]) {
146 $.each(data[0].resource, function(idx, r) {
147 resources.push(r.urn);
151 console.log(myslice.pending);
152 console.log(resources);
153 $.each(resources.concat(myslice.pending), function(idx, v) {
157 $.post("/update/slice/", { 'filters': { 'slice_hrn' : myslice.slice }, 'params' : update }, function(data) {
161 console.log(this.slice);
169 // var Reflector = function(obj) {
170 // this.getProperties = function() {
171 // var properties = [];
172 // for (var prop in obj) {
173 // if (typeof obj[prop] != 'function') {
174 // properties.push(prop);
175 // console.log("prop: " + prop);
177 // console.log("func: " + prop);
180 // return properties;
183 // var reflector = new Reflector(myslice.slices[0].resources.pending);
184 // reflector.getProperties();
187 $(document).ready(function() {
188 //console.log(myslice.user().slices);
190 // $.post("/rest/user/",{'filters':{'user_hrn':'$user_hrn'}}, function(data) {
191 // myslice.user = new user(data[0]);
192 // console.log(myslice.user.slices);
193 // myslice.user.list();
195 // }).fail(function() {
196 // throw "error retreiving user data";
198 // Put the object into storage
199 //localStorage.setItem('testObject', JSON.stringify(testObject));
201 // Retrieve the object from storage
207 // add a resource to pending
209 //myslice.user.slice('ple.upmc.myslicedemo').resources.pending.add(resource);