Sha256: 56a71cac6ab445a12dfe48178ee3194ed2c83f3d1c7392e39da0b4709a9e6555

Contents?: true

Size: 1.57 KB

Versions: 15

Compression:

Stored size: 1.57 KB

Contents

if (typeof TasksScheduler == "undefined") {
  TasksScheduler = function() {};
}

TasksScheduler.Alert = function () {
};

_A = TasksScheduler.Alert;

_A.DEFAULT_REFRESH_INTERVAL = 5000;
_A.DEFAULT_ELEMENT_SELECTOR = '#tasks_scheduler_alert';
_A.CSS_CLASSES_PREFIX = 'alert_';
_A.url = Routes.status_tasks_scheduler_daemon_path();

_A.init = function (options) {
  options = typeof options !== 'undefined' ? options : {};
  $(document).ready(function () {
    _A.options = options;
    if (!_A.options.refresh_interval) {
      _A.options.refresh_interval = _A.DEFAULT_REFRESH_INTERVAL;
    }
    if (!_A.options.element_selector) {
      _A.options.element_selector = _A.DEFAULT_ELEMENT_SELECTOR;
    }
    _A.refresh();
  });
};

_A.setNextRefresh = function () {
  setTimeout(_A.refresh, _A.options.refresh_interval);
};

_A.refresh = function () {
  $.ajax(_A.refreshAjaxData());
};

_A.refreshAjaxData = function () {
  return {
    url: _A.url,
    success: function (result) {
      var alert = $(_A.options.element_selector);
      var pattern = new RegExp('(^|\\s)' + _A.CSS_CLASSES_PREFIX + "\\S+", 'g');
      alert.removeClass (function (index, className) {
        return (className.match (pattern) || []).join(' ');
      });
      alert.addClass(_A.resultToCssClass(result));
    },
    complete: function (result) {
      _A.setNextRefresh();
    }
  };
};

_A.resultToCssClass = function(result) {
  var suffix = "ok"
  if (!result.daemon_running) {
    suffix = "daemon_stopped";
  } else if (!result.tasks_all_ok) {
    suffix = "task_failed";
  }
  return _A.CSS_CLASSES_PREFIX + suffix;
};

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
tasks_scheduler-0.6.11 app/assets/javascripts/tasks_scheduler/alert.js
tasks_scheduler-0.6.10 app/assets/javascripts/tasks_scheduler/alert.js
tasks_scheduler-0.6.9 app/assets/javascripts/tasks_scheduler/alert.js
tasks_scheduler-0.6.8 app/assets/javascripts/tasks_scheduler/alert.js
tasks_scheduler-0.6.7 app/assets/javascripts/tasks_scheduler/alert.js
tasks_scheduler-0.6.6 app/assets/javascripts/tasks_scheduler/alert.js
tasks_scheduler-0.6.5 app/assets/javascripts/tasks_scheduler/alert.js
tasks_scheduler-0.6.4 app/assets/javascripts/tasks_scheduler/alert.js
tasks_scheduler-0.6.3 app/assets/javascripts/tasks_scheduler/alert.js
tasks_scheduler-0.6.2 app/assets/javascripts/tasks_scheduler/alert.js
tasks_scheduler-0.6.1 app/assets/javascripts/tasks_scheduler/alert.js
tasks_scheduler-0.6.0 app/assets/javascripts/tasks_scheduler/alert.js
tasks_scheduler-0.5.4 app/assets/javascripts/tasks_scheduler/alert.js
tasks_scheduler-0.5.3 app/assets/javascripts/tasks_scheduler/alert.js
tasks_scheduler-0.5.2 app/assets/javascripts/tasks_scheduler/alert.js