Code coverage report for app/controllers/global/wizard_watcher_controller.js

Statements: 100% (15 / 15)      Branches: 100% (6 / 6)      Functions: 100% (8 / 8)      Lines: 100% (15 / 15)      Ignored: none     

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