OctoPrint-SimpleEmergencyStop/octoprint_simpleemergencystop/static/js/simpleemergencystop.js

86 lines
2.8 KiB
JavaScript
Raw Normal View History

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