| Current Path : /var/www/element/data/www/greenpr.ru/bitrix/js/fileman/medialib/ |
| Current File : /var/www/element/data/www/greenpr.ru/bitrix/js/fileman/medialib/core_admin.js |
function BXMedialibAdmin(oConfig)
{
window.MLItems = {};
this.arCollections = window.MLCollections;
this.arItemsCollList = {};
this.oConfig = oConfig;
this.sessid = this.oConfig.sessid;
this.zIndex = 1000;
this.arItems = {};
this.curColl = this.oConfig.curColl;
this.arExt = this.oConfig.strExt.split(',');
}
BXMedialibAdmin.prototype =
{
OnStart: function()
{
this.pCollCont = document.getElementById('ml_coll_cont');
this.pBread = document.getElementById('ml_breadcrumbs');
this.InitMultiaction();
this.InitContextMenu();
// Build collections
this.BuildCollections();
if (this.arCollections.length <= 0)
document.getElementById('ml_no_colection_notice').style.display = "block";
if (this.curColl > 0)
{
this.SelectCollection(this.curColl, true);
this.OpenCollection(this.curColl);
}
},
BuildCollections: function()
{
this.oCollections = {};
this.arCollectionsTree = [];
var
arCollectionsTemp = [], newAr, it = 0,
i, l = this.arCollections.length;
for (i = 0; i < l; i++)
{
if (!this.BuildCollection(this.arCollections[i], i))
arCollectionsTemp.push([this.arCollections[i], i]);
}
while(arCollectionsTemp.length > 0 && it < 50)
{
l = arCollectionsTemp.length;
newAr = [];
for (i = 0; i < l; i++)
{
if (!this.BuildCollection(arCollectionsTemp[i][0], arCollectionsTemp[i][1]))
newAr.push(arCollectionsTemp[i]);
}
arCollectionsTemp = newAr;
it++;
}
this.bRedrawCollections = true;
},
BuildCollection: function(oCol, ind)
{
var pCont, level, _this = this, parAr;
oCol.parent = parseInt(oCol.parent);
if (!oCol.parent) // Root element
{
pCont = this.pCollCont;
level = 0;
parAr = this.arCollectionsTree;
}
else if (this.oCollections[oCol.parent])
{
pCont = this.oCollections[oCol.parent].pCollsCont;
level = this.oCollections[oCol.parent].level + 1;
this.oCollections[oCol.parent].childCount++;
if (this.oCollections[oCol.parent].childCount == 1)
this.oCollections[oCol.parent].icon.className = 'ml-col-icon-closed';
parAr = this._ReqFindChildCol(this.arCollectionsTree, oCol.parent);
}
else
return false;
parAr.push({id: oCol.id, child: []});
if (pCont)
{
var
titleDiv = jsUtils.CreateElement("DIV", {id : 'ml_coll_title_' + oCol.id}),
img = titleDiv.appendChild(jsUtils.CreateElement("IMG", {src: '/bitrix/images/1.gif', className: 'ml-col-icon'})),
arHideItems = {length: 0},
ch = titleDiv.appendChild(jsUtils.CreateElement("INPUT", {type: 'checkbox', value: 'c_' + oCol.id})),
menuIc = titleDiv.appendChild(jsUtils.CreateElement("IMG", {src: '/bitrix/images/1.gif', className: 'ml-col-menu', id: 'mlccm_' + oCol.id})),
span = titleDiv.appendChild(jsUtils.CreateElement("SPAN")),
childDiv = jsUtils.CreateElement("DIV"),
childTbl = childDiv.appendChild(jsUtils.CreateElement("TABLE"));
itemsTd = childTbl.insertRow(-1).insertCell(-1),
colsTd = childTbl.insertRow(-1).insertCell(-1);
itemsTd.className = 'ml-coll-items-cont';
colsTd.className = 'ml-coll-cols-cont';
childTbl.style.width = "100%";
if (arHideItems.del = !this.UserCan(oCol, 'del'))
arHideItems.length++;
if (arHideItems.edit = !this.UserCan(oCol, 'edit'))
arHideItems.length++;
if (arHideItems.add_col = !this.UserCan(oCol, 'new_col'))
arHideItems.length++;
if (arHideItems.add_item = !this.UserCan(oCol, 'new_item'))
arHideItems.length++;
if (arHideItems.access = !this.UserCan(oCol, 'access'))
arHideItems.length++;
if (arHideItems.length < 5)
{
menuIc.onmouseover = function(){addClassName(this, 'ml-col-menu-over');};
menuIc.onmouseout = function(){removeClassName(this, 'ml-col-menu-over');};
menuIc.onclick = function(e){_this.oColMenu.Show({pElement: this, arHideItems: arHideItems});return jsUtils.PreventDefault(e);};
}
else
{
menuIc.className = 'ml-col-menu ml-col-menu-dis';
}
ch.onclick = function(e)
{
var id = this.value.substr('c_'.length);
if (!this.checked)
{
var col = _this.GetCollection(id);
if (col && col.parent > 0 && _this.oCollections[col.parent])
_this.oCollections[col.parent].pCheck.checked = false;
}
_this.CheckAllCollChild(id, !!this.checked, true);
if(!e) e = window.event;
if(e.stopPropagation)
e.stopPropagation();
else
e.cancelBubble = true;
};
_this._SetColTitleLevel(titleDiv, childDiv, level);
span.innerHTML = oCol.name;
titleDiv.title = bxspcharsback(oCol.desc || oCol.name);
titleDiv.onclick = function(){_this.OpenCollection(this.id.substr('ml_coll_title_'.length), true);};
img.onclick = function(e){_this.OpenCollection(this.parentNode.id.substr('ml_coll_title_'.length), false, true); return jsUtils.PreventDefault(e || window.event);};
pCont.appendChild(titleDiv);
pCont.appendChild(childDiv);
this.oCollections[oCol.id] =
{
ind: ind,
pTitle: titleDiv,
pChildCont: childDiv,
pCollsCont: colsTd,
pItemsCont: itemsTd,
icon: img,
level: level,
childCount: 0,
bOpened: false,
pCheck: ch
};
return true;
}
},
ReNewCollectionTree: function()
{
this.bRedrawCollections = true;
this.arCollectionsTree = [];
var
arTMP = [], newAr, it = 0,
i, l = this.arCollections.length;
for (i = 0; i < l; i++)
{
if (!this.ReNewCol4Tree(this.arCollections[i]))
arTMP.push(this.arCollections[i]);
}
while(arTMP.length > 0 && it < 50)
{
l = arTMP.length;
newAr = [];
for (i = 0; i < l; i++)
{
if (!this.ReNewCol4Tree(arTMP[i]))
newAr.push(arTMP[i]);
}
arTMP = newAr;
it++;
}
},
ReNewCol4Tree: function(oCol)
{
var
parId = parseInt(oCol.parent),
parAr;
if (!parId) // Root element
parAr = this.arCollectionsTree;
else if (this.oCollections[parId])
parAr = this._ReqFindChildCol(this.arCollectionsTree, parId);
if(!parAr)
return false;
parAr.push({id: oCol.id, child: []});
return true;
},
SelectCollection: function(id, bOpenCrumbs)
{
var Col = this.oCollections[id];
if (!Col || this.SelectedColId == id)
return;
this.DeSelectCollection(false);
this.SelectedColId = id;
addClassName(Col.pTitle, 'mlcollt-active');
addClassName(Col.pChildCont, 'mlcollt-active-ch');
var arCrumbs = this.GetCollsCrumbs(id);
this.BuildCrumbs(arCrumbs);
if (bOpenCrumbs) // Open collection sections
{
var i, l = arCrumbs.length;
for(i = 1; i < l; i++)
{
if (!this.oCollections[arCrumbs[i].id].bOpened)
this.OpenCollection(arCrumbs[i].id);
}
}
},
DeSelectCollection: function(bDelCrumbs)
{
if (this.SelectedColId && this.oCollections[this.SelectedColId]) // Deselect
{
removeClassName(this.oCollections[this.SelectedColId].pTitle, 'mlcollt-active');
removeClassName(this.oCollections[this.SelectedColId].pChildCont, 'mlcollt-active-ch');
}
if (bDelCrumbs !== false) // Clean BreadCrumbs
while(this.pBread.childNodes.length > 0)
this.pBread.removeChild(this.pBread.firstChild);
},
UserCan: function(oCol, action)
{
var oAc;
if (typeof oCol !== 'object')
{
if (oCol === 0)
{
oAc = this.oConfig.rootAccess;
}
else
{
oCol = this.GetCollection(oCol);
if (typeof oCol !== 'object' )
return false;
oAc = oCol.access;
}
}
else
{
oAc = oCol.access;
}
return oAc && oAc[action] === '1';
},
GetCollsCrumbs: function(id)
{
var arCrumbs = [], arCol;
while(id)
{
arCol = this.GetCollection(id);
if (arCol)
{
arCrumbs.push(arCol);
id = arCol.parent;
}
else
id = false;
}
return arCrumbs;
},
BuildCrumbs: function(arCrumbs)
{
// Clean
while(this.pBread.childNodes.length > 0)
this.pBread.removeChild(this.pBread.firstChild);
var
_this = this,
coll,
i, l = arCrumbs.length;
for(i = l - 1; i >= 0; i--)
{
coll = arCrumbs[i];
if (!coll || typeof coll != 'object')
continue;
pCr = jsUtils.CreateElement("DIV", {className: 'ml-crumb', id : 'ml_crumb_' + coll.id, title: coll.desc});
pCr.innerHTML = coll.name;
this.pBread.appendChild(pCr);
if (i > 0)
{
// Add separator
this.pBread.appendChild(jsUtils.CreateElement("DIV", {className: 'ml-crumb-sep'})).appendChild(document.createTextNode(' '));
pCr.onclick = function(){_this.SelectCollection(this.id.substr('ml_crumb_'.length));};
}
else
{
pCr.style.cursor = 'default';
}
}
return arCrumbs;
},
GetCollection: function(id)
{
if (this.oCollections[id])
return this.arCollections[this.oCollections[id].ind];
return false;
},
_ReqFindChildCol: function(arr, id)
{
var i, l = arr.length, res = false;
for (i = 0; i < l; i++)
{
if (arr[i].id == id)
{
res = arr[i].child;
break;
}
else if (arr[i].child.length > 0)
{
res = this._ReqFindChildCol(arr[i].child, id);
if (res)
break;
}
}
return res;
},
_ReqBuildCollSelect: function(oSel, arr, level, bClean)
{
if (!level)
level = 0;
var i, l = arr.length, l1 = oSel.options.length, j, html, opt;
if (bClean == true)
{
var ind = 1;
while (oSel.options[ind])
oSel.options[ind] = null;
}
for (i = 0; i < l; i++)
{
col = this.GetCollection(arr[i].id);
if (col)
{
html = '';
for (j = 0; j < level; j++)
html += ' . ';
html += bxspcharsback(col.name);
opt = new Option(html, arr[i].id);
opt.title = bxspcharsback(col.name);
oSel.options.add(opt);
if (arr[i].child.length > 0)
this._ReqBuildCollSelect(oSel, arr[i].child, level + 1);
}
}
this.bRedrawCollections = false;
},
OpenCollection: function(id, bSelect, bClose)
{
var Col = this.oCollections[id];
if (!Col || typeof Col != 'object')
return;
if (!Col.bOpened || !bClose)
{
if(bSelect)
this.SelectCollection(id);
// Show Items
Col.icon.className = 'ml-col-icon ml-col-icon-opened';
Col.pChildCont.style.display = 'block';
if (Col.childCount > 0)
Col.pCollsCont.style.display = 'block';
this.ShowItems(id);
}
else
{
Col.pChildCont.style.display = 'none';
Col.icon.className = 'ml-col-icon ml-col-icon-closed';
}
Col.bOpened = !Col.bOpened;
},
DelCollection: function(id)
{
if (id > 0 && confirm(ML_MESS.DelCollectionConf))
{
var childs = [];
if (this.oCollections[id].childCount > 0)
{
var
arDivs = this.oCollections[id].pChildCont.getElementsByTagName('DIV'),
i, l = arDivs.length, chId;
for (i = 0; i < l; i++)
{
if (arDivs[i].id.substr(0, 14) == 'ml_coll_title_')
{
chId = parseInt(arDivs[i].id.substr(14));
if (chId > 0)
childs.push(chId);
}
}
}
var _this = this;
this.Request({
action: 'del_collection',
postData: {id: id, child_cols: childs},
handler: function()
{
if (window.bx_req_res)
_this.CSDelCollection(id, childs);
}
});
}
},
_IncreaseCollChild: function(id, i)
{
var Col = this.oCollections[id];
if (Col)
{
if (i !== -1) // Increase
{
Col.childCount++;
if (Col.childCount > 0)
Col.icon.className = 'ml-col-icon ' + (Col.bOpened ? 'ml-col-icon-opened' : 'ml-col-icon-closed');
}
else
{
Col.childCount--;
if (Col.childCount <= 0)
Col.icon.className = 'ml-col-icon';
}
}
},
_SetColTitleLevel: function(pTitle, pChild, level)
{
pTitle.className = 'ml-coll-title mlcolllevel-' + (level > 3 ? 3 : level);
pChild.className = 'ml-coll-child-cont mlchlevel-' + (level > 3 ? 3 : level);
if (level >= 3)
pTitle.childNodes[1].className = 'ml-smaller-title';
},
SaveCollection: function()
{
var
D = this.EditCollDialog,
_this = this,
postData =
{
name: D.pName.value,
desc: D.pDesc.value,
keywords: D.pKeys.value,
parent: D.pParent.value
};
// 1. Check name
if(D.pName.value == '')
{
alert(ML_MESS.ColNameError);
D.pName.focus();
return false;
}
if (!D.bNew)
postData.id = D.oCol.id;
this.Request({
action: 'edit_collection',
postData: postData,
handler: function()
{
if (window.bx_req_res !== false)
{
_this.CloseEditCollDialog();
var oCol =
{
id: window.bx_req_res.id,
name: bxhtmlspecialchars(postData.name),
desc: bxhtmlspecialchars(postData.desc),
date: '',
keywords: bxhtmlspecialchars(postData.keywords),
parent: postData.parent,
access: window.bx_req_res.access
};
// Cliend Side
if (D.bNew)
{
var ind = _this.arCollections.length;
if (ind == 0) // Refresh page
return _this.Refresh({curColl: oCol.id});
_this.arCollections.push(oCol);
_this.BuildCollection(oCol, ind);
}
else
{
var
pTitle = _this.oCollections[oCol.id].pTitle,
pChildCont = _this.oCollections[oCol.id].pChildCont,
oldParent = _this.arCollections[_this.oCollections[oCol.id].ind].parent,
newParent = oCol.parent || 0;
if (_this.arCollections[_this.oCollections[oCol.id].ind].parent != newParent) // Move
{
_this._IncreaseCollChild(oldParent, -1);
_this._IncreaseCollChild(newParent);
var pCont = newParent == 0 ? _this.pCollCont : _this.oCollections[newParent].pChildCont;
pCont.appendChild(pTitle);
pCont.appendChild(pChildCont);
var level = newParent == 0 ? 0 : _this.oCollections[newParent].level + 1; // Level padding
_this.oCollections[oCol.id].level = level;
_this._SetColTitleLevel(pTitle, pChildCont, level);
}
_this.arCollections[_this.oCollections[oCol.id].ind] = oCol;
pTitle.childNodes[3].innerHTML = oCol.name;
pTitle.title = bxspcharsback(oCol.desc || oCol.name);
}
_this.ReNewCollectionTree();
_this.SelectCollection(oCol.id);
}
else
{
// TODO: Error message
alert('error');
}
}
});
},
OpenEditCollDialog: function(Params)
{
if (!Params)
Params = {};
if (!this.EditCollDialog)
this.CreateEditCollDialog();
this.EditCollDialog.bNew = !Params.id;
var
zIndex = 600,
D = this.EditCollDialog,
w = jsUtils.GetWindowSize(),
left = parseInt(w.scrollLeft + w.innerWidth / 2 - D.width / 2),
top = parseInt(w.scrollTop + w.innerHeight / 2 - D.height / 2);
if (this.bRedrawCollections)
this._ReqBuildCollSelect(D.pParent, this.arCollectionsTree, 0, true);
D.Overlay.Show({zIndex: zIndex - 10});
D.pWnd.style.zIndex = zIndex;
D.pWnd.style.display = 'block';
if (!D.bNew)
{
var oCol = this.GetCollection(Params.id);
D.pName.value = bxspcharsback(oCol.name);
D.pDesc.value = bxspcharsback(oCol.desc);
D.pKeys.value = bxspcharsback(oCol.keywords);
D.pParent.value = oCol.parent || 0;
this.EditCollDialog.oCol = oCol;
}
else
{
D.pName.value = '';
D.pDesc.value = '';
D.pKeys.value = '';
if (!Params.parentCol && Params.bGetSelCol && this.SelectedColId && this.oCollections[this.SelectedColId])
Params.parentCol = this.SelectedColId;
if (Params.parentCol > 0 && this.UserCan(Params.parentCol, 'new_col'))
D.pParent.value = Params.parentCol;
}
D.pName.onchange(); // Set title
D.pName.focus();
//alert(left+' :: '+top);
jsFloatDiv.Show(this.EditCollDialog.pWnd, left, top);
//return;
jsUtils.addEvent(document, "keypress", window.MlEdColOnKeypress);
},
CreateEditCollDialog: function(Params)
{
var
_this = this,
D = {
width: 360,
height: 220,
pWnd: document.getElementById('mlsd_coll'),
pTitle: document.getElementById('mlsd_coll_title'),
pName: document.getElementById('mlsd_coll_name'),
pDesc: document.getElementById('mlsd_coll_desc'),
pKeys: document.getElementById('mlsd_coll_keywords'),
pParent: document.getElementById('mlsd_coll_parent'),
Overlay: new BXOverlay({id: 'bxml_ed_col_overlay'})
};
D.pName.onkeydown = D.pName.onchange = function()
{
setTimeout(
function(){
var
D = _this.EditCollDialog,
val = bxhtmlspecialchars(D.pName.value),
t1 = D.bNew ? ML_MESS.NewCollection : ML_MESS.Collection;
D.pTitle.title = t1 + (val.length > 0 ? ': ' + D.pName.value : '');
D.pTitle.innerHTML = t1 + (val.length > 0 ? ': ' + val : '');
}, 20);
};
D.pParent.onchange = function()
{
if (!_this.EditCollDialog.bNew && this.value == _this.EditCollDialog.oCol.parent)
return true;
if (_this.EditCollDialog.bNew && !_this.UserCan(parseInt(this.value), 'new_col') ||
!_this.EditCollDialog.bNew && !_this.UserCan(parseInt(this.value), 'edit'))
{
_this._SetFirstAvailableCol();
return alert(ML_MESS.CollAccessDenied3);
}
if (_this.EditCollDialog.oCol)
{
var arCol = _this._ReqFindChildCol(_this.arCollectionsTree, _this.EditCollDialog.oCol.id); // Put parent into child
if (!arCol || _this._ReqFindChildCol(arCol, this.value))
{
alert(ML_MESS.ColLocEr2);
this.value = _this.EditCollDialog.oCol.parent || 0;
return true;
}
}
if (!_this.EditCollDialog.bNew && _this.EditCollDialog.oCol.id == this.value)
{
alert(ML_MESS.ColLocEr);
this.value = _this.EditCollDialog.oCol.parent || 0;
}
};
document.getElementById('mlsd_coll_save').onclick = function(){_this.SaveCollection();};
document.getElementById('mlsd_coll_cancel').onclick = function(){_this.CloseEditCollDialog();};
document.getElementById('mlsd_coll_close').onclick = function(){_this.CloseEditCollDialog();};
this.bRedrawCollections = true;
window.MlEdColOnKeypress = function(e)
{
if(!e) e = window.event
if(e && e.keyCode == 27)
_this.CloseEditCollDialog();
};
D.pWnd.style.width = D.width + 'px';
D.pWnd.style.height = D.height + 'px';
this.EditCollDialog = D;
},
CloseEditCollDialog: function()
{
this.EditCollDialog.pWnd.style.display = 'none';
jsFloatDiv.Close(this.EditCollDialog.pWnd);
this.EditCollDialog.Overlay.Hide();
jsUtils.removeEvent(document, "keypress", window.MlEdColOnKeypress);
},
_SetFirstAvailableCol: function(act)
{
var
D = this.EditCollDialog,
act = D.bNew ? 'new_col' : 'edit',
cid, col, i, l = D.pParent.options.length;
if (!D.bNew && D.oCol.parent)
D.pParent.value = D.oCol.parent;
if (this.oConfig.rootAccess[act])
D.pParent.value = 0;
else
{
for (i = 0; i < l; i++)
{
cid = D.pParent.options[i].value;
col = this.GetCollection(cid);
if (col && col.access && col.access[act])
{
D.pParent.value = cid;
return;
}
}
}
},
ShowItems: function(id)
{
var
_this = this,
arCol = this.GetCollection(id),
arAccess = {edit: this.UserCan(arCol, 'edit_item'), del: this.UserCan(arCol, 'del_item')};
if (typeof MLItems[id] == 'object')
return this.DisplayItems({Items: MLItems[id], id: id, Access: arAccess});
this.Request({
action: 'get_items',
postData: {col_id: id},
handler: function()
{
if (!window.MLItems[id])
return false;
_this.DisplayItems({Items: MLItems[id], id: id, Access: arAccess});
}
});
},
DisplayItems: function(Params)
{
var
id = Params.id,
pCont = this.oCollections[id].pItemsCont;
//this.currentIdShowed = id;
pCont.style.display = 'block';
// Clean
while(pCont.firstChild)
pCont.removeChild(pCont.lastChild);
this.arItems[id] = {};
if (Params.Items && Params.Items.length)
{
var i, l = Params.Items.length, bCheck = false;
if (this.arLoadItems[id])
bCheck = true;
for (i = 0; i < l; i++)
this.DisplayItem({Item: Params.Items[i], pCont: pCont, bCheck: bCheck, id: id, Access: Params.Access});
}
},
DisplayItem: function(Params)
{
var
oItem = Params.Item,
_this = this,
w = this.oConfig.thumbWidth,
h = this.oConfig.thumbHeight,
itemDiv = jsUtils.CreateElement("DIV", {id : 'ml_item_' + oItem.id, className: 'ml-item-cont', title: bxspcharsback(oItem.name)}, {width: (w + 15) + 'px', height: (h + 35) + 'px'}),
ch = itemDiv.appendChild(jsUtils.CreateElement("INPUT", {type: 'checkbox', className: 'item-checkbox', value: Params.id + '|' + oItem.id})),
tmbImg = itemDiv.appendChild(jsUtils.CreateElement("IMG", {src: oItem.thumb_path || '/bitrix/images/1.gif', className: 'ml-item-thumb'})),
titleDiv = itemDiv.appendChild(jsUtils.CreateElement("DIV", {className: 'ml-item-title'}, {width: (w + 8) + 'px'}));
if (!oItem.thumb_path || !oItem.width || !oItem.height)
{
addClassName(tmbImg, 'ml-item-no-thumb');
}
else if (oItem.width < w && oItem.height < h) // Small image
{
var mt = Math.round((h - oItem.height) / 2);
if (mt > 0)
tmbImg.style.marginTop = mt + 'px';
}
else
{
if (oItem.width > oItem.height)
tmbImg.style.width = w + 'px';
else
tmbImg.style.height = h + 'px';
}
titleDiv.appendChild(document.createTextNode(bxspcharsback(oItem.name)));
if (Params.bCheck)
ch.checked = true;
ch.onclick = function()
{
if (!this.checked && _this.oCollections[Params.id])
_this.oCollections[Params.id].pCheck.checked = false;
_this.EnableMultiAction(this.checked || _this.AskAllCheckBoxes());
};
if (Params.Access.edit || Params.Access.del)
{
if (Params.Access.edit)
{
var edit = titleDiv.appendChild(jsUtils.CreateElement("IMG", {src: '/bitrix/images/1.gif', className: 'ml-item-edit', title: ML_MESS.EditItem}));
edit.onclick = function(e)
{
var id = this.parentNode.parentNode.id;
id = id.substr('ml_item_'.length);
_this.GetItemCollList(id, "OpenEditItemDialog", {id: id, colId: Params.id});
return jsUtils.PreventDefault(e || window.event);
};
}
if (Params.Access.del)
{
var del = titleDiv.appendChild(jsUtils.CreateElement("IMG", {src: '/bitrix/images/1.gif', className: 'ml-item-del', title: ML_MESS.DelItem}));
del.onclick = function(e)
{
var id = this.parentNode.parentNode.id;
id = id.substr('ml_item_'.length);
_this.GetItemCollList(id, "DelItem", {id: id, colId: Params.id});
return jsUtils.PreventDefault(e || window.event);
};
}
itemDiv.onmouseover = function(){addClassName(this, 'ml-item-cont-over');};
itemDiv.onmouseout = function(){removeClassName(this, 'ml-item-cont-over');};
}
itemDiv.onclick = function(e)
{
if (!e)
e = window.event;
var targ = e.target || e.srcElement;
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;
if (targ && targ.nodeName && targ.nodeName.toLowerCase() != 'input')
ch.checked = !ch.checked; ch.onclick();
};
itemDiv.ondblclick = function(e)
{
_this.OpenViewItDialog({id: this.id.substr('ml_item_'.length), colId: Params.id, Access: Params.Access});
return jsUtils.PreventDefault(e);
};
this.arItems[Params.id][oItem.id] = {oItem : oItem, pWnd: itemDiv};
Params.pCont.appendChild(itemDiv);
},
OpenViewItDialog: function(Params)
{
if (!this.ViewItDialog)
this.CreateViewItDialog();
var
oItem, i, l,
zIndex = 600,
D = this.ViewItDialog;
if(MLItems[Params.colId])
{
l = MLItems[Params.colId].length;
for (i = 0; i < l; i++)
{
if (MLItems[Params.colId][i].id == Params.id)
{
oItem = MLItems[Params.colId][i];
break;
}
}
}
D.oItem = oItem;
D.colId = Params.colId;
D.pTitle.innerHTML = oItem.name;
this.GetItemCollList(Params.id, "SetItemInfo", oItem) // Fill info panel in callback
D.Overlay.Show({zIndex: zIndex - 10});
D.pWnd.style.zIndex = zIndex;
D.pImg.style.display = 'none';
D.pWnd.style.display = 'block';
// Set Image and resize it and dialog
if (oItem.type == 'image')
{
D.pImg.src = oItem.path;
oItem.width = parseInt(oItem.width);
oItem.height = parseInt(oItem.height);
removeClassName(D.pImg, 'no-thumb-view');
}
else
{
D.pImg.src = '/bitrix/images/1.gif';
addClassName(D.pImg, 'no-thumb-view');
oItem.width = oItem.height = 200;
}
var
pers = 100,
imgW = oItem.width,
imgH = oItem.height,
wh = oItem.width / oItem.height,
maxImgW = D.width - 270,
maxImgH = D.height - 80;
if (parseInt(oItem.width) > maxImgW && wh >= 1)
{
imgW = maxImgW;
imgH = parseInt(imgW / wh);
pers = parseInt((imgW / oItem.width) * 100);
}
else if(parseInt(oItem.height) > maxImgH && wh < 1)
{
imgH = maxImgH;
imgW = parseInt(imgH * wh);
pers = parseInt((imgH / oItem.height) * 100);
}
D.pDel.style.display = Params.Access.del ? 'inline' : 'none';
D.pEdit.style.display = Params.Access.edit ? 'inline' : 'none';
D.pImg.style.width = imgW + 'px';
D.pImg.style.height = imgH + 'px';
D.pImg.title = (pers < 100) ? ML_MESS.Decreased + ': ' + pers + '%' : '';
var
dialogWidth = 270 + imgW,
dialogHeight = 80 + imgH,
w = jsUtils.GetWindowSize(),
left = parseInt(w.scrollLeft + w.innerWidth / 2 - dialogWidth / 2),
top = parseInt(w.scrollTop + w.innerHeight / 2 - dialogHeight / 2);
D.pWnd.style.width = dialogWidth + 'px';
D.pWnd.style.height = dialogHeight + 'px';
D.bOpened = true;
jsFloatDiv.Show(D.pWnd, left, top);
jsUtils.addEvent(document, "keypress", window.MlViewItOnKeypress);
},
CreateViewItDialog: function()
{
var
_this = this,
size = this.GetOptDialogSize(),
D = {
width: size.width,
height: size.height,
pWnd: document.getElementById('mlsd_view_item'),
pTitle: document.getElementById('mlsd_viewit_title'),
pImg: document.getElementById('mlsd_viewit_img'),
pName: document.getElementById('mlvi_info_name'),
pCols: document.getElementById('mlvi_info_colls'),
pKeys: document.getElementById('mlvi_info_keys'),
pDesc: document.getElementById('mlvi_info_desc'),
pDetails: document.getElementById('mlvi_info_details'),
pDel: document.getElementById('mlsd_viewit_del'),
pEdit: document.getElementById('mlsd_viewit_edit'),
Overlay: new BXOverlay({id: 'bxml_viewit_overlay'})
};
document.getElementById('mlsd_viewit_cancel').onclick = function(){_this.CloseViewItDialog();};
document.getElementById('mlsd_viewit_close').onclick = function(){_this.CloseViewItDialog();};
D.pImg.onload = function(){D.pImg.style.display="block";};
D.pImg.onerror = function(){D.pImg.style.display="none";};
D.pDel.onclick = function(e){_this.DelItem({id: _this.ViewItDialog.oItem.id, colId: _this.ViewItDialog.colId});};
D.pEdit.onclick = function(e){_this.CloseViewItDialog(); _this.OpenEditItemDialog({id: _this.ViewItDialog.oItem.id, colId: _this.ViewItDialog.colId});};
window.MlViewItOnKeypress = function(e)
{
if(!e) e = window.event
if(e && e.keyCode == 27)
_this.CloseViewItDialog();
};
this.ViewItDialog = D;
},
CloseViewItDialog: function()
{
this.ViewItDialog.bOpened = false;
this.ViewItDialog.pWnd.style.display = 'none';
jsFloatDiv.Close(this.ViewItDialog.pWnd);
this.ViewItDialog.Overlay.Hide();
jsUtils.removeEvent(document, "keypress", window.MlEdColOnKeypress);
},
SetItemInfo: function(oItem)
{
var
_this = this,
D = this.ViewItDialog,
arCols = this.arItemsCollList[oItem.id],
str = '', i, l = arCols.length, a, oCol;
// Name
D.pName.innerHTML = oItem.name;
// Keywords
if (oItem.keywords.length > 0)
{
D.pKeys.parentNode.className = '';
D.pKeys.innerHTML = oItem.keywords;
D.pKeys.title = bxspcharsback(oItem.keywords);
}
else
{
D.pKeys.parentNode.className = 'ml-info-keys-h';
}
// Description
if (oItem.desc.length > 0)
{
//removeClassName(D.pDesc, 'mlid-scrld');
D.pDesc.innerHTML = oItem.desc.replace(/\n/g, '<br />');
D.pDesc.parentNode.className = '';
}
else
{
D.pDesc.parentNode.className = 'ml-info-desc-h';
}
// Collections
for (i = 0; i < l; i++)
{
oCol = this.GetCollection(arCols[i]);
str += oCol.name + (i != l - 1 ? ', ' : '');
}
D.pCols.innerHTML = str;
var Details = ML_MESS.DateModified + ': ' + oItem.date_mod;
if (oItem.file_size)
Details += '<br />' + ML_MESS.FileSize + ': ' + oItem.file_size;
if (oItem.width && oItem.height)
Details += '<br />' + ML_MESS.ImageSize + ': ' + oItem.width + ' x ' + oItem.height;
D.pDetails.innerHTML = Details;
},
DelItem: function(Params)
{
if (!Params.id)
return;
var
_this = this,
bDisAll = false,
arCols = this.arItemsCollList[Params.id],
i, l = arCols.length, oCol;
for (i = 0; i < l; i++)
{
if (!this.GetCollection(arCols[i]))
{
bDisAll = true;
break;
}
}
if (!Params.mode)
return this.OpenConfirm(
{
text: ML_MESS.DelItConfTxt,
but1: {text: ML_MESS.DelItB1, handler: function(){_this.DelItem({id: Params.id, colId: Params.colId, mode: 'current'})}},
but2: {text: ML_MESS.DelItB2, handler: function(){_this.DelItem({id: Params.id, colId: Params.colId, mode: 'all'})}, disabled: bDisAll}
});
var colId = Params.colId || 0;
this.Request({
action: 'del_item',
postData: {id: Params.id, mode: Params.mode, col_id: colId},
handler: function()
{
if (window.bx_req_res == true)
_this.CSDelItem({id: Params.id, mode: Params.mode, colId: colId});
else if (window.bx_req_res !== false)
return false;
}
});
},
_ChooseKeysCount: function(pk, pp, strKeys, h, bCut)
{
var _this = this;
pk.innerHTML = strKeys;
setTimeout(function()
{
var
kh = parseInt(pp.offsetHeight),
ind = strKeys.lastIndexOf(',');
if(kh > h && ind > 0)
_this._ChooseKeysCount(pk, pp, jsUtils.trim(strKeys.substr(0, ind)), h, true)
else if(bCut)
pk.innerHTML += '...';
}, 1);
},
GetItemCollList: function(id, strCallback, oParam)
{
if (!this.arItemsCollList[id])
{
var _this = this;
this.Request({
action: 'get_item_coll_list',
postData: {id: id},
handler: function()
{
if (!window._ml_items_colls)
return false;
_this.arItemsCollList[id] = [];
for (var i = 0, l = window._ml_items_colls.length; i < l; i++)
_this.arItemsCollList[id].push(window._ml_items_colls[i]);
_this[strCallback](oParam);
}
});
}
else
this[strCallback](oParam);
},
OpenEditItemDialog: function(Params, bFromOnload)
{
if (!this.EditItemDialog)
return this.CreateEditItemDialog(Params);
else if(!bFromOnload)
{
this.EditItemDialog.alreadySubmitted = false;
this.EditItemDialog.alreadyLoaded = false;
this.EditItemDialog.Params = Params || this.EditItemDialog.Params || {};
this.EditItemDialog.pIfrm.src = this.GetRequestUrl('upload_form');
return;
}
var
_this = this,
D = this.EditItemDialog,
id = D.Params.id,
zIndex = 600,
w = jsUtils.GetWindowSize(),
left = parseInt(w.scrollLeft + w.innerWidth / 2 - D.width / 2),
top = parseInt(w.scrollTop + w.innerHeight / 2 - D.height / 2);
D.bNew = !id;
D.Overlay.Show({zIndex: zIndex - 10});
D.pWnd.style.zIndex = zIndex;
D.pWnd.style.display = 'block';
this.EditItemDialog.bShow = true;
D.arColls = {};
if (!D.bNew)
{
var oItem = this.arItems[D.Params.colId][id].oItem;
D.pPCFileCont.style.display = D.pLoadFDLink.style.display = D.pFDFileCont.style.display = D.pLoadPCLink.style.display = 'none';
D.pFNFileCont.style.display = 'block';
D.pChangeFileLink.style.display = 'inline';
D.pChangeFileLinkBack.style.display = 'none';
D.pFileName.innerHTML = oItem.file_name;
this._AddItemsCollections(this.arItemsCollList[id]);
D.pName.value = bxspcharsback(oItem.name);
D.pDesc.value = bxspcharsback(oItem.desc);
D.pKeys.value = bxspcharsback(oItem.keywords);
if (oItem.width && oItem.height)
{
D.pSize.style.display = 'block';
D.pSize.innerHTML = oItem.width + " x " + oItem.height;
}
else
{
D.pSize.style.display = 'none';
}
if (oItem.thumb_path)
{
D.pThumb.src = oItem.thumb_path;
D.pNoPreview.style.display = "none";
if (oItem.width - oItem.height > 0)
D.pThumb.style.width = "146px";
else
D.pThumb.style.height = "136px";
}
D.oItem = oItem;
}
else
{
D.pFNFileCont.style.display = 'none';
D.pChangeFileLink.style.display = 'none';
D.pChangeFileLinkBack.style.display = 'none';
D.pFileName.innerHTML = "";
D.pName.value = '';
D.pDesc.value = '';
D.pKeys.value = '';
D.pSize.style.display = 'none';
if (!D.Params.parentCol && D.Params.bGetSelCol && this.SelectedColId && this.oCollections[this.SelectedColId])
D.Params.parentCol = this.SelectedColId;
if (D.Params.parentCol > 0 && this.UserCan(D.Params.parentCol, 'new_item'))
this._AddItemsCollections([D.Params.parentCol]);
}
D.pName.onchange(); // Set title
jsFloatDiv.Show(D.pWnd, left, top);
window.MlEdItemOnKeypress = function(e)
{
if(!e) e = window.event
if(e && e.keyCode == 27)
_this.CloseEditItemDialog();
};
jsUtils.addEvent(document, "keypress", window.MlEdItemOnKeypress);
},
CreateEditItemDialog: function(Params)
{
var
_this = this,
D = {
Params: Params || false,
width: 420,
height: 340,
pWnd: document.getElementById('mlsd_item'),
pTitle: document.getElementById('mlsd_item_title'),
pIfrm: document.getElementById('mlsd_iframe_upload'),
Overlay: new BXOverlay({id: 'bxml_ed_it_overlay'})
};
D.pIfrm.src = this.GetRequestUrl('upload_form');
var _this = this;
if (jsUtils.IsIE())
D.pIfrm.onreadystatechange = function(){_this.EditItemDialogOnload()};
else
D.pIfrm.onload = function(){_this.EditItemDialogOnload()};
document.getElementById('mlsd_item_cancel').onclick = document.getElementById('mlsd_item_close').onclick = function(){_this.CloseEditItemDialog();};
D.pWnd.style.width = D.width + 'px';
D.pWnd.style.height = D.height + 'px';
this.EditItemDialog = D;
},
EditItemDialogOnload: function(Params)
{
var
_this = this,
D = this.EditItemDialog;
D.pFrameDoc = D.pIfrm.contentDocument || D.pIfrm.contentWindow.document;
D.pName = D.pFrameDoc.getElementById("mlsd_item_name");
if (!D.pName && !this.EditItemDialog.alreadySubmitted) // Result
{
this.EditItemDialog.alreadySubmitted = true;
return setTimeout(function(){_this.CSEditItem(top.bx_req_res, top._ml_items_colls);}, 50);
}
if (this.EditItemDialog.alreadyLoaded || this.EditItemDialog.alreadySubmitted)
return;
this.EditItemDialog.alreadyLoaded = true;
D.pDesc = D.pFrameDoc.getElementById("mlsd_item_desc");
D.pKeys = D.pFrameDoc.getElementById("mlsd_item_keywords");
D.pColSelect = D.pFrameDoc.getElementById("mlsd_coll_sel");
D.pItCollCont = D.pColSelect.parentNode.parentNode;
D.pFNFileCont = D.pFrameDoc.getElementById("mlsd_fname_cont");
D.pPCFileCont = D.pFrameDoc.getElementById("mlsd_load_cont");
D.pFDFileCont = D.pFrameDoc.getElementById("mlsd_select_cont");
D.pLoadFile = D.pFrameDoc.getElementById("ml_load_file");
D.pChangeFileLink = D.pFrameDoc.getElementById("mlsd_fname_change");
D.pChangeFileLinkBack = D.pFrameDoc.getElementById("mlsd_fname_change_back");
D.pLoadPCLink = D.pFrameDoc.getElementById("mlsd_select_pc");
D.pLoadFDLink = D.pFrameDoc.getElementById("mlsd_select_fd");
D.pItemColls = D.pFrameDoc.getElementById('mlsd_item_collections');
D.pFileName = D.pFrameDoc.getElementById("ml_file_name");
D.pId = D.pFrameDoc.getElementById("mlsd_item_id");
D.pNoPreview = D.pFrameDoc.getElementById("mlsd_no_preview");
D.pFileName = D.pFrameDoc.getElementById("ml_file_name");
D.pThumb = D.pFrameDoc.getElementById("mlsd_item_thumb");
D.pSize = D.pFrameDoc.getElementById("mlsd_item_size");
D.pItemPath = D.pFrameDoc.getElementById("mlsd_item_path");
D.pOpenFD = D.pFrameDoc.getElementById("mlsd_open_fd");
D.pSourceType = D.pFrameDoc.getElementById("mlsd_source_type");
D.pSaveBut = document.getElementById('mlsd_item_save');
D.pForm = D.pFrameDoc.forms['ml_item_form'];
D.pItemPath.onchange = D.pLoadFile.onchange = function()
{
var val = this.value;
if (!val || val.length <= 0)
return;
val = val.replace(/\\/g, '/');
val = val.substr(val.lastIndexOf('/') + 1);
D.pName.value = val;
D.pName.onchange();
};
D.pName.onkeydown = D.pName.onchange = function()
{
setTimeout(
function(){
var
D = _this.EditItemDialog,
val = bxhtmlspecialchars(D.pName.value),
t1 = D.bNew ? ML_MESS.NewItem : ML_MESS.Item;
D.pTitle.title = t1 + (val.length > 0 ? ': ' + D.pName.value : '');
D.pTitle.innerHTML = t1 + (val.length > 0 ? ': ' + val : '');
}, 20);
};
D.pLoadFDLink.onclick = function()
{
D.pPCFileCont.style.display = D.pLoadFDLink.style.display = 'none';
D.pFDFileCont.style.display = 'block';
D.pLoadPCLink.style.display = 'inline';
D.pSourceType.value = "FD";
};
D.pLoadPCLink.onclick = function()
{
D.pPCFileCont.style.display = 'block';
D.pLoadFDLink.style.display = 'inline';
D.pFDFileCont.style.display = D.pLoadPCLink.style.display = 'none';
D.pSourceType.value = "PC";
};
D.pChangeFileLink.onclick = function()
{
D.pFNFileCont.style.display = 'none';
D.pChangeFileLink.style.display = 'none';
D.pChangeFileLinkBack.style.display = 'inline';
D.pLoadPCLink.onclick();
};
D.pChangeFileLinkBack.onclick = function()
{
D.pPCFileCont.style.display = D.pLoadFDLink.style.display = D.pFDFileCont.style.display = D.pLoadPCLink.style.display = 'none';
D.pFNFileCont.style.display = 'block';
D.pChangeFileLink.style.display = 'inline';
D.pChangeFileLinkBack.style.display = 'none';
D.pSourceType.value = "N";
};
D.pColSelect.onchange = function(){_this._AddCollToItem(this.value); this.value = 0;};
D.pSaveBut.onclick = function()
{
if (_this.EditItemDialogOnsubmit())
{
D.pForm.submit();
_this.CloseEditItemDialog();
}
};
D.pOpenFD.onclick = window.mlOpenFileDialog;
window.mlOnFileDialogSave = function(name, path, site)
{
var url = (path == '/' ? '' : path) + '/' + name;
D.pItemPath.value = url;
D.pItemPath.focus();
D.pItemPath.select();
};
this._ReqBuildCollSelect(D.pColSelect, this.arCollectionsTree, 0, true);
this.OpenEditItemDialog(false, true);
},
EditItemDialogOnsubmit: function(Params)
{
var
D = this.EditItemDialog,
cid, ar = this.EditItemDialog.arColls, val = '';
for (cid in ar)
if(ar[cid] && typeof ar[cid] == 'object' && ar[cid].pWnd)
val += (val == '' ? '' : ',') + cid;
// 1. Check source
if (D.bNew)
{
var bStop = true, srcVal = D.pSourceType.value == "PC" ? D.pLoadFile.value : D.pItemPath.value;
if (srcVal == '')
alert(ML_MESS.ItSourceError);
else if(!this.CheckFileExt(srcVal))
alert(ML_MESS.ItemExtError);
else
bStop = false;
if (bStop)
{
if (D.pSourceType.value == "PC")
{
D.pLoadPCLink.onclick();
D.pLoadFile.focus();
}
else
{
D.pLoadFDLink.onclick();
D.pItemPath.focus();
}
return false;
}
}
// 2. Check name
if(D.pName.value == '')
{
alert(ML_MESS.ItNameError);
D.pName.focus();
return false;
}
// 3. Check collections
if(val == '')
{
alert(ML_MESS.ItCollsError);
D.pColSelect.focus();
return false;
}
if (!this.EditItemDialog.bNew)
this.EditItemDialog.pId.value = this.EditItemDialog.oItem.id;
this.EditItemDialog.pItemColls.value = val;
return true;
},
CloseEditItemDialog: function()
{
this.EditItemDialog.bShow = false;
this.EditItemDialog.Params = false;
this.EditItemDialog.pWnd.style.display = 'none';
jsFloatDiv.Close(this.EditItemDialog.pWnd);
this.EditItemDialog.Overlay.Hide();
jsUtils.removeEvent(document, "keypress", window.MlEdItemOnKeypress);
},
_AddItemsCollections: function(arColls)
{
var i, l = arColls.length;
for (i = 0; i < l; i++)
this._AddCollToItem(arColls[i]);
},
_AddCollToItem: function(id)
{
if (this.EditItemDialog.arColls[id])
return;
if (this.EditItemDialog.bNew && !this.UserCan(parseInt(id), 'new_item') ||
!this.EditItemDialog.bNew && !this.UserCan(parseInt(id), 'edit_item'))
return alert(ML_MESS.CollAccessDenied4);
var
i, l, _this = this,
oCol = this.GetCollection(id),
pSel = this.EditItemDialog.pColSelect,
pDiv = jsUtils.CreateElement("DIV", {className: 'mlsd-ch-col'}, false, this.EditItemDialog.pFrameDoc),
pSpan = pDiv.appendChild(jsUtils.CreateElement("SPAN", false, false, this.EditItemDialog.pFrameDoc)),
pDel = pDiv.appendChild(jsUtils.CreateElement("IMG", {src: '/bitrix/images/1.gif', className: 'ml-col-del', title: ML_MESS.DelColFromItem, id: 'mlsd_it_' + id}, false, this.EditItemDialog.pFrameDoc));
pSpan.innerHTML = oCol.name;
this.EditItemDialog.pItCollCont.onmouseover = function(e){};
this.EditItemDialog.pItCollCont.onmouseout = function(e){};
pDiv.onmouseover = function(e){addClassName(this, 'col-over');};
pDiv.onmouseout = function(e){parent.removeClassName(this, 'col-over');};
pDel.onclick = function(e)
{
var cid = this.id.substr('mlsd_it_'.length);
_this.EditItemDialog.pItCollCont.removeChild(_this.EditItemDialog.arColls[cid].pWnd);
_this._SelectOptionInColList(_this.EditItemDialog.pColSelect, cid, false);
_this.EditItemDialog.arColls[cid] = null;
};
this.EditItemDialog.pItCollCont.insertBefore(pDiv, pSel.parentNode);
_this._SelectOptionInColList(pSel, id);
this.EditItemDialog.arColls[id] = {pWnd : pDiv};
},
_SelectOptionInColList: function(pSel, val, bSel)
{
for (var i = 0, l = pSel.options.length; i < l; i++)
{
if (pSel.options[i].value == val)
{
pSel.options[i].className = (bSel !== false) ? 'opt-checked' : '';
pSel.options[i].title = (bSel !== false) ? ML_MESS.CheckedColTitle : '';
break;
}
}
},
GetRequestUrl: function(action, sessid)
{
return '/bitrix/admin/fileman_medialib.php?sessid=' + (sessid || this.sessid) + '&lang=' + this.oConfig.lang + (action ? '&action=' + action : '');
},
CheckReqLostSessid: function(result)
{
var
LSS = 'BX_ML_DUBLICATE_ACTION_REQUEST',
LSSIndex = result.indexOf(LSS);
if (LSSIndex == -1)
return true;
this.sessid = result.substring(LSSIndex + LSS.length, result.lastIndexOf('-->'));
return this.sessid;
},
Request : function(P)
{
this.ShowWaitWindow();
var
_this = this, iter = 0,
q = new JCHttpRequest();
q.Action = function(result)
{
var handleRes = function()
{
_this.CloseWaitWindow();
if (result.indexOf('BX_ML_LOAD_OK') == -1)
return alert(ML_MESS.AccessDenied);
var new_sess = _this.CheckReqLostSessid(result);
if (new_sess !== true)
{
if (P.bRequestReply)
alert(ML_MESS.SessExpired);
else
{
P.bRequestReply = true;
setTimeout(function(){_this.Request(P);}, 50);
}
return;
}
var res = P.handler(result);
if(res === false && ++iter < 20)
setTimeout(handleRes, 3);
};
setTimeout(handleRes, 10);
};
window.bx_req_res = false;
q.Post(this.GetRequestUrl(P.action), P.postData ? ConvertArray2Post(P.postData) : '');
},
ShowWaitWindow: function()
{
if (window.ShowWaitWindow)
ShowWaitWindow();
},
CloseWaitWindow: function()
{
if (window.CloseWaitWindow)
CloseWaitWindow();
},
OpenConfirm: function(Params)
{
var
w = Params.width || 550,
h = Params.height || 100,
//zIndex = Params.zIndex || this.zIndex + 100;
zIndex = 700,
_this = this;
if (!this.Confirm)
{
var D = {
pWnd: document.getElementById('ml_colfirm_dialog'),
pText: document.getElementById('ml_confd_text'),
but1: document.getElementById('ml_confd_b1'),
but2: document.getElementById('ml_confd_b2'),
butCancel: document.getElementById('ml_confd_cancel'),
Overlay: new BXOverlay({id: 'bxml_conf_overlay', parCont: document.getElementById('ml_colfirm_dialog').parentNode})
};
D.butCancel.onclick = function(){_this.CloseConfirm();};
}
else
{
var D = this.Confirm;
}
D.pWnd.style.width = w + 'px';
D.pWnd.style.height = h + 'px';
D.pWnd.style.zIndex = zIndex;
D.pWnd.style.display = 'block';
D.Overlay.Show({zIndex: zIndex - 10, clickCallback:{func:this.CloseConfirm, obj: this}});
var
ws = jsUtils.GetWindowSize(),
left = parseInt(ws.scrollLeft + ws.innerWidth / 2 - w / 2),
top = parseInt(ws.scrollTop + ws.innerHeight / 2 - h / 2);
jsFloatDiv.Show(D.pWnd, left, top, 0);
//But 1
D.but1.value = Params.but1.text;
D.but1.onclick = function(e){Params.but1.handler(e);_this.CloseConfirm();}
D.but1.disabled = !!Params.but1.disabled;
D.but1.focus();
if (Params.but2)
{
D.but2.style.display = 'inline';
D.but2.value = Params.but2.text;
D.but2.disabled = !!Params.but2.disabled;
D.but2.onclick = function(e){Params.but2.handler(e);_this.CloseConfirm();}
}
else
{
D.but2.style.display = 'none';
}
D.pText.innerHTML = Params.text;
this.Confirm = D;
window.MlConfDialofOnKeypress = function(e)
{
if(!e) e = window.event
if(e && e.keyCode == 27)
_this.CloseConfirm();
};
jsUtils.addEvent(document, "keypress", window.MlConfDialofOnKeypress);
},
CloseConfirm: function()
{
//this.bShow = false;
this.Confirm.pWnd.style.display = 'none';
jsFloatDiv.Close(this.Confirm.pWnd);
this.Confirm.Overlay.Hide();
jsUtils.removeEvent(document, "keypress", window.MlConfDialofOnKeypress);
},
SaveSettings: function()
{
if (this.width && this.height)
{
this.userSettings.width = this.width;
this.userSettings.height = this.height;
}
this.Request({
action: 'save_settings',
postData: this.userSettings,
handler: function(){}
});
},
CSDelCollection: function(id, childs)
{
var C = this.oCollections[id];
if (C)
{
var col = this.GetCollection(id);
if (childs !== false && typeof col == 'object' && col.parent > 0)
this._IncreaseCollChild(parseInt(col.parent), -1);
if (this.SelectedColId && this.SelectedColId == id)
this.DeSelectCollection();
//1. Del from array
this.arCollections = deleteFromArray(this.arCollections, C.ind);
// Del from list
if (C.pChildCont.parentNode)
C.pChildCont.parentNode.removeChild(C.pChildCont);
if (C.pTitle.parentNode)
C.pTitle.parentNode.removeChild(C.pTitle);
// Del from obj
this.oCollections[id] = null;
if (childs)
{
for (var i = 0, l = childs.length; i < l; i++)
this.CSDelCollection(childs[i], false);
}
if (childs !== false)
this.ReNewCollectionTree();
}
},
CSDelItem: function(Params)
{
var
colId = parseInt(Params.colId),
id = Params.id,
Item = this.arItems[colId][parseInt(id)],
arCols = [];
if (!Item)
return;
if (this.ViewItDialog && this.ViewItDialog.bOpened)
this.CloseViewItDialog();
if (Params.mode == 'current')
{
arCols.push(colId);
this.arItemsCollList[id] = false;
}
else
{
if (!this.arItemsCollList[id])
return this.GetItemCollList(id, "CSDelItem", Params);
arCols = this.arItemsCollList[id];
}
// Del from collections
var i, l = arCols.length, n, j, el, col;
for (i = 0; i < l; i++)
{
if(MLItems[arCols[i]])
{
n = MLItems[arCols[i]].length;
for (j = 0; j < n; j++)
{
el = MLItems[arCols[i]][j];
if (el.id == id)
{
MLItems[arCols[i]] = deleteFromArray(MLItems[arCols[i]], j);
break;
}
}
this.ShowItems(arCols[i]);
}
}
},
CSEditItem: function(arItem, arColls)
{
if (!arItem)
return alert(ML_MESS.EditItemError);
var
i, l = arColls.length,
id = arItem.id, ind,
oldColls = this.arItemsCollList[id] || [],
l2 = oldColls.length,
used = {};
if (oldColls.length > 0)
{
ind = this.FindItem(oldColls[0], id)
if (ind !== false)
arItem = this._MergeItemInfo(MLItems[oldColls[0]][ind], arItem);
}
for (i = 0; i < l; i++)
{
if (MLItems[arColls[i]])
{
ind = this.FindItem(arColls[i], id);
if (ind === false)
MLItems[arColls[i]].push(arItem);
else
MLItems[arColls[i]][ind] = arItem;
used[arColls[i]] = true;
}
}
for (i = 0; i < l2; i++)
{
if(!used[oldColls[i]])
{
ind = this.FindItem(oldColls[i], id);
if (ind !== false)
{
MLItems[oldColls[i]] = deleteFromArray(MLItems[oldColls[i]], ind);
this.ShowItems(oldColls[i]);
}
}
}
this.arItemsCollList[id] = arColls;
for (i = 0; i < l; i++)
this.ShowItems(arColls[i]);
},
_MergeItemInfo: function(ar1, ar2)
{
if (typeof ar1 == 'object' && typeof ar2 == 'object')
{
for (var i in ar2)
{
if (ar2[i] && (ar2[i].length > 0 || ar2[i] > 0))
ar1[i] = ar2[i];
}
}
return ar1;
},
FindItem: function(colId, itemId)
{
if (MLItems[colId] && typeof MLItems[colId] == 'object' && MLItems[colId].length > 0)
{
var i, l = MLItems[colId].length;
for (i = 0; i < l; i++)
{
el = MLItems[colId][i];
if (el && el.id == itemId)
return i;
}
}
return false;
},
InitMultiaction: function()
{
var _this = this;
this.pMultiActCont = document.getElementById('ml_multiaction_cnt');
if (!this.pMultiActCont)
return;
this.pCheckAll = document.getElementById('ml_action_target');
this.arLoadItems = {};
this.pDelBut = document.getElementById('action_delete_button');
this.pCheckAll.onclick = function()
{
var
bCheck = !!this.checked,
arChecks = _this.pCollCont.getElementsByTagName('INPUT'),
i, l = arChecks.length;
for (i = 0; i < l; i++)
if (arChecks[i].type == 'checkbox')
arChecks[i].checked = bCheck;
_this.EnableMultiAction(bCheck);
_this.arLoadItems = {};
if (bCheck)
for (i = 0, l = _this.arCollections.length; i < l; i++)
_this.arLoadItems[_this.arCollections[i].id] = true;
};
this.pDelBut.onclick = function()
{
if (!_this.bMultiActEnabled || !confirm(ML_MESS.MultiDelConfirm))
return;
var Res = _this.MultiActGetSelected();
_this.Request({
action: 'multi_del',
postData: {
cols: Res.Colls,
items: Res.Items
},
handler: function()
{
_this.Refresh({curColl: _this.SelectedColId});
}
});
};
},
AskAllCheckBoxes: function()
{
var
arChecks = this.pCollCont.getElementsByTagName('INPUT'),
i, l = arChecks.length;
for (i = 0; i < l; i++)
if (arChecks[i].type == 'checkbox' && arChecks[i].checked)
return true;
return false;
},
EnableMultiAction: function(bEnable)
{
this.bMultiActEnabled = bEnable;
if (bEnable)
removeClassName(this.pMultiActCont, "multi-dis");
else
addClassName(this.pMultiActCont, "multi-dis");
},
CheckAllCollChild: function(colId, bCheck, bRoot)
{
var
oCol = this.oCollections[colId],
col,
i, l = this.arCollections.length;
oCol.pCheck.checked = bCheck;
if (bRoot)
{
this.arMultiSelect = {
Cols: [colId],
Items:[],
NotLoadedItems:[]
};
}
if (oCol.childCount > 0) //Subcollections
{
for (i = 0; i < l; i++)
{
col = this.arCollections[i];
if (col.parent == colId)
this.CheckAllCollChild(col.id, bCheck);
}
}
if (typeof MLItems[colId] == 'undefined') // Items not loaded
{
if (bCheck)
{
this.arLoadItems[colId] = true;
//this.arMultiSelect.NotLoadedItems.push(colId);
}
else
this.arLoadItems[colId] = false;
}
else if (typeof MLItems[colId] == 'object' && MLItems[colId].length > 0)
{
var
arChecks = oCol.pChildCont.getElementsByTagName('INPUT'),
l1 = arChecks.length;
for (i = 0; i < l1; i++)
if (arChecks[i].type == 'checkbox')
arChecks[i].checked = bCheck;
}
if (bRoot)
this.EnableMultiAction(bCheck || this.AskAllCheckBoxes());
},
MultiActGetSelected: function()
{
var
arSelCols = [], arSelItems = {},
arChecks = this.pCollCont.getElementsByTagName('INPUT'),
i, l = arChecks.length, val, sep, cid, eid;
for (i = 0; i < l; i++)
{
if (arChecks[i].type == 'checkbox' && arChecks[i].checked)
{
val = arChecks[i].value;
if (val.indexOf('c_') != -1) // Collection
{
arSelCols.push(val.substr(2));
continue;
}
sep = val.indexOf('|');
if (sep != -1)
{
cid = val.substr(0, sep);
eid = val.substr(sep + 1);
if (!arSelItems[cid])
arSelItems[cid] = [];
arSelItems[cid].push(eid); // Items
}
}
}
return {Colls: arSelCols, Items: arSelItems};
},
InitContextMenu: function()
{
var _this = this;
var arMenuColl =
[
{id: 'edit', name: ML_MESS.Edit, title: ML_MESS.EditCollection, handler: function(pEl){_this.OpenEditCollDialog({id: pEl.id.substr('mlccm_'.length)});}},
{id: 'del', name: ML_MESS.Delete,title: ML_MESS.DelCollection,handler: function(pEl){_this.DelCollection(pEl.id.substr('mlccm_'.length));}},
{id: 'access', name: ML_MESS.Access,title: ML_MESS.AccessTitle,handler: function(pEl){window.location = "/bitrix/admin/fileman_medialib_access.php?col_id=" + pEl.id.substr('mlccm_'.length);}},
{id: 'add_item', name: ML_MESS.AddElement,title: ML_MESS.AddElementTitle, handler: function(pEl){_this.OpenEditItemDialog({parentCol: pEl.id.substr('mlccm_'.length)});}},
{id: 'add_col', name: ML_MESS.AddCollection,title: ML_MESS.AddCollectionTitle,handler: function(pEl){_this.OpenEditCollDialog({parentCol: pEl.id.substr('mlccm_'.length)});}}
];
this.ClearOverlay = new BXOverlay({id: 'bx_clear', className: 'bx-clear-overlay'});
this.oColMenu = new MLContextMenu({id: 'coll', Items: arMenuColl, Overlay: this.ClearOverlay, cmPushed: 'ml-col-menu-pushed'});
//this.oItemMenu = new MLContextMenu({id: 'item'});
},
GetOptDialogSize: function(Params)
{
if (!Params)
Params = {};
var
minw = Params.minw || 600,
maxw = Params.maxw || 1024,
s = jsUtils.GetWindowSize(),
w = s.innerWidth - 100;
if (w > maxw)
w = maxw;
if (w < minw)
w = minw;
var h = Math.round(w / 1.61803399);
return {width: w, height: h};
},
Refresh: function(Params)
{
var
curColl = parseInt(Params.curColl),
strLoc = window.location.toString();
if (curColl > 0)
{
if (strLoc.indexOf('cur_col=') != -1)
strLoc = strLoc.replace(/(cur_col=)(\d)+/g, '$1' + curColl);
else
strLoc += (strLoc.indexOf('?') == -1 ? '?' : '&') + 'cur_col=' + curColl;
}
window.location = strLoc;
},
CheckFileExt: function(ext)
{
ext = ext.substr(ext.lastIndexOf('.') + 1);
ext = ext.toLowerCase();
for (var i = 0, l = this.arExt.length; i < l; i++)
if (this.arExt[i] == ext)
return true;
return false;
}
}
function BXOverlay(arParams)
{
this.id = arParams.id || 'bx_trans_overlay';
this.zIndex = arParams.zIndex || 500;
this.className = arParams.className || "bx-trans-overlay";
this.pParentCont = arParams.parCont || document.body;
//this.pParentCont = document.body;
}
BXOverlay.prototype = {
Create: function ()
{
this.bCreated = true;
this.bShowed = false;
var windowSize = jsUtils.GetWindowScrollSize();
this.pWnd = this.pParentCont.appendChild(jsUtils.CreateElement("DIV", {id: this.id, className: this.className}, {zIndex: this.zIndex, width: windowSize.scrollWidth + "px", height: windowSize.scrollHeight + "px"}));
var _this = this;
window[this.id + '_resize'] = function(){_this.Resize();};
this.pWnd.ondrag = jsUtils.False;
this.pWnd.onselectstart = jsUtils.False;
},
Show: function(arParams)
{
if (!this.bCreated)
this.Create();
this.bShowed = true;
var windowSize = jsUtils.GetWindowScrollSize();
this.pWnd.style.display = 'block';
this.pWnd.style.width = windowSize.scrollWidth + "px";
this.pWnd.style.height = windowSize.scrollHeight + "px";
if (!arParams)
arParams = {};
if (arParams.clickCallback)
{
this.pWnd.onclick = function(e)
{
var
clbck = arParams.clickCallback,
p = clbck.params || [];
if (clbck.obj)
clbck.func.apply(clbck.obj, p);
else
clbck.func(p);
return jsUtils.PreventDefault(e);
};
}
if (arParams.zIndex)
this.pWnd.style.zIndex = arParams.zIndex;
jsUtils.addEvent(window, "resize", window[this.id + '_resize']);
return this.pWnd;
},
Hide: function ()
{
if (!this.bShowed)
return;
this.bShowed = false;
this.pWnd.style.display = 'none';
jsUtils.removeEvent(window, "resize", window[this.id + '_resize']);
this.pWnd.onclick = null;
},
Resize: function ()
{
if (this.bCreated)
this.pWnd.style.width = jsUtils.GetWindowScrollSize().scrollWidth + "px";
}
};
// CONTEXT MENU FOR EDITING AREA
function MLContextMenu(arParams)
{
this.Items = arParams.Items;
this.oOverlay = arParams.Overlay;
this.zIndex = arParams.zIndex || 600;
this.id = arParams.id || 'menu';
this.cmPushed = arParams.cmPushed;
this.PreCreate();
}
MLContextMenu.prototype =
{
PreCreate: function()
{
this.pref = 'ML_' + this.id + '_';
this.oDiv = document.body.appendChild(jsUtils.CreateElement('DIV', {className: 'bx-cm', id: this.pref + '_cont'}, {zIndex: this.zIndex}));
this.oDiv.innerHTML = '<table><tr><td class="bxcm-popup"><table id="' + this.pref + '_cont_items"><tr><td></td></tr></table></td></tr></table>';
// Part of logic of JCFloatDiv.Show() Prevent bogus rerendering window in IE... And SpeedUp first context menu calling
document.body.appendChild(jsUtils.CreateElement('IFRAME',{id: this.pref + '_frame', src: "javascript:void(0)"}, {position: 'absolute', zIndex: this.zIndex - 5, left: '-1000px', top: '-1000px', visibility: 'hidden'}));
this.menu = new PopupMenu(this.pref + '_cont');
},
Create: function()
{
this.BuildItems();
this.bCreated = true;
},
Show: function(Params)
{
if (!this.bCreated)
this.Create();
this.oDiv.style.width = parseInt(this.oDiv.firstChild.offsetWidth) + 'px';
this.pElement = Params.pElement;
var
pos = jsUtils.GetRealPos(this.pElement),
_this = this,
w = parseInt(this.oDiv.offsetWidth),
h = parseInt(this.oDiv.offsetHeight),
pOverlay = this.oOverlay.Show();
if (this.cmPushed)
addClassName(this.pElement, this.cmPushed);
if (Params.arHideItems.length > 0)
{
var i, n = this.Items.length;
for(i = 0; i < n; i++)
{
if (typeof this.Items[i] == 'object')
this.Items[i].pWnd.style.display = Params.arHideItems[this.Items[i].id] ? 'none' : (jsUtils.IsIE() ? 'inline' : 'table-cell');
}
}
pOverlay.onclick = function(){_this.Close()};
window.overlay_keypress = function(e){_this.OnKeyPress(e);};
jsUtils.addEvent(window, "keypress", window.overlay_keypress);
pos.top += 2;
pos.left += 1;
this.menu.PopupShow(pos);
},
Close: function()
{
this.menu.PopupHide();
this.oOverlay.Hide();
if (this.cmPushed)
removeClassName(this.pElement, this.cmPushed);
jsUtils.removeEvent(window, "keypress", window.overlay_keypress);
},
BuildItems: function()
{
var
contTbl = document.getElementById(this.pref + '_cont_items'),
n = this.Items.length;
_this = this;
var i, cell, oItem;
//Creation menu elements
for(i = 0; i < n; i++)
{
oItem = this.Items[i];
cell = contTbl.insertRow(-1).insertCell(-1);
if(oItem == 'separator')
{
cell.innerHTML = '<div class="popupseparator"></div>';
}
else
{
cell.innerHTML =
'<table class="popupitem" id="bx_cm_' + oItem.id + '"><tr><td class="gutter"><div class="bx-button" id="bx_btn_' + oItem.id + '" ></div></td><td class="item">' + oItem.name + '</td></tr></table>';
var oTable = cell.firstChild;
oTable.onmouseover = function(e){this.className='popupitem popupitemover';}
oTable.onmouseout = function(e){this.className = 'popupitem';};
oTable.onclick = function(e){_this.OnClick(this);};
oItem.pWnd = cell;
}
}
this.oDiv.style.width = contTbl.parentNode.offsetWidth;
return true;
},
OnClick: function(pEl)
{
var i, n = this.Items.length, act = pEl.id.substring('bx_cm_'.length);
this.Close();
for(i = 0; i < n; i++)
if (this.Items[i].id == act && this.Items[i].handler)
return this.Items[i].handler(this.pElement);
},
OnKeyPress: function(e)
{
if(!e) e = window.event
if(e.keyCode == 27)
this.Close();
}
}
window.addClassName = function(el, cn)
{
if (el.className.indexOf(cn) == -1)
el.className += ' ' + cn;
}
window.removeClassName =function(el, cn)
{
if (typeof el == 'object' && el.className && el.className.indexOf(cn) != -1)
{
var ecm = el.className;
ecm = ecm.replace(cn, '').replace(' ', ' ');
el.className = ecm;
}
}
window.deleteFromArray =function(ar, ind)
{
return ar.slice(0, ind).concat(ar.slice(ind + 1));
}
window.bxhtmlspecialchars = function(str)
{
if(!str.replace)
return str;
str = str.replace(/&/g, '&');
str = str.replace(/"/g, '"');
str = str.replace(/</g, '<');
str = str.replace(/>/g, '>');
return str;
}
window.bxspcharsback = function(str)
{
if(!(typeof(str) == "string" || str instanceof String))
return str;
str = str.replace(/\"/g, '"');
str = str.replace(/'/g, "'");
str = str.replace(/\</g, '<');
str = str.replace(/\>/g, '>');
str = str.replace(/\!/g, '!');
str = str.replace(/\$/g, '$');
str = str.replace(/\%/g, '%');
str = str.replace(/\~/g, '~');
str = str.replace(/\ /g, ' ');
str = str.replace(/\#/g, '#');
str = str.replace(/\&/g, '&');
return str;
}
window.ConvertArray2Post = function(arData, prefix)
{
var data = '', i, name;
if (null != arData)
{
for(i in arData)
{
if (data.length > 0) data += '&';
name = jsUtils.urlencode(i);
if(prefix)
name = prefix + '[' + name + ']';
if(typeof arData[i] == 'object')
data += ConvertArray2Post(arData[i], name)
else
data += name + '=' + jsUtils.urlencode(arData[i])
}
}
return data;
}