%PDF- %PDF-
| Direktori : /usr/share/l.v.e-manager/commons/js/ |
| Current File : //usr/share/l.v.e-manager/commons/js/alt-ruby-selector.js |
/**
* Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2019 All Rights Reserved
*
* Licensed under CLOUD LINUX LICENSE AGREEMENT
* http://cloudlinux.com/docs/LICENSE.TXT
*/
(function(win){
var doc = win.document,
project_creator = doc.getElementById('project-create-btn'),
project_path = doc.getElementById('project-path-field'),
project_domain = doc.getElementById('project-domain-field'),
project_uri = doc.getElementById('project-uri-field'),
version_list = doc.getElementById('version-selector'),
project_list = doc.getElementById('project-list');
var uuid = function(){
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
};
var apps = (function(a){
var o = {};
Array.prototype.forEach.call(a, function(i){
var id = uuid();
i.id = id;
o[id] = new Project(id, backend_uri, 'ruby');
o[id].add_hook();
});
return o;
}(doc.getElementsByClassName('app-container')));
var get_app_id = function(el){
if (el.nodeType !== 1) return;
while (el.className !== 'app-container')
el = el.parentNode;
return el.id;
};
project_list.onchange = function(e) {
e = e || win.event;
var tgt = e.target || e.srcElement,
classname = tgt.className,
token = 'app-';
if (classname === '') return;
var pos = classname.indexOf(token);
if (pos !== 0) return;
var item = classname.substring(token.length);
if (item !== 'versionselector')
return;
var id = get_app_id(tgt);
if (id === undefined) return;
apps[id]['versionedit'](tgt, 'ruby');
};
project_list.onclick = function(e){
e = e || win.event;
var tgt = e.target || e.srcElement,
classname = tgt.className,
token = 'app-';
if (classname === '') return;
var regex = new RegExp(token + '([\\w-_]+)'),
actionMatch = classname.match(regex);
if(!actionMatch) {
return;
}
var action = actionMatch[1],
actions = {remove: true, update: true, modexpand: true, modcollapse: true,
modremove: true, modadd: true, pathedit: true, uriedit: true,
wsgiedit: true, reset: true, restart: true, execute: true};
var id = get_app_id(tgt);
if (id === undefined) return;
if (action in actions)
apps[id][action](tgt, 'ruby');
if (action === 'remove')
delete apps[id];
};
doc.documentElement.onclick = function(e){
var popup = doc.getElementById('listpopup'),
style = win.getComputedStyle(popup, null).display;
if (style === 'block' && popup.getAttribute('verCount') == null)
popup.style.display = 'none';
};
project_creator.onclick = function(e){
var path = project_path.value,
uri = project_uri.value || '/',
version = version_list.options[version_list.selectedIndex].firstChild.nodeValue;
if (path === '' || uri === '') {
alert("Project path and uri must be given");
return false;
}
if(!isAllowedText(path) || !isAllowedText(uri)) {
alert("Path or URI contains not allowed symbols");
return false;
}
var id = uuid(),
project = new Project(id, backend_uri, 'ruby');
project.id = id;
project.create(path, uri, version, project_list, 'ruby', project_domain.value);
apps[id] = project;
return true;
};
(function(uri){
var request = new XMLHttpRequest();
request.open("POST", uri);
request.onreadystatechange = function(){
if ( request.readyState === 4 && request.status === 200 ) {
var data = JSON.parse(request.responseText);
if (data['status'] === 'OK') {
modlist = data['data'];
}
}
};
request.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
request.send(encodeFormData({action:'rbmodlist'}));
}(backend_uri));
}(window));