var Client = Backbone.Model.extend({
defaults: {
api_token: null,
client_id: null
},
initialize: function(){
var session = new Session();
this.set('api_token', session.getApiKey())
},
get_clients: function(user_id){
$.ajax({
type: 'POST',
url: '/api/client/list_clients',
data: {api_token : this.get('api_token'), user_id : user_id},
success: function(resp){
var r = JSON.parse(resp)
data = ""
$.each(r,function(index,value){
data += "
"+value+" |
";
})
$('tr.remove-tr-device').remove();
$('#device-table tr:last').after(data);
},
error: function(resp){
if(resp.status == 422){
new App.Views.Index()
}
$('#showuser-alert')[0].innerHTML = resp.responseText;
$('#showuser-alert').css('display','block');
}
})
},
list_client_docs: function(client_id,source_id){
$.ajax({
type: 'POST',
url: '/api/client/list_client_docs',
data: {api_token : this.get('api_token'), client_id : client_id, source_id : source_id},
success: function(resp){
var r = JSON.parse(resp)
data = ""
$.each(r,function(index,value){
data += ""+value+" |
";
})
$('tr.remove-tr-docs').remove();
$('#sourcedocs-table tr:last').after(data);
},
error: function(resp){
if(resp.status == 422){
new App.Views.Index()
}
$('#showdevice-alert')[0].innerHTML = resp.responseText;
$('#showdevice-alert').css('display','block');
}
})
},
get_client_params: function(client_id){
$.ajax({
type: 'POST',
url: '/api/client/get_client_params',
data: {api_token : this.get('api_token'),client_id : client_id},
success: function(resp){
var r = JSON.parse(resp)
data = "";
$.each(r, function(index,value){
if(value.value != null && value.value != "")
data += "" + value.name + " | " + value.value + " |
"
})
$('tr.remove-tr-client').remove();
$('#deviceattr-table tr:last').after(data);
},
error: function(resp){
if(resp.status == 422){
new App.Views.Index()
}
$('#showdevice-alert')[0].innerHTML = resp.responseText;
$('#showdevice-alert').css('display','block');
}
})
}
})