2017-07-23 18:20:27 +02:00
|
|
|
/*
|
|
|
|
* View model for OctoPrint-Simpleemergencystop
|
|
|
|
*
|
|
|
|
* Author: Sebastien Clement
|
|
|
|
* License: AGPLv3
|
|
|
|
*/
|
2020-03-25 20:44:23 +01:00
|
|
|
$(function () {
|
2017-07-23 18:20:27 +02:00
|
|
|
function SimpleemergencystopViewModel(parameters) {
|
2020-03-25 20:44:23 +01:00
|
|
|
this.settings = undefined;
|
|
|
|
this.allSettings = parameters[0];
|
|
|
|
this.loginState = parameters[1];
|
|
|
|
this.printerState = parameters[2];
|
|
|
|
this.confirmation = undefined;
|
2017-07-25 23:58:19 +02:00
|
|
|
|
2020-08-04 13:57:44 +02:00
|
|
|
this.onAfterBinding = function () {};
|
2020-03-25 20:44:23 +01:00
|
|
|
this.onBeforeBinding = function () {
|
|
|
|
this.confirmation = $("#confirmation");
|
|
|
|
this.settings = this.allSettings.settings.plugins.simpleemergencystop;
|
2017-07-25 23:58:19 +02:00
|
|
|
};
|
|
|
|
|
2020-03-25 20:44:23 +01:00
|
|
|
this.click = function () {
|
|
|
|
if (!this.can_send_command())
|
|
|
|
return;
|
|
|
|
if (this.settings.confirmationDialog())
|
|
|
|
this.confirmation.modal("show");
|
2017-07-25 23:58:19 +02:00
|
|
|
else
|
2020-08-04 13:57:44 +02:00
|
|
|
this.sendCommand();
|
2017-07-25 23:58:19 +02:00
|
|
|
|
|
|
|
};
|
2017-08-28 00:30:45 +02:00
|
|
|
|
2020-03-25 20:44:23 +01:00
|
|
|
this.sendCommand = function () {
|
2017-07-25 23:58:19 +02:00
|
|
|
$.ajax({
|
2020-03-25 20:44:23 +01:00
|
|
|
url: API_BASEURL + "plugin/simpleemergencystop",
|
|
|
|
type: "POST",
|
|
|
|
dataType: "json",
|
|
|
|
data: JSON.stringify({
|
|
|
|
command: "emergencyStop"
|
|
|
|
}),
|
|
|
|
contentType: "application/json; charset=UTF-8",
|
2020-08-04 13:57:44 +02:00
|
|
|
success: function (data, status) {}
|
2017-07-25 23:58:19 +02:00
|
|
|
});
|
2020-03-25 20:44:23 +01:00
|
|
|
this.confirmation.modal("hide");
|
2017-07-25 23:58:19 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-08-17 13:05:24 +02:00
|
|
|
this.hasControlPermition = function () {
|
|
|
|
let user = this.loginState.currentUser()
|
|
|
|
return user.permissions.includes("control") || user.needs.role.includes("control");
|
|
|
|
}
|
|
|
|
|
2020-03-25 20:44:23 +01:00
|
|
|
this.big_button_visible = function () {
|
2020-08-17 13:05:24 +02:00
|
|
|
return this.loginState.isUser() && this.settings.big_button() && this.hasControlPermition();
|
2017-08-28 00:30:45 +02:00
|
|
|
};
|
2017-07-25 23:58:19 +02:00
|
|
|
|
2020-03-25 20:44:23 +01:00
|
|
|
this.little_button_visible = function () {
|
2020-08-17 13:05:24 +02:00
|
|
|
return this.loginState.isUser() && !this.settings.big_button() && this.hasControlPermition();
|
2020-03-25 20:44:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.can_send_command = function () {
|
2020-08-17 13:05:24 +02:00
|
|
|
return this.loginState.isUser() && this.hasControlPermition() && this.printerState.isOperational() ;
|
2020-03-25 20:44:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.little_button_css = function () {
|
2020-08-04 13:57:44 +02:00
|
|
|
return (this.printerState.isOperational() ? "ses_small" : "ses_small_disabled");
|
2020-03-25 20:44:23 +01:00
|
|
|
};
|
|
|
|
this.big_button_css = function () {
|
2020-08-04 13:57:44 +02:00
|
|
|
return (this.printerState.isOperational() ? "ses_big" : "ses_big ses_big_disabled");
|
2020-03-25 20:44:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.get_title = function () {
|
2020-08-04 13:57:44 +02:00
|
|
|
return (this.printerState.isOperational() ? gettext('!!! Emergency Stop !!! ') : gettext('Printer disconnected'));
|
|
|
|
};
|
2020-03-25 20:44:23 +01:00
|
|
|
|
2017-07-23 18:20:27 +02:00
|
|
|
|
2020-08-04 13:57:44 +02:00
|
|
|
};
|
2017-07-23 18:20:27 +02:00
|
|
|
|
|
|
|
// view model class, parameters for constructor, container to bind to
|
|
|
|
OCTOPRINT_VIEWMODELS.push([
|
|
|
|
SimpleemergencystopViewModel,
|
|
|
|
|
2020-03-25 20:44:23 +01:00
|
|
|
["settingsViewModel", "loginStateViewModel", "printerStateViewModel"],
|
2017-07-23 18:20:27 +02:00
|
|
|
|
|
|
|
["#navbar_plugin_simpleemergencystop"]
|
|
|
|
]);
|
|
|
|
});
|