lpio
Version:
The last dashboard app you'll ever need
59 lines (52 loc) • 1.86 kB
HTML
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="crud-api.html">
<script>
window.ApiBehaviors = window.ApiBehaviors || {};
/**
*
* @polymerBehavior ApiBehaviors.Dashboard
*
**/
ApiBehaviors.DashboardImpl = {
createDashboard: function(dashboard){
var self = this;
if(!_.isObject(dashboard)){
console.error("createDashboard: bad object");
return;
}
self.setSaving('dashboards');
self.createEntity('dashboard',dashboard)
.then(function(data){
// added a new dashboard, refresh
self.getAllDashboards();
})
.catch(function(err){
console.error(err);
self.setError('Error creating new dashboard');
})
.finally(function(){
self.setSavingDone('dashboards');
}).done();
},
getAllDashboards: function(){
var self = this;
var url = "http://"+self.host + ":" + self.port + "/v1/dashboard/_all"
self.setLoading('dashboards');
$.ajax({
url: url,
contentType: "application/json"
})
.done(function(data) {
self.dispatch({key:'dashboards',type:'setAll',dashboards:data});
})
.fail(function(jqXHR, textStatus) {
console.error(textStatus);
self.setError('Error retrieving Dashboards');
})
.always(function(){
self.setLoadingDone('dashboards');
});
}
};
ApiBehaviors.Dashboard = [ApiBehaviors.Crud,ApiBehaviors.DashboardImpl];
</script>