mirror of
https://github.com/unraid/webgui.git
synced 2026-05-21 21:59:27 -05:00
repo reorg
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
var pathNum = 2;
|
||||
var portNum = 0;
|
||||
var varNum = 0;
|
||||
var currentPath = "/mnt/";
|
||||
|
||||
if (!String.prototype.format) {
|
||||
String.prototype.format = function() {
|
||||
var args = arguments;
|
||||
return this.replace(/{(\d+)}/g, function(match, number) {
|
||||
return typeof args[number] != 'undefined' ? args[number] : match;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function rmTemplate(tmpl) {
|
||||
var name = tmpl.split(/[\/]+/).pop();
|
||||
swal({title:"Are you sure?",text:"Remove template: "+name,type:"warning",html:true,showCancelButton:true},function(){$("#rmTemplate").val(tmpl);$("#formTemplate").submit();});
|
||||
}
|
||||
|
||||
function toggleBrowser(N) {
|
||||
var el = $('#fileTree' + N);
|
||||
if (el.is(':visible')) {
|
||||
hideBrowser(N);
|
||||
} else {
|
||||
$( el ).fileTree({
|
||||
root: currentPath,
|
||||
filter: 'HIDE_FILES_FILTER'
|
||||
},
|
||||
function(file) {},
|
||||
function(folder) {
|
||||
$("#hostPath" + N).val(folder);
|
||||
});
|
||||
$( el ).slideDown('fast');
|
||||
}
|
||||
}
|
||||
|
||||
function hideBrowser(N) {
|
||||
$("#fileTree" + N).slideUp('fast', function () {
|
||||
$(this).html("");
|
||||
});
|
||||
}
|
||||
|
||||
function addPort(frm) {
|
||||
portNum++;
|
||||
var hostPort = $("#hostPort1");
|
||||
var containerPort = $("#containerPort1");
|
||||
var portProtocol = $("#portProtocol1");
|
||||
|
||||
var select = "";
|
||||
if (portProtocol.val() == "udp"){
|
||||
select = "selected";
|
||||
}
|
||||
|
||||
var row = [
|
||||
'<tr id="portNum{0}" style="display: none;">',
|
||||
'<td>',
|
||||
'<input type="number" min="1" max="65535" name="containerPort[]" value="{2}" class="textPort" title="Set the port your app uses inside the container.">',
|
||||
'</td>',
|
||||
'<td>',
|
||||
'<input type="number" min="1" max="65535" name="hostPort[]" value="{1}" class="textPort" title="Set the port you use to interact with the app.">',
|
||||
'</td>',
|
||||
'<td>',
|
||||
'<select name="portProtocol[]">',
|
||||
'<option value="tcp">tcp</option>',
|
||||
'<option value="udp" {3}>udp</option>',
|
||||
'</select>',
|
||||
'</td>',
|
||||
'<td>',
|
||||
'<input type="button" value="Remove" onclick="removePort({0});">',
|
||||
'</td>',
|
||||
'</tr>'
|
||||
].join('').format(portNum, hostPort.val(), containerPort.val(), select);
|
||||
|
||||
$(row).appendTo('#portRows').fadeIn("fast");
|
||||
hostPort.val('');
|
||||
containerPort.val('');
|
||||
portProtocol.val('tcp');
|
||||
}
|
||||
|
||||
function removePort(rnum) {
|
||||
$('#portNum' + rnum).fadeOut("fast", function() { $(this).remove(); });
|
||||
}
|
||||
|
||||
function addPath(frm) {
|
||||
pathNum++;
|
||||
var hostPath = $("#hostPath1");
|
||||
var containerPath = $("#containerPath1");
|
||||
var hostWritable = $("#hostWritable1");
|
||||
|
||||
var select = "";
|
||||
if (hostWritable.val() == "ro"){
|
||||
select = "selected";
|
||||
}
|
||||
|
||||
var row = [
|
||||
'<tr id="pathNum{0}" style="display: none;">',
|
||||
'<td>',
|
||||
'<input type="text" name="containerPath[]" value="{2}" class="textPath" onclick="hideBrowser({0});" title="The directory your app uses inside the container. Ex: /config">',
|
||||
'</td>',
|
||||
'<td>',
|
||||
'<input type="text" id="hostPath{0}" name="hostPath[]" value="{1}" class="textPath" onclick="toggleBrowser({0});" title="The directory in your array the app have access to. Ex: /mnt/user/Movies"/>',
|
||||
'<div id="fileTree{0}" class="fileTree"></div>',
|
||||
'</td>',
|
||||
'<td>',
|
||||
'<select name="hostWritable[]">',
|
||||
'<option value="rw">Read/Write</option>',
|
||||
'<option value="ro" {3}>Read Only</option>',
|
||||
'</select>',
|
||||
'</td>',
|
||||
'<td>',
|
||||
'<input type="button" value="Remove" onclick="removePath({0});"></td></tr>',
|
||||
'</td>',
|
||||
'</tr>'
|
||||
].join('').format(pathNum, hostPath.val(), containerPath.val(), select);
|
||||
|
||||
$(row).appendTo('#pathRows tbody').fadeIn("fast");
|
||||
hostPath.val('');
|
||||
containerPath.val('');
|
||||
hostWritable.val('rw');
|
||||
}
|
||||
|
||||
function removePath(rnum) {
|
||||
$('#pathNum' + rnum).fadeOut("fast", function() { $(this).remove(); });
|
||||
}
|
||||
|
||||
function addEnv(frm) {
|
||||
varNum++;
|
||||
var VariableName = $("#VariableName1");
|
||||
var VariableValue = $("#VariableValue1");
|
||||
|
||||
var row = [
|
||||
'<tr id="varNum{0}" style="display: none;">',
|
||||
'<td>',
|
||||
'<input type="text" name="VariableName[]" value="{1}" class="textEnv">',
|
||||
'</td>',
|
||||
'<td>',
|
||||
'<input type="text" name="VariableValue[]" value="{2}" class="textEnv">',
|
||||
'<input type="button" value="Remove" onclick="removeEnv({0});">',
|
||||
'</td>',
|
||||
'</tr>'
|
||||
].join('').format(varNum, VariableName.val(), VariableValue.val());
|
||||
|
||||
$(row).appendTo('#envRows tbody').fadeIn("fast");
|
||||
VariableName.val('');
|
||||
VariableValue.val('');
|
||||
}
|
||||
|
||||
function removeEnv(rnum) {
|
||||
$('#varNum' + rnum).fadeOut("fast", function() { $(this).remove(); });
|
||||
}
|
||||
|
||||
function toggleMode(){
|
||||
$("#toggleMode").toggleClass("fa-toggle-off fa-toggle-on");
|
||||
$(".additionalFields").slideToggle();
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
var eventURL = '/plugins/dynamix.docker.manager/include/Events.php';
|
||||
|
||||
function addDockerContainerContext(container, image, template, started, paused, update, autostart, webui, shell, id, Support, Project, Registry, donateLink, ReadMe) {
|
||||
var opts = [];
|
||||
context.settings({right:false,above:false});
|
||||
if (started && !paused) {
|
||||
if (webui !== '' && webui != '#') opts.push({text:_('WebUI'), icon:'fa-globe', href:webui, target:'_blank'});
|
||||
opts.push({text:_('Console'), icon:'fa-terminal', action:function(e){e.preventDefault(); openTerminal('docker',container,shell);}});
|
||||
opts.push({divider:true});
|
||||
}
|
||||
if (update==1) {
|
||||
opts.push({text:_('Update'), icon:'fa-cloud-download', action:function(e){e.preventDefault(); updateContainer(container);}});
|
||||
opts.push({divider:true});
|
||||
}
|
||||
if (started) {
|
||||
if (paused) {
|
||||
opts.push({text:_('Resume'), icon:'fa-play', action:function(e){e.preventDefault(); eventControl({action:'resume', container:id}, 'loadlist');}});
|
||||
} else {
|
||||
opts.push({text:_('Stop'), icon:'fa-stop', action:function(e){e.preventDefault(); eventControl({action:'stop', container:id}, 'loadlist');}});
|
||||
opts.push({text:_('Pause'), icon:'fa-pause', action:function(e){e.preventDefault(); eventControl({action:'pause', container:id}, 'loadlist');}});
|
||||
}
|
||||
opts.push({text:_('Restart'), icon:'fa-refresh', action:function(e){e.preventDefault(); eventControl({action:'restart', container:id}, 'loadlist');}});
|
||||
} else {
|
||||
opts.push({text:_('Start'), icon:'fa-play', action:function(e){e.preventDefault(); eventControl({action:'start', container:id}, 'loadlist');}});
|
||||
}
|
||||
opts.push({divider:true});
|
||||
opts.push({text:_('Logs'), icon:'fa-navicon', action:function(e){e.preventDefault(); openTerminal('docker',container,'.log');}});
|
||||
if (template) {
|
||||
opts.push({text:_('Edit'), icon:'fa-wrench', action:function(e){e.preventDefault(); editContainer(container, template);}});
|
||||
}
|
||||
opts.push({text:_('Remove'), icon:'fa-trash', action:function(e){e.preventDefault(); rmContainer(container, image, id);}});
|
||||
if (ReadMe||Project||Support||Registry) {
|
||||
opts.push({divider:true});
|
||||
}
|
||||
if (ReadMe) {
|
||||
opts.push({text:_('Read Me First'), icon:'fa-book', href:ReadMe, target:'_blank'});
|
||||
}
|
||||
if (Project) {
|
||||
opts.push({text:_('Project Page'), icon:'fa-life-ring', href:Project, target:'_blank'});
|
||||
}
|
||||
if (Support) {
|
||||
opts.push({text:_('Support'), icon:'fa-question', href:Support, target:'_blank'});
|
||||
}
|
||||
if (Registry) {
|
||||
opts.push({text:_('More Info'),icon:'fa-info-circle', href:Registry, target:'_blank'});
|
||||
}
|
||||
if (donateLink) {
|
||||
opts.push({divider:true});
|
||||
opts.push({text:_('Donate'),icon:'fa-external-link', href:donateLink,target:'_blank'});
|
||||
}
|
||||
context.attach('#'+id, opts);
|
||||
}
|
||||
function addDockerImageContext(image, imageTag) {
|
||||
var opts = [];
|
||||
opts.push({text:_('Remove'), icon:'fa-trash', action:function(e){e.preventDefault(); rmImage(image, imageTag);}});
|
||||
context.attach('#'+image, opts);
|
||||
}
|
||||
function popupWithIframe(title, cmd, reload, func) {
|
||||
pauseEvents();
|
||||
$('#iframe-popup').html('<iframe id="myIframe" frameborder="0" scrolling="yes" width="100%" height="99%"></iframe>');
|
||||
$('#iframe-popup').dialog({
|
||||
autoOpen:true,
|
||||
title:title,
|
||||
draggable:true,
|
||||
width: Math.min(Math.max(window.innerWidth/2,900),1600),
|
||||
height: Math.max(window.innerHeight*3/5,600),
|
||||
resizable:true,
|
||||
modal:true,
|
||||
show:{effect:'fade', duration:250},
|
||||
hide:{effect:'fade', duration:250},
|
||||
open:function(ev, ui) {
|
||||
$('#myIframe').attr('src', cmd);
|
||||
},
|
||||
close:function(event, ui) {
|
||||
if (reload && !$('#myIframe').contents().find('#canvas').length) {
|
||||
if (func) setTimeout(func+'()',0); else location = window.location.href;
|
||||
} else {
|
||||
resumeEvents();
|
||||
}
|
||||
}
|
||||
});
|
||||
$(".ui-dialog .ui-dialog-titlebar").addClass('menu');
|
||||
$('.ui-dialog .ui-dialog-titlebar-close').text('X').prop('title',_('Close'));
|
||||
$(".ui-dialog .ui-dialog-title").css({'text-align':'center','width':'100%'});
|
||||
$(".ui-dialog .ui-dialog-content").css({'padding-top':'15px','vertical-align':'bottom'});
|
||||
}
|
||||
function execUpContainer(container) {
|
||||
var title = _('Updating the container')+': '+container;
|
||||
var cmd = '/plugins/dynamix.docker.manager/include/CreateDocker.php?updateContainer=true&ct[]='+encodeURIComponent(container);
|
||||
popupWithIframe(title, cmd, true, 'loadlist');
|
||||
}
|
||||
function addContainer() {
|
||||
var path = location.pathname;
|
||||
var x = path.indexOf('?');
|
||||
if (x!=-1) path = path.substring(0,x);
|
||||
location = path+'/AddContainer';
|
||||
}
|
||||
function editContainer(container, template) {
|
||||
var path = location.pathname;
|
||||
var x = path.indexOf('?');
|
||||
if (x!=-1) path = path.substring(0, x);
|
||||
location = path+'/UpdateContainer?xmlTemplate=edit:'+template;
|
||||
}
|
||||
function updateContainer(container) {
|
||||
swal({
|
||||
title:_('Are you sure?'),text:_('Update container')+': '+container, type:'warning',html:true,showCancelButton:true,closeOnConfirm:false,confirmButtonText:_('Yes, update it!'),cancelButtonText:_('Cancel')
|
||||
},function(){
|
||||
openDocker('update_container '+encodeURIComponent(container),_('Updating the container'),'','loadlist');
|
||||
});
|
||||
}
|
||||
function rmContainer(container, image, id) {
|
||||
var body = _('Remove container')+': '+container+'<br><br><label><input id="removeimagechk" type="checkbox" checked style="display:inline;width:unset;height:unset;margin-top:unset;margin-bottom:unset">'+_('also remove image')+'</label>';
|
||||
$('input[type=button]').prop('disabled',true);
|
||||
swal({
|
||||
title:_('Are you sure?'),text:body,type:'warning',html:true,showCancelButton:true,confirmButtonText:_('Yes, delete it!'),cancelButtonText:_('Cancel'),showLoaderOnConfirm:true
|
||||
},function(c){
|
||||
if (!c) {setTimeout(loadlist); return;}
|
||||
$('div.spinner.fixed').show('slow');
|
||||
if ($('#removeimagechk').prop('checked')) {
|
||||
eventControl({action:'remove_all', container:id, name:container, image:image},'loadlist');
|
||||
} else {
|
||||
eventControl({action:'remove_container', container:id, name:container},'loadlist');
|
||||
}
|
||||
});
|
||||
}
|
||||
function rmImage(image, imageName) {
|
||||
var body = _('Remove image')+': '+$('<textarea />').html(imageName).text();
|
||||
$('input[type=button]').prop('disabled',true);
|
||||
swal({
|
||||
title:_('Are you sure?'),text:body,type:'warning',html:true,showCancelButton:true,confirmButtonText:_('Yes, delete it!'),cancelButtonText:_('Cancel'),showLoaderOnConfirm:true
|
||||
},function(c){
|
||||
if (!c) {setTimeout(loadlist,0); return;}
|
||||
$('div.spinner.fixed').show('slow');
|
||||
eventControl({action:'remove_image', image:image},'loadlist');
|
||||
});
|
||||
}
|
||||
function eventControl(params, spin) {
|
||||
if (spin) $('#'+params['container']).parent().find('i').removeClass('fa-play fa-square fa-pause').addClass('fa-refresh fa-spin');
|
||||
$.post(eventURL, params, function(data) {
|
||||
$('div.spinner.fixed').hide('slow');
|
||||
if (data.success === true) {
|
||||
if (spin) setTimeout(spin+'()',500); else location=window.location.href;
|
||||
} else {
|
||||
setTimeout(function(){
|
||||
swal({
|
||||
title:_('Execution error'),text:data.success,type:'error',html:true,confirmButtonText:_('Ok')
|
||||
},function(){
|
||||
if (spin) setTimeout(spin+'()',500); else location=window.location.href;
|
||||
});
|
||||
},100);
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
function startAll() {
|
||||
$('input[type=button]').prop('disabled',true);
|
||||
for (var i=0,ct; ct=docker[i]; i++) if (ct.state==0) $('#'+ct.id).parent().find('i').removeClass('fa-square').addClass('fa-refresh fa-spin');
|
||||
$.post('/plugins/dynamix.docker.manager/include/ContainerManager.php',{action:'start'},function(){loadlist();});
|
||||
}
|
||||
function stopAll() {
|
||||
$('input[type=button]').prop('disabled',true);
|
||||
for (var i=0,ct; ct=docker[i]; i++) if (ct.state==1) $('#'+ct.id).parent().find('i').removeClass('fa-play fa-pause').addClass('fa-refresh fa-spin');
|
||||
$.post('/plugins/dynamix.docker.manager/include/ContainerManager.php',{action:'stop'},function(){loadlist();});
|
||||
}
|
||||
function pauseAll() {
|
||||
$('input[type=button]').prop('disabled',true);
|
||||
for (var i=0,ct; ct=docker[i]; i++) if (ct.state==1 && ct.pause==0) $('#'+ct.id).parent().find('i').removeClass('fa-play').addClass('fa-refresh fa-spin');
|
||||
$.post('/plugins/dynamix.docker.manager/include/ContainerManager.php',{action:'pause'},function(){loadlist();});
|
||||
}
|
||||
function resumeAll() {
|
||||
$('input[type=button]').prop('disabled',true);
|
||||
for (var i=0,ct; ct=docker[i]; i++) if (ct.state==1 && ct.pause==1) $('#'+ct.id).parent().find('i').removeClass('fa-pause').addClass('fa-refresh fa-spin');
|
||||
$.post('/plugins/dynamix.docker.manager/include/ContainerManager.php',{action:'unpause'},function(){loadlist();});
|
||||
}
|
||||
function checkAll() {
|
||||
$('input[type=button]').prop('disabled',true);
|
||||
$('.updatecolumn').html('<span style="color:#267CA8"><i class="fa fa-refresh fa-spin"></i> '+_('checking')+'...</span>');
|
||||
$.post('/plugins/dynamix.docker.manager/include/DockerUpdate.php',{},function(){loadlist();});
|
||||
}
|
||||
function updateAll() {
|
||||
$('input[type=button]').prop('disabled',true);
|
||||
var ct = [];
|
||||
for (var i=0,d; d=docker[i]; i++) if (d.update==1) ct.push(encodeURIComponent(d.name));
|
||||
openDocker('update_container '+ct.join('*'),_('Updating all Containers'),'','loadlist');
|
||||
}
|
||||
function rebuildAll() {
|
||||
$('input[type=button]').prop('disabled',true);
|
||||
$('div.spinner.fixed').show('slow');
|
||||
var ct = [];
|
||||
for (var i=0,d; d=docker[i]; i++) if (d.update==2) ct.push(encodeURIComponent(d.name));
|
||||
$.get('/plugins/dynamix.docker.manager/include/CreateDocker.php',{updateContainer:true,mute:true,ct},function(){loadlist();});
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user