wizard_watcher_controller.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. App.WizardWatcherController = Em.Controller.extend(App.UserPref, {
  20. name: 'wizardWatcherController',
  21. /**
  22. * @const
  23. */
  24. PREF_KEY: 'wizard-data',
  25. /**
  26. * name of user who working with wizard
  27. * @type {string|null}
  28. */
  29. wizardUser: null,
  30. /**
  31. * @type {string|null}
  32. */
  33. controllerName: null,
  34. /**
  35. * @type {Function}
  36. */
  37. mock: Em.K,
  38. /**
  39. * define whether Wizard is running
  40. * @type {boolean}
  41. */
  42. isWizardRunning: function() {
  43. return !Em.isNone(this.get('wizardUser'));
  44. }.property('wizardUser'),
  45. /**
  46. * @type {string}
  47. */
  48. wizardDisplayName: function() {
  49. if (this.get('controllerName')) {
  50. return Em.I18n.t('wizard.inProgress').format(App.router.get(this.get('controllerName')).get('displayName'));
  51. }
  52. return "";
  53. }.property('controllerName'),
  54. /**
  55. * define whether logged in user is the one who started wizard
  56. * @type {boolean}
  57. */
  58. isNonWizardUser: function() {
  59. return this.get('isWizardRunning') && this.get('wizardUser') !== App.router.get('loginName');
  60. }.property('App.router.loginName', 'wizardUser').volatile(),
  61. /**
  62. * set user who launched wizard
  63. * @returns {$.ajax}
  64. */
  65. setUser: function(controllerName) {
  66. return this.postUserPref(this.get('PREF_KEY'), {
  67. userName: App.router.get('loginName'),
  68. controllerName: controllerName
  69. });
  70. },
  71. /**
  72. * reset user who launched wizard
  73. * @returns {$.ajax}
  74. */
  75. resetUser: function() {
  76. return this.postUserPref(this.get('PREF_KEY'), null);
  77. },
  78. /**
  79. * get user who launched wizard
  80. * @returns {$.ajax}
  81. */
  82. getUser: function() {
  83. return this.getUserPref(this.get('PREF_KEY'));
  84. },
  85. getUserPrefSuccessCallback: function(data) {
  86. if (Em.isNone(data)) {
  87. this.set('wizardUser', null);
  88. this.set('controllerName', null);
  89. } else {
  90. this.set('wizardUser', data.userName);
  91. this.set('controllerName', data.controllerName);
  92. }
  93. },
  94. getUserPrefErrorCallback: function () {
  95. this.resetUser();
  96. }
  97. });