var Source = Backbone.Model.extend({ defaults: { api_token: null, rhoconnect_version: null, licensee: null, seats: null, issued: null, source_id: null, partition_type: null, user_id: null, doctype: null, device_id: null }, initialize: function(){ var session = new Session(); this.set('api_token', session.getApiKey()) }, url: '/api/admin', methodUrl: { 'create': '/api/admin/get_license_info', 'read' : '/api/source/list_sources' }, sync: function(method, model, options) { if (model.methodUrl && model.methodUrl[method.toLowerCase()]) { options = options || {}; options.url = model.methodUrl[method.toLowerCase()]; if(method == 'read'){ options.url += "?api_token=" + this.get('api_token') + "&partition_type=" + this.get('partition_type') } } Backbone.sync(method, model, options); }, parse: function(resp){ if(resp[0] != undefined || resp.length < 1){ var user = this.get('user_id'); var doctype = this.get('doctype'); var client_id = this.get('client_id'); var adapters = ""; $.each(resp, function(index,value){ if(doctype == null){ adapters += ""+ value + "" } else{ adapters += ""+ value + "" } }) $('#source-table tr:last').after(adapters); } else{ var license_text = "Licensed to  " + resp["licensee"] + " on " + resp["issued"] + ", available " + resp["available"] + " out of " + resp['seats'] + " devices" var license_footer = "Licensed to Rhomobile "+resp['available']+"/"+resp['seats']+" devices available" $('#license').html(license_text); $('#license_info').html(license_footer); } }, list_source_docs: function(source_id,user_id){ var session = new Session(); $.ajax({ type: 'POST', url: '/api/source/list_source_docs', data: {api_token : session.getApiKey, source_id : source_id, user_id : user_id}, success: function(resp){ var r = JSON.parse(resp) var docs = ""; $.each(r, function(index,value){ docs += "" + index + "" + value + "" }) $('#sourcedocs-table tr:last').after(docs); }, error: function(resp){ if(resp.status == 422){ new App.Views.Index() } $('#docalert')[0].innerHTML = resp.responseText; $('#docalert').css('display','block'); } }) }, get_source_params: function(source_id,user_id){ var session = new Session(); $.ajax({ type: 'POST', url: '/api/source/get_source_params', data: {api_token : session.getApiKey, source_id : source_id, user : user_id}, success: function(resp){ var r = JSON.parse(resp) var params = ""; $.each(r, function(index,value){ if(value.value != null && value.value != "") params += "" + value.name + "" + value.value + "" }) $('#sourceparams-table tr:last').after(params); }, error: function(resp){ if(resp.status == 422){ new App.Views.Index() } $('#docalert')[0].innerHTML = resp.responseText; $('#docalert').css('display','block'); } }) } })