Add ability to create new machines in app
This commit is contained in:
parent
d8af366494
commit
2dc370faed
@ -97,6 +97,71 @@ function machineEditorOpenAsync(routeTo, routeFrom, resolve, reject) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function newMachineEditorOpenAsync(routeTo, routeFrom, resolve, reject) {
|
||||||
|
app.dialog.preloader("Loading editor...");
|
||||||
|
|
||||||
|
apirequest(
|
||||||
|
"getmachineformfields",
|
||||||
|
{},
|
||||||
|
function (resp) {
|
||||||
|
app.dialog.close();
|
||||||
|
if (resp.status == "ERROR") {
|
||||||
|
app.dialog.alert(resp.msg, "Error");
|
||||||
|
reject();
|
||||||
|
} else {
|
||||||
|
var context = {
|
||||||
|
machineid: "",
|
||||||
|
info: {}
|
||||||
|
};
|
||||||
|
var tabindex = 0;
|
||||||
|
for (var k in resp.formdata.inputtypes) {
|
||||||
|
if (resp.formdata.inputtypes.hasOwnProperty(k)) {
|
||||||
|
context.info[k] = {
|
||||||
|
name: k,
|
||||||
|
value: "",
|
||||||
|
type: (typeof resp.formdata.inputtypes[k] == "string" ? resp.formdata.inputtypes[k] : "text"),
|
||||||
|
label: (typeof resp.formdata.labels[k] == "string" ? resp.formdata.labels[k] : k),
|
||||||
|
icon: (typeof resp.formdata.icons[k] == "string" ? resp.formdata.icons[k] : "fas fa-square"),
|
||||||
|
tabindex: tabindex
|
||||||
|
};
|
||||||
|
if (context.info[k].type == "select") {
|
||||||
|
console.log(resp.formdata.options[k]);
|
||||||
|
var options = [];
|
||||||
|
for (var m in resp.formdata.options[k]) {
|
||||||
|
if (resp.formdata.options[k].hasOwnProperty(m)) {
|
||||||
|
options.push({
|
||||||
|
value: "val_" + m,
|
||||||
|
label: resp.formdata.options[k][m]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(options);
|
||||||
|
context.info[k].options = options;
|
||||||
|
}
|
||||||
|
tabindex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(context);
|
||||||
|
|
||||||
|
resolve({
|
||||||
|
templateUrl: "pages/machineeditor.html",
|
||||||
|
}, {
|
||||||
|
context: context
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function (xhr) {
|
||||||
|
app.dialog.close();
|
||||||
|
var error = $.parseJSON(xhr.responseText);
|
||||||
|
if (error && typeof error.msg != 'undefined') {
|
||||||
|
app.dialog.alert(error.msg, "Error");
|
||||||
|
} else {
|
||||||
|
app.dialog.alert("A server or network error occurred.", "Error");
|
||||||
|
}
|
||||||
|
reject();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function machineInfoOpenAsync(routeTo, routeFrom, resolve, reject) {
|
function machineInfoOpenAsync(routeTo, routeFrom, resolve, reject) {
|
||||||
app.dialog.preloader("Loading...");
|
app.dialog.preloader("Loading...");
|
||||||
|
|
||||||
@ -157,6 +222,9 @@ function machineInfoOpenAsync(routeTo, routeFrom, resolve, reject) {
|
|||||||
var tabindex = 0;
|
var tabindex = 0;
|
||||||
for (var k in resp.info) {
|
for (var k in resp.info) {
|
||||||
if (resp.info.hasOwnProperty(k)) {
|
if (resp.info.hasOwnProperty(k)) {
|
||||||
|
// if (resp.info[k] == null) {
|
||||||
|
// resp.info[k] = "";
|
||||||
|
// }
|
||||||
switch (k) {
|
switch (k) {
|
||||||
case "type":
|
case "type":
|
||||||
case "clientid":
|
case "clientid":
|
||||||
@ -164,7 +232,7 @@ function machineInfoOpenAsync(routeTo, routeFrom, resolve, reject) {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
var value = resp.info[k];
|
var value = resp.info[k];
|
||||||
if (value == false || value == 0) {
|
if (value == false || value == 0 || value == null) {
|
||||||
value = false;
|
value = false;
|
||||||
} else {
|
} else {
|
||||||
value = value.toString().replace("\n", " <br />");
|
value = value.toString().replace("\n", " <br />");
|
||||||
@ -203,9 +271,16 @@ function machineInfoOpenAsync(routeTo, routeFrom, resolve, reject) {
|
|||||||
function saveMachineEdits(machineid) {
|
function saveMachineEdits(machineid) {
|
||||||
app.dialog.preloader("Saving...");
|
app.dialog.preloader("Saving...");
|
||||||
|
|
||||||
var machinedata = {
|
if (typeof machineid == "undefined" || machineid == null) {
|
||||||
id: machineid
|
var apirequesttype = "addmachine";
|
||||||
};
|
var machinedata = {};
|
||||||
|
} else {
|
||||||
|
var apirequesttype = "editmachine";
|
||||||
|
var machinedata = {
|
||||||
|
id: machineid
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
$("#machineform .machinefield").each(function (i, o) {
|
$("#machineform .machinefield").each(function (i, o) {
|
||||||
if ($(this).parent().is(".smart-select")) {
|
if ($(this).parent().is(".smart-select")) {
|
||||||
machinedata[$(this).attr("name")] = app.smartSelect.get('#smartselect-' + $(this).attr("name")).getValue().replace("val_", "");
|
machinedata[$(this).attr("name")] = app.smartSelect.get('#smartselect-' + $(this).attr("name")).getValue().replace("val_", "");
|
||||||
@ -215,7 +290,7 @@ function saveMachineEdits(machineid) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
apirequest(
|
apirequest(
|
||||||
"editmachine",
|
apirequesttype,
|
||||||
machinedata,
|
machinedata,
|
||||||
function (resp) {
|
function (resp) {
|
||||||
app.dialog.close();
|
app.dialog.close();
|
||||||
@ -226,7 +301,11 @@ function saveMachineEdits(machineid) {
|
|||||||
text: 'Machine saved!',
|
text: 'Machine saved!',
|
||||||
closeTimeout: 2000,
|
closeTimeout: 2000,
|
||||||
}).open();
|
}).open();
|
||||||
|
addMachineToSearchHistory(resp.id);
|
||||||
router.back();
|
router.back();
|
||||||
|
if (apirequesttype === "addmachine") {
|
||||||
|
router.navigate("/machine/" + resp.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
function (xhr) {
|
function (xhr) {
|
||||||
|
@ -23,6 +23,12 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="fab fab-right-bottom">
|
||||||
|
<a href="/machineeditor">
|
||||||
|
<span class="material-icons">add</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="page-content">
|
<div class="page-content">
|
||||||
<!-- Searchbar is part of scrollable page content -->
|
<!-- Searchbar is part of scrollable page content -->
|
||||||
<form class="searchbar inset margin-top" id="machinesearchbar">
|
<form class="searchbar inset margin-top" id="machinesearchbar">
|
||||||
|
@ -41,7 +41,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|||||||
<i class="icon f7-icons if-not-md">plus</i>
|
<i class="icon f7-icons if-not-md">plus</i>
|
||||||
<i class="icon f7-icons if-not-md">xmark</i>
|
<i class="icon f7-icons if-not-md">xmark</i>
|
||||||
<!-- Icons For MD Theme -->
|
<!-- Icons For MD Theme -->
|
||||||
<i class="icon material-icons md-only">add</i>
|
<i class="icon material-icons md-only">more_vert</i>
|
||||||
<i class="icon material-icons md-only">close</i>
|
<i class="icon material-icons md-only">close</i>
|
||||||
</a>
|
</a>
|
||||||
<div class="fab-buttons fab-buttons-top">
|
<div class="fab-buttons fab-buttons-top">
|
||||||
|
@ -15,12 +15,12 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|||||||
<i class="icon icon-back"></i>
|
<i class="icon icon-back"></i>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="title">Editing #{{machineid}}</div>
|
<div class="title">{{#if machineid}}Editing #{{machineid}}{{else}}Add Machine{{if}}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="fab fab-extended fab-right-bottom color-green" id="save-fab">
|
<div class="fab fab-extended fab-right-bottom color-green" id="save-fab">
|
||||||
<a href="#" onclick="saveMachineEdits('{{machineid}}')">
|
<a href="#" onclick="saveMachineEdits({{#if machineid}}'{{machineid}}'{{/if}})">
|
||||||
<!-- Icons For iOS Theme -->
|
<!-- Icons For iOS Theme -->
|
||||||
<i class="icon f7-icons if-not-md">floppy_disk</i>
|
<i class="icon f7-icons if-not-md">floppy_disk</i>
|
||||||
<!-- Icons For MD Theme -->
|
<!-- Icons For MD Theme -->
|
||||||
|
@ -25,6 +25,11 @@ var routes = [
|
|||||||
name: "machine",
|
name: "machine",
|
||||||
async: machineInfoOpenAsync
|
async: machineInfoOpenAsync
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "/machineeditor",
|
||||||
|
name: "machineeditor",
|
||||||
|
async: newMachineEditorOpenAsync
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: "/machineeditor/:id",
|
path: "/machineeditor/:id",
|
||||||
name: "machineeditor",
|
name: "machineeditor",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user