mirror of
https://github.com/Sebclem/OctoPrint-SimpleEmergencyStop.git
synced 2024-11-06 01:22:58 +01:00
108 lines
3.4 KiB
JavaScript
108 lines
3.4 KiB
JavaScript
/*
|
|
* View model for OctoPrint-Simpleemergencystop
|
|
*
|
|
* Author: Sebastien Clement
|
|
* License: AGPLv3
|
|
*/
|
|
$(function () {
|
|
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();
|
|
if(user.permissions !== undefined){
|
|
return user.permissions.includes("control") || user.needs.role.includes("control");
|
|
}
|
|
else return true;
|
|
|
|
}
|
|
|
|
this.ses_margin_css = function () {
|
|
if (this.settings.enableMargin()) {
|
|
$('#ses_wrapper').css({
|
|
'margin-left':`${this.settings.marginValue()}px`,
|
|
'margin-right':`${this.settings.marginValue()}px`
|
|
});
|
|
} else {
|
|
$('#ses_wrapper').css({
|
|
'margin-left':'0px',
|
|
'margin-right':'0px'
|
|
});
|
|
}
|
|
};
|
|
|
|
this.ses_visible = function () {
|
|
return this.loginState.isUser() && this.hasControlPermition();
|
|
};
|
|
|
|
this.big_button_visible = function () {
|
|
return this.settings.big_button();
|
|
};
|
|
|
|
this.little_button_visible = function () {
|
|
return !this.settings.big_button();
|
|
};
|
|
|
|
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'));
|
|
};
|
|
|
|
|
|
};
|
|
|
|
// view model class, parameters for constructor, container to bind to
|
|
OCTOPRINT_VIEWMODELS.push([
|
|
SimpleemergencystopViewModel,
|
|
|
|
["settingsViewModel", "loginStateViewModel", "printerStateViewModel"],
|
|
|
|
["#navbar_plugin_simpleemergencystop"]
|
|
]);
|
|
});
|