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; });
109 if(localStorage.getItem('user')!='undefined'){
110 this.user = JSON.parse(localStorage.getItem('user'));
117 loadSlices: function(slices) {
118 if (typeof(slices) == "undefined"){
120 if(myslice.user != null && typeof(myslice.user.slices) != "undefined" && myslice.user.slices.length>0){
121 slices = myslice.user.slices
124 // myslice.user is in LocalStorage
125 if(typeof(slices) != "undefined"){
127 This allows progressive loading per AM platform
128 Launch queries to get the resources and leases in Manifold Cache
130 TODO support cache for prefixed objects
131 XXX Disabled until it's supported on Manifold side
134 $.post("/rest/platform/", function( data ) {
135 $.each(data, function(index, p) {
136 $.post("/rest/"+p.platform+":resource/", function( data ) {
138 $.post("/rest/"+p.platform+":lease/", function( data ) {
140 $.each( slices, function(i, val) {
141 // Launch a Query for each slice to get it in Manifold Cache
142 $.post("/rest/"+p.platform+":slice/", { 'filters': { 'slice_hrn' : val } }, function(data) {
152 login: function(fn) {
153 user = localStorage.getItem('user');
154 if($.isEmptyObject(user)){
155 // REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2
156 $.post("/rest/myslice:user/",{'filters':{'user_hrn':'$user_hrn'}}, function( data ) {
157 //myslice.user = new user(data[0]);
158 localStorage.setItem('user', JSON.stringify(data[0]));
159 myslice.loadSlices(data[0].slices);
163 getSlices: function(name) {
167 refreshUser: function() {
173 //$('div#loading').show();
176 //setTimeout(function(){
177 //$('div#loading').hide();
178 //window.location.href = '/resources/' + this.slice + '?message=true';
183 $.post("/rest/slice/", { 'fields': ['resource','slice_hrn'], 'filters': { 'slice_hrn' : this.slice } }, function(data) {
188 if ('resource' in data[0]) {
189 $.each(data[0].resource, function(idx, r) {
190 resources.push(r.urn);
194 console.log(myslice.pending);
195 console.log(resources);
196 $.each(resources.concat(myslice.pending), function(idx, v) {
200 $.post("/update/slice/", { 'filters': { 'slice_hrn' : myslice.slice }, 'params' : update }, function(data) {
204 console.log(this.slice);
212 // var Reflector = function(obj) {
213 // this.getProperties = function() {
214 // var properties = [];
215 // for (var prop in obj) {
216 // if (typeof obj[prop] != 'function') {
217 // properties.push(prop);
218 // console.log("prop: " + prop);
220 // console.log("func: " + prop);
223 // return properties;
226 // var reflector = new Reflector(myslice.slices[0].resources.pending);
227 // reflector.getProperties();
230 $(document).ready(function() {
231 //console.log(myslice.user().slices);
233 // $.post("/rest/user/",{'filters':{'user_hrn':'$user_hrn'}}, function(data) {
234 // myslice.user = new user(data[0]);
235 // console.log(myslice.user.slices);
236 // myslice.user.list();
238 // }).fail(function() {
239 // throw "error retreiving user data";
241 // Put the object into storage
242 //localStorage.setItem('testObject', JSON.stringify(testObject));
244 // Retrieve the object from storage
250 // add a resource to pending
252 //myslice.user.slice('ple.upmc.myslicedemo').resources.pending.add(resource);