Your IP : 18.219.40.177
//context menu
App.ContextMenu = function (window, $, EventMgr, App) {
'use strict';
var init = function() {
EventMgr.on(contentSelector, contextMenuIconSelector, 'mouseover', showMenuContextIcon);
EventMgr.on(contentSelector, contextMenuIconSelector, 'mouseout', hideMenuContextIcon);
EventMgr.on(contentSelector, contextMenuLink, 'click', contextMenuLinkHandler);
EventMgr.obind(contextMenuIconSelector1, 'mouseout', checkHideMenuContextIcon);
EventMgr.obind(contextMenuIconSelector1, 'mouseover', selfShowEditableIcon);
EventMgr.obind(contextMenuIconSelector1, 'click', showMenu);
EventMgr.obind(contextMenuIconSelector1, 'click', showMenu);
EventMgr.bind('listMultiSelect', activateContextLinksGroup);
EventMgr.bind('listSelect', activateContextLinksAll);
EventMgr.bind('listUnSelect', deactivateContextLinksAll);
EventMgr.bind('changedTab', hideMenuContextIcon);
EventMgr.bind('hideContextIcon', hideMenuContextIcon);
},
contextMenuIconSelector1 = '#context-menu-icon',
contentSelector = '#main-wrapper',
contexMenuSelector = '.context-menu',
contextMenuLink = '.context-list a.action, .context-list a.back',
contextMenuIconSelector = '.list_table .data-wrapper.data.key-field',
$$contextMenuIcon = function() {
return App.Dom.byId('context-menu-icon');
},
$$contextMenu = function(tabId) {
return App.Dom.byId('cont-' + tabId + '-context-menu');
},
$$contextMenuWrapper = function() {
return App.Dom.byId('context-menu-wrapper');
},
opened = false,
tabId,
editable = false,
pos = {
left: 0,
top: 0,
width: 0,
elem: null
},
//show icon context menu
selfShowEditableIcon = function() {
//hard hack for show edit icon
if (editable) {
$('#edit-filed-in-list').css('display', 'block');
}
this.style.display = 'block';
},
showId,
//show icon context menu
showMenuContextIcon = function() {
var self = $(this),
tabIdLoc = self.parents('.tab-content').attr('data-tabid');
if (!checkContextMenuItems(tabIdLoc, self)) {
return false;
}
var //self = $(this),
offset = self.offset(),
left = offset.left,
top = offset.top,
width = this.offsetWidth,
contextMenuIconElem = $$contextMenuIcon(),
iconLeftPos = left + width - 22;
//check for editable icon
if (this.className.match('editable')) {
iconLeftPos -= 22;
editable = true;
} else {
editable = false;
}
pos.left = left;
pos.top = top;
pos.width = width;
pos.elem = self;
pos.iLeft = iconLeftPos;
contextMenuIconElem.style.left = iconLeftPos + 'px';
contextMenuIconElem.style.top = top + 'px';
showId = setTimeout(function() {
contextMenuIconElem.style.display = 'block';
}, 200);
//contextMenuIconElem.style.display = 'block';
tabId = tabIdLoc;
},
//check for items in context menu
checkContextMenuItems = function(tabId, self) {
var currentTr = self.parents('tr'),
type = 't1',
t2 = '#tcw-' + tabId + ' .toolbar .img-link.t3',
t1 = '#tcw-' + tabId + ' .toolbar .img-link',
hide, lenBtn, cHide,
show = false,
selecteElems = $('#lt-' + tabId + ' tr.selected');
if (!currentTr.attr('data-elid')) {
return false;
}
if (currentTr.hasClass('selected')) {
if (selecteElems.length > 1) {
type = 't2';
}
}
if (type === 't1') {
hide = currentTr.attr('data-hide');
hide = hide ? ':not("' + hide + '")' : '';
lenBtn = $(t1 + hide).length;
} else {
hide = '';
selecteElems.each(function() {
cHide = this.getAttribute('data-hide');
hide += cHide || '';
});
hide = (hide !== '') ? ':not("' + hide + '")' : '';
lenBtn = $(t2 + hide).length;
}
if (lenBtn > 0) {
show = true;
}
return show;
},
//show context menu
showMenu = function(e) {
hideMenu();
selectListItem(this);
hideToolsep();
var contentMenuElem = $$contextMenu(tabId).cloneNode(true),
contextMenuWrapper = $$contextMenuWrapper();
contextMenuWrapper.appendChild(contentMenuElem);
contentMenuElem.className += ' active ';
var width = contentMenuElem.offsetWidth,
wWidth = window.innerWidth,
left = pos.iLeft + 11,
df = wWidth - (left + width);
contentMenuElem.style.top = pos.top + 11 + "px";
//check for out position
if (df < 0) {
left = pos.left + pos.width - width;
}
contentMenuElem.style.left = left + "px";
opened = true;
EventMgr.on('body', '#main-wrapper', 'click.context', checkForClose);
e.stopPropagation();
},
//check and hide toolsep
hideToolsep = function() {
//hard logic!
var active = false, toolsep = false, prevToolsep, toolseps = [], curToolsep, len;
$('#wrapper #cont-'+ tabId +'-context-menu li').each(function() {
if (this.className.match(/toolsep/)) {
toolsep = true;
if (prevToolsep) {
prevToolsep.bottom = active;
}
curToolsep = {
self : this,
top : active,
bottom : false
};
toolseps.push(curToolsep);
} else {
toolsep = false;
}
if (!this.className.match(/notActive/)) {
if (!active && !toolsep) {active = true;}
if (toolsep) {active = false;}
}
prevToolsep = curToolsep;
});
if (prevToolsep) {
prevToolsep.bottom = active;
}
len = toolseps.length;
for (var i = 0; i < len; i ++) {
if (!toolseps[i].bottom) {
toolseps[i].self.className = toolseps[i].self.className.replace('active', 'notActive');
}
}
},
//handler body click for close menu
checkForClose = function(e) {
var elem = $(e.srcElement);
if (!(elem.hasClass('.context-menu') || (elem.parents('.context-menu').length > 0 ))) {
hideMenu();
hideMenuContextIcon();
}
},
//hide menu function
hideMenu = function() {
EventMgr.off('body', '.context');
var contextMenuWrapper = $$contextMenuWrapper();
while (contextMenuWrapper.hasChildNodes()) {
contextMenuWrapper.removeChild(contextMenuWrapper.lastChild);
}
opened = false;
},
hideId,
//hide icon or not?
checkHideMenuContextIcon = function(e) {
if (e.relatedTarget) {
if (e.relatedTarget.className.match(/\sdata/)) {
return false;
}
}
hideMenuContextIcon();
},
//hide icon context menu
hideMenuContextIcon = function() {
clearTimeout(showId);
var contextMenuIconElem = $$contextMenuIcon();
contextMenuIconElem.style.display = 'none';
$('#edit-filed-in-list').css('display', 'none');
},
//select list line
selectListItem = function() {
var elem = pos.elem,
tr = elem.parents('tr');
if (!tr.hasClass('selected')) {
tr.trigger('click');
}
},
//all context links
$contextLinksAll = function() {
return $('#cont-' + tabId + ' .context-list li');
},
//grouping actions
$contextLinksGroup = function() {
return $('#cont-' + tabId + ' .context-list a.group:not(".back"):not(".new")').parent();
},
//not grouping actions for action
$contextLinksNotGroup = function() {
return $('#cont-' + tabId + ' .context-list a:not(".group"):not(".back"):not(".new"):not(".list")').parent();
},
//not group not formgroup for hidden
$contextLinksNotFormGroup = function() {
return $('#cont-' + tabId + ' .context-list a:not(".group"):not(".groupform"):not(".back"):not(".new"):not(".list")').parent();
},
//show all context links exclude "new" and "back"
deactivateContextLinksAll = function(e) {
$contextLinksNotGroup().switchClass('notActive', 'active');
$contextLinksGroup().switchClass('notActive', 'active');
},
//hide not group context links
activateContextLinksGroup = function() {
$contextLinksNotFormGroup().switchClass('notActive', 'active');
$contextLinksGroup().switchClass('active', 'notActive');
},
//show all context links
activateContextLinksAll = function() {
$contextLinksAll().switchClass('active', 'notActive');
},
//handler for links in context menu
contextMenuLinkHandler = function(e) {
e.preventDefault();
var id = this.getAttribute('data-id');
hideMenuContextIcon();
$('#' + id).trigger('click');
};
return {
init: init
};
}(window, $, EventMgr, App);