Your IP : 18.219.40.177


Current Path : /usr/local/mgr5/skins/orion/src/
Upload File :
Current File : //usr/local/mgr5/skins/orion/src/App.ConfirmForm.js

/**
 * Module provide confirm form
 *  @param {object} window  global object
 *  @param {function} $ jQuery library
 *  @param {object} EventMgr EventMgr library
 *  @param {object} App Application
 *  @return {object} api
 */
App.ConfirmForm = function(window, $, EventMgr, App) {
  'use strict';

  var confirmElems = {};

  function checkWarningForConfirm(e, d) {
    if (d && d.w) {
      var warning,
          index = 0,
          confirmKey,
          plid = d.d.plid,
          listaction = d.d.func,
          tabId = d.d.tabId,
          hasConfirmWarning = false;
      confirmElems[tabId] = {};
      for (var key in d.w) {
        warning = d.w[key];
        if (warning.type === 'extraconfirm') {
          confirmKey = warning.func + warning.value;
          hasConfirmWarning = true;
          if (!confirmElems[tabId][confirmKey]) {
            confirmElems[tabId][confirmKey] = {
              'elid': [],
              //'func': 'groupedit',
              'func': warning.func,
              'plid': plid,
              'listaction': listaction,
              'action': warning.src_func
              //'faction': warning.func
            };
          }
          confirmElems[tabId][confirmKey].elid.push(String(warning.elid).replace(/,\s/g, ', , '));
        }
      }
      if (hasConfirmWarning) {
        openConfirmForm(confirmElems[tabId], tabId);
      }
    }
  }

  function openConfirmForm(elems, tabId) {
    var hasNext = false;
    for (var key in elems) {
      var w = elems[key],
          param = w;
      param.elid = w.elid.join(', ');
      EventMgr.trigger('ajaxRequest', {
        param: param,
        invar: { sourceTab: tabId, __innervars: { confirmKey: key, sourceTab: tabId, afterFunc: 'checkNextConfirmForm' } },
        type: 'get',
        outtype: 'json',
        trfunc: 'ajaxResponseInspectorForm',
        queue: '',
        failfunc: 'failResponseInspectorForm' });
      hasNext = true;
      break;
    }
    if (!hasNext) {
      if (confirmElems[tabId]) {
        delete confirmElems[tabId];
      }
      EventMgr.trigger('reloadTab', { tabId: tabId });
    }
  }

  function checkNextConfirmForm(e, d) {
    if (d && d.d && d.d.confirmKey && d.d.sourceTab) {
      if (confirmElems[d.d.sourceTab] && confirmElems[d.d.sourceTab][d.d.confirmKey]) {
        delete confirmElems[d.d.sourceTab][d.d.confirmKey];
      }
    }
    openConfirmForm(confirmElems[d.d.sourceTab], d.d.sourceTab);
  }

  function checkForCloseSourceTab(e, d) {
    if (d && d.tabId) {
      if (confirmElems[d.tabId]) {
        delete confirmElems[d.tabId];
        EventMgr.trigger('closeModalForm');
      }
    }
  }

  function init() {
    EventMgr.bind('checkWarningForConfirm', checkWarningForConfirm);
    EventMgr.bind('checkNextConfirmForm', checkNextConfirmForm);
    EventMgr.bind('closeTabEvent', checkForCloseSourceTab);
  }

  var api = {
    init: init
  };

  return api;

} (window, $, EventMgr, App);