lib/suricate/generator/assets/javascript/widget-view.js in suricate-0.0.2 vs lib/suricate/generator/assets/javascript/widget-view.js in suricate-0.0.3
- old
+ new
@@ -1,11 +1,18 @@
(function() {
"use strict";
window.Suricate = window.Suricate || {};
+ var statuses = {
+ ok: "ok",
+ alert: "danger",
+ warning: "warning"
+ };
+
Suricate.WidgetView = function(content) {
- this.content = $(content);
+ this.content = $(content);
+ this.currentStatus = statuses.ok;
};
/*
* Public
*/
@@ -35,12 +42,36 @@
Suricate.WidgetView.prototype.setPlaceholder = function(name, value) {
this.getPlaceholder(name).html(value);
};
+
+ Suricate.WidgetView.prototype.setStatusOK = function() {
+ this.setStatus(statuses.ok);
+ };
+
+ Suricate.WidgetView.prototype.setStatusAlert = function() {
+ this.setStatus(statuses.alert);
+ };
+
+ Suricate.WidgetView.prototype.setStatusWarning = function() {
+ this.setStatus(statuses.warning);
+ };
+
/*
* Private
*/
Suricate.WidgetView.prototype.getPlaceholder = function(name) {
return this.content.find("[data-widget-binding='" + name + "']");
+ };
+
+ Suricate.WidgetView.prototype.setStatus = function(status) {
+ if(this.currentStatus !== status) {
+ var statuses = ["ok", "danger", "warning"];
+ var statusIndex = statuses.indexOf(status);
+ var classesToRemove = statuses.splice(statusIndex, 1);
+ this.content.removeClass(classesToRemove);
+ this.content.addClass(status);
+ this.currentStatus = status;
+ }
};
}());