tab-installed.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. var MainTab = BaseView.extend({
  2. el: '#tab',
  3. name: 'main',
  4. templateUrl: '/options/templates/tab-installed.html',
  5. events: {
  6. 'click #bNew': 'newScript',
  7. 'click #bUpdate': 'updateAll',
  8. },
  9. initialize: function () {
  10. var _this = this;
  11. BaseView.prototype.initialize.call(_this);
  12. _this.listenTo(scriptList, 'reset', _this.render);
  13. _this.listenTo(scriptList, 'add', _this.addOne);
  14. _this.listenTo(scriptList, 'add update', _this.setBackdrop);
  15. _this.listenTo(scriptList, 'edit:open', function (model) {
  16. _this.closeEdit();
  17. _this.editView = new EditView({model: model.clone()});
  18. _this.$el.append(_this.editView.$el);
  19. });
  20. _this.listenTo(scriptList, 'edit:close', _this.closeEdit);
  21. },
  22. closeEdit: function () {
  23. var _this = this;
  24. if (_this.editView) {
  25. _this.editView.remove();
  26. _this.editView = null;
  27. }
  28. },
  29. _render: function () {
  30. this.$el.html(this.templateFn());
  31. this.$list = this.$('.scripts');
  32. this.$bd = this.$('.backdrop');
  33. this.$bdm = this.$('.backdrop > div');
  34. this.setBackdrop();
  35. this.addAll();
  36. },
  37. setBackdrop: function () {
  38. if (scriptList.loading) {
  39. this.$bd.addClass('mask').show();
  40. this.$bdm.html(_.i18n('msgLoading'));
  41. } else if (!scriptList.length) {
  42. this.$bd.removeClass('mask').show();
  43. this.$bdm.html(_.i18n('labelNoScripts'));
  44. } else {
  45. this.$bd.hide();
  46. }
  47. },
  48. addOne: function (script) {
  49. var view = new ScriptView({model: script});
  50. this.$list.append(view.$el);
  51. },
  52. addAll: function () {
  53. scriptList.forEach(this.addOne, this);
  54. },
  55. newScript: function () {
  56. _.sendMessage({cmd: 'NewScript'}).then(function (script) {
  57. scriptList.trigger('edit:open', new Script(script));
  58. });
  59. },
  60. updateAll: function () {
  61. _.sendMessage({cmd: 'CheckUpdateAll'});
  62. },
  63. });