From 979dd225f7a4dc1e55227fbe5959960b6d1c00d3 Mon Sep 17 00:00:00 2001
From: SimonFair <39065407+SimonFair@users.noreply.github.com>
Date: Tue, 16 Jan 2024 19:41:13 +0000
Subject: [PATCH] add support for XML Custom
---
.../templates/XML_Expert.form.php | 58 +++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/emhttp/plugins/dynamix.vm.manager/templates/XML_Expert.form.php b/emhttp/plugins/dynamix.vm.manager/templates/XML_Expert.form.php
index b73ede75a..3162c2d30 100644
--- a/emhttp/plugins/dynamix.vm.manager/templates/XML_Expert.form.php
+++ b/emhttp/plugins/dynamix.vm.manager/templates/XML_Expert.form.php
@@ -22,6 +22,14 @@
require_once "$docroot/webGui/include/Translations.php";
}
+ $templateslocation = "/boot/config/plugins/dynamix.vm.manager/savedtemplates.json";
+
+ if (is_file($templateslocation)){
+ $arrAllTemplates["User-templates"] = "";
+ $ut = json_decode(file_get_contents($templateslocation),true) ;
+ $arrAllTemplates = array_merge($arrAllTemplates, $ut);
+ }
+
$hdrXML = "\n"; // XML encoding declaration
// create new VM
@@ -37,6 +45,15 @@
exit;
}
+
+ // create new VM template
+ if (isset($_POST['createvmtemplate'])) {
+ $reply = addtemplatexml($_POST);
+ echo json_encode($reply);
+ exit;
+ }
+
+
// update existing VM
if (isset($_POST['updatevm'])) {
$uuid = $_POST['domain']['uuid'];
@@ -99,6 +116,9 @@
} ?>
+
+
+
} else { ?>
} ?>
@@ -180,5 +200,43 @@ $(function() {
}
}, "json");
});
+
+ $("#vmform #btnTemplateSubmit").click(function frmSubmit() {
+ var $button = $(this);
+ var $form = $button.closest('form');
+
+ editor.save();
+
+ $form.find('input').prop('disabled', false); // enable all inputs otherwise they wont post
+ $form.append('');
+ var createVmInput = $form.find('input[name="createvm"],input[name="updatevm"]');
+ createVmInput.remove();
+ var postdata = $form.serialize().replace(/'/g,"%27");
+
+ $form.find('input').prop('disabled', true);
+ $button.val($button.attr('busyvalue'));
+ swal({
+ title: _("Template Name")_,
+ text: _("Enter name:\nIf name already exists it will be replaced.")_,
+ type: "input",
+ showCancelButton: true,
+ closeOnConfirm: false,
+ //animation: "slide-from-top",
+ inputPlaceholder: _("Leaving blank will use OS name.")_
+ },
+ function(inputValue){
+ postdata=postdata+"&templatename="+inputValue;
+ $.post("/plugins/dynamix.vm.manager/templates/XML_Expert.form.php", postdata, function( data ) {
+ if (data.success) {
+ done();
+ }
+ if (data.error) {
+ swal({title:"_(VM creation error)_",text:data.error,type:"error",confirmButtonText:"_(Ok)_"});
+ $form.find('input').prop('disabled', false);
+ $button.val($button.attr('readyvalue'));
+ }
+ }, "json");
+ });
+ });
});