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.Stuff.js

//Constructor for tabs
(function(window, $, templates) {
  'use strict';
  function TabObj(id, status, type, selfUrl) {
    this.id = id;
    this.cid = 'cont-' + this.id;
    //this.title = title;
    this.status = status || 0;
    this.type = type;
    this.selfUrl = selfUrl;
    this.body = '';
    this.header = '';
    this.param = '';
    this.sIndex = String(id).replace('tab', '') - 0;
  }

  TabObj.fn = TabObj.prototype;

  TabObj.fn.deactive = function() {
    $('#' + this.id).removeClass('active');
    $('#switch-' + this.id).removeClass('active');
    //$('#s-' + this.id).removeClass('active');
    if (this.hType === 'child') {
      $('#' + this.gParent).removeClass('active');
      $('#switch-' + this.gParent).removeClass('active');
    }
    $('#' + this.cid).removeClass('tab-content_st_active').addClass('hidden');
    this.status = 0;
  };

  TabObj.fn.activate = function() {
    $('#' + this.id).addClass('active');
    $('#switch-' + this.id).addClass('active');
    //$('#s-' + this.id).addClass('active');
    if (this.hType === 'child') {
      $('#' + this.gParent).addClass('active');
    }
    $('#' + this.cid).addClass('tab-content_st_active').removeClass('hidden');
    this.status = 1;
  };
  //render HTML for tabHead and tabBody
  TabObj.fn.render = function() {
    switch (this.type) {
      case 'empty':
        this.htmlBody = templates.tabContEmpty(this.body);
        if (this.hType === 'parent') {
          this.htmlHeader = templates.tabLi(this.header);
        } else {
          this.htmlHeader = templates.tabChld(this.header);
        }
        break;
      case 'list':
        this.htmlBody = templates.tabCont(this.body);
        if (this.hType === 'parent') {
          this.htmlHeader = templates.tabLi(this.header);
        } else {
          this.htmlHeader = templates.tabChld(this.header);
        }
        break;
      case 'form':
        this.htmlBody = templates.tabContForm(this.body); //going replace
        if (this.hType === 'parent') {
          this.htmlHeader = templates.tabLi(this.header);
        } else {
          this.htmlHeader = templates.tabChld(this.header);
        }
        break;
      case 'report':
        this.htmlBody = templates.tabContForm(this.body); //going replace
        if (this.hType === 'parent') {
          this.htmlHeader = templates.tabLi(this.header);
        } else {
          this.htmlHeader = templates.tabChld(this.header);
        }
        break;
      case 'dashboard':
        this.htmlBody = templates.tabContDashBoard(this.body);
        break;
      case 'map':
      case 'rack':
        this.htmlBody = templates.tabContMap(this.body); //going replace
        if (this.hType === 'parent') {
          this.htmlHeader = templates.tabLi(this.header);
        } else {
          this.htmlHeader = templates.tabChld(this.header);
        }
        break;

    }
    return this;
  };
  //append tabBody and tabHead
  TabObj.fn.append = function(tabId) {
    if (this.htmlHeader && this.htmlBody) {
      if (this.hType === 'parent') {
        tabId = tabId || 'add-tab';
        $('#nav-tabs #' + tabId).before(this.htmlHeader);
      } else {
        $('#' + this.gParent).append(this.htmlHeader);
      }
      $('#wr-content').append(this.htmlBody);
    } else if (this.htmlBody) {
      $('#wr-content').append(this.htmlBody);
    }

    return this;
  };
  //replace tabBody
  TabObj.fn.update = function() {
    var body = document.getElementById(this.cid);
    if (body !== null) {
      body.parentNode.removeChild(body);
    }
    $('#wr-content').append(this.htmlBody);
    return this;
  };
  //replace only table
  TabObj.fn.softUpdate = function() {
    var table = document.getElementById('ltwr-' + this.id),
        newTable = '';
    if (table !== null) {
      newTable = '<div class="content" id="ltwr-' + this.id +
          '" data-tabid=' + this.id + '>' + this.body.table + '</div>';
      $(table).replaceWith(newTable);
    }
    return this;
  };
  //replace tabBody and tabHeader
  TabObj.fn.replace = function() {
    var tabHeader = document.getElementById(this.id),
        tabBody = document.getElementById(this.cid);
    if (tabBody !== null) {
      tabBody.parentNode.removeChild(tabBody);
    }
    $('#wr-content').append(this.htmlBody);
    if (tabHeader !== null) {
      $(tabHeader).replaceWith(this.htmlHeader);
    }
    return this;
  };
  //remove temprorary properties
  TabObj.fn.clean = function() {
    this.htmlBody = null;
    this.htmlHeader = null;
    this.header = null;
    this.body = null;
  };
  //close tab
  TabObj.fn.close = function() {
    if (this.chart !== undefined) {
      var myArray = this.chart,
          i = this.chart.length;
      while (i--) {
        if (typeof myArray[i].clearChart === 'function') {
          myArray[i].clearChart();
          myArray[i] = null;
        }
      }
    }
    var header = document.getElementById(this.id),
        body = document.getElementById(this.cid);
    if (header !== null) {
      header.parentNode.removeChild(header);
    }
    if (body !== null) {
      body.parentNode.removeChild(body);
    }
    header = null;
    body = null;
  };

  window.TabObj = TabObj;
  //Constructor for menuGroup
  function MenuGroup(level, id, status, self) {
    this.level = level;
    this.id = id;
    this.status = (status !== null) ? status : '0';
    this.self = self;
  }
  MenuGroup.fn = MenuGroup.prototype;
  //methods
  MenuGroup.fn.statusUp = function(status) {
    this.status = status;
  };

  MenuGroup.fn.activate = function() {
    this.status = '1';
    this.self.removeClass('collapsed');
  };

  MenuGroup.fn.disactivate = function() {
    this.status = '0';
    this.self.addClass('collapsed');
  };

  MenuGroup.fn.toggle = function() {
    if (this.status === '1') {
      this.status = '0';
    } else {
      this.status = '1';
    }
    this.self.toggleClass('collapsed');
  };

  window.MenuGroup = MenuGroup;
  //utilits
  //setCookie
  function setCookie(cName, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var cValue = encodeURIComponent(value) + ((exdays === null) ? '' :
        '; expires=' + exdate.toUTCString());
    document.cookie = cName + '=' + cValue;
  }
  window.setCookie = setCookie;
  //getCookie
  function getCookie(cName) {
    var i, x, y, ARRcookies = document.cookie.split(';');
    for (i = 0; i < ARRcookies.length; i++) {
      x = ARRcookies[i].substr(0, ARRcookies[i].indexOf('='));
      y = ARRcookies[i].substr(ARRcookies[i].indexOf('=') + 1);
      x = x.replace(/^\s+|\s+$/g, '');
      if (x === cName) {
        return decodeURIComponent(y);
      }
    }
    return '';
  }
  window.getCookie = getCookie;
  //jquery !plugins
  $.fn.switchClass = function(added, removed) {
    return this.removeClass(removed).addClass(added);
  };

  $.fn.serializeObject = function() {
    var formArray = this.serializeArray(),
        formObject = {},
        length = formArray.length,
        i;
    for (i = 0; i < length; i++) {
      formObject[formArray[i].name] = formArray[i].value;
    }
    return formObject;
  };
  //get flags from attr data-flag="default|reload"
  $.fn.getFlags = function() {
    var flags = {},
        flagString = this.attr('data-flags'),
        flagStringArr;
    if (flagString) {
      flagStringArr = flagString.split('|');
      for (var i = 0, l = flagStringArr.length; i < l; i++) {
        flags[$.trim(flagStringArr[i])] = true;
      }
    }
    return flags;
  };

  //get vars from attribute data-vars="t:1|r:25"
  $.fn.getVars = function() {
    var vars = {},
        varsString = this.attr('data-vars'),
        varsStringAttr,
        varsStringValue;
    if (varsString) {
      varsStringAttr = String(varsString).split('|');
      for (var i = 0, l = varsStringAttr.length; i < l; i++) {
        varsStringValue = varsStringAttr[i].split(':');
        if (varsStringValue && varsStringValue[0] && varsStringValue[1]) {
          vars[varsStringValue[0]] = varsStringValue[1];
        }
      }
    }
    return vars;
  };

  //@todo remove from all

  function blockEvent(e) {
    e = e || window.event;
    if (e.stopPropagation) {
      e.stopPropagation();
    }
    else {
      e.cancelBubble = true;
    }
    if (e.preventDefault) {
      e.preventDefault();
    }
    else {
      e.returnValue = false;
    }
  }
  window.blockEvent = blockEvent;

  //from here https://github.com/janl/mustache.js/blob/master/mustache.js#L47
  var entityMap = {
    '&': '&amp;',
    '<': '&lt;',
    '>': '&gt;',
    '"': '&quot;',
    "'": '&#39;',
    '/': '&#x2F;',
    '&amp;': '&',
    '&lt;': '<',
    '&gt;': '>' ,
    '&quot;': '"',
    '&#39;': "'" ,
    '&#x2F;': '/'
  };

  function scrollToTopLeft() {
    if (!window.pageInfo.mobile && !window.pageInfo.store && !window.pageInfo.extform) {
      window.scrollTo(0, 0);
    }
  }

  window.scrollToTopLeft = scrollToTopLeft;

  function htmlEscape(string) {
    return String(string).replace(/[&<>"'\/]/g, function(s) {
      return entityMap[s];
    });
  }

  window.htmlEscape = htmlEscape;
  function htmlDecode(value) {
    return $('<div/>').html(value).text();
  }
  window.htmlDecode = htmlDecode;

  function htmlEncode(s) {
    s = String(s).replace(/&lt;/g, '<').replace(/&gt;/g, '>');
    return s;
  }
  window.htmlEncode = htmlEncode;
  function blockSelection() {
    if (window.getSelection) { window.getSelection().removeAllRanges(); }
    //else if (document.selection && document.selection.clear) {
    // document.selection.clear();
    // }
    else if (document.selection && document.selection.empty) {
      document.selection.empty();
    }
  }
  window.blockSelection = blockSelection;
  function hash(input) {
    var hashI = 0, charI, i;
    if (input.length === 0) {
      return hashI;
    }
    for (i = 0; i < input.length; i++) {
      charI = input.charCodeAt(i);
      hashI = ((hashI << 5) - hashI) + charI;
      hashI = hashI & hashI; // Convert to 32bit integer
    }
    return 'id' + hashI;
  }
  window.hash = hash;


  var split;

  // Avoid running twice; that would break the `nativeSplit` reference
  split = window.split || function(undef) {

    var nativeSplit = String.prototype.split,
        // NPCG: nonparticipating capturing group
        compliantExecNpcg = /()??/.exec('')[1] === undef,
        self;

    self = function(str, separator, limit) {
      // If `separator` is not a regex, use `nativeSplit`
      if (Object.prototype.toString.call(separator) !== '[object RegExp]') {
        return nativeSplit.call(str, separator, limit);
      }
      var output = [],
          flags = (separator.ignoreCase ? 'i' : '') +
          (separator.multiline ? 'm' : '') +
          (separator.extended ? 'x' : '') + // Proposed for ES6
          (separator.sticky ? 'y' : ''), // Firefox 3+
          lastLastIndex = 0,
          // Make `global` and avoid `lastIndex` issues by working with a copy
          separator2, match, lastIndex, lastLength;
      separator = new RegExp(separator.source, flags + 'g');
      str += ''; // Type-convert
      if (!compliantExecNpcg) {
        // Doesn't need flags gy, but they don't hurt
        separator2 = new RegExp('^' + separator.source + '$(?!\\s)', flags);
      }

      limit = limit === undef ?
          -1 >>> 0 : // Math.pow(2, 32) - 1
          limit >>> 0; // ToUint32(limit)
      /* jslint boss:true*/
      while (match = separator.exec(str)) {
        // `separator.lastIndex` is not reliable cross-browser
        lastIndex = match.index + match[0].length;
        if (lastIndex > lastLastIndex) {
          output.push(str.slice(lastLastIndex, match.index));
          // Fix browsers whose `exec` methods don't consistently
          // return `undefined` for
          // nonparticipating capturing groups
          /* jslint loopfunc:true*/
          if (!compliantExecNpcg && match.length > 1) {
            match[0].replace(separator2, function() {
              for (var i = 1; i < arguments.length - 2; i++) {
                if (arguments[i] === undef) {
                  match[i] = undef;
                }
              }
            });
          }
          if (match.length > 1 && match.index < str.length) {
            Array.prototype.push.apply(output, match.slice(1));
          }
          lastLength = match[0].length;
          lastLastIndex = lastIndex;
          if (output.length >= limit) {
            break;
          }
        }
        if (separator.lastIndex === match.index) {
          separator.lastIndex++; // Avoid an infinite loop
        }
      }
      if (lastLastIndex === str.length) {
        if (lastLength || !separator.test('')) {
          output.push('');
        }
      } else {
        output.push(str.slice(lastLastIndex));
      }
      return output.length > limit ? output.slice(0, limit) : output;
    };

    // For convenience
    String.prototype.split = function(separator, limit) {
      return self(this, separator, limit);
    };

    return self;

  }();

}(window, $, templates));