Better feedback of current vs selected profile & available actions
Also part of fixing core reason of #1734
This commit is contained in:
parent
5535a9aeb0
commit
880b99faaf
2 changed files with 35 additions and 17 deletions
|
|
@ -444,6 +444,14 @@ $(function() {
|
|||
self.updateProfile(profile);
|
||||
};
|
||||
|
||||
self.canMakeDefault = function(data) {
|
||||
return !data.isdefault();
|
||||
};
|
||||
|
||||
self.canRemove = function(data) {
|
||||
return !data.iscurrent() && !data.isdefault();
|
||||
};
|
||||
|
||||
self.requestData = function() {
|
||||
OctoPrint.printerprofiles.list()
|
||||
.done(self.fromResponse);
|
||||
|
|
@ -482,9 +490,9 @@ $(function() {
|
|||
}
|
||||
self.requestData();
|
||||
})
|
||||
.fail(function() {
|
||||
.fail(function(xhr) {
|
||||
var text = gettext("There was unexpected error while saving the printer profile, please consult the logs.");
|
||||
new PNotify({title: gettext("Saving failed"), text: text, type: "error", hide: false});
|
||||
new PNotify({title: gettext("Could not add profile"), text: text, type: "error", hide: false});
|
||||
})
|
||||
.always(function() {
|
||||
self.requestInProgress(false);
|
||||
|
|
@ -492,18 +500,28 @@ $(function() {
|
|||
};
|
||||
|
||||
self.removeProfile = function(data) {
|
||||
self.requestInProgress(true);
|
||||
OctoPrint.printerprofiles.delete(data.id, {url: data.resource})
|
||||
.done(function() {
|
||||
self.requestData();
|
||||
})
|
||||
.fail(function() {
|
||||
var text = gettext("There was unexpected error while removing the printer profile, please consult the logs.");
|
||||
new PNotify({title: gettext("Saving failed"), text: text, type: "error", hide: false});
|
||||
})
|
||||
.always(function() {
|
||||
self.requestInProgress(false);
|
||||
});
|
||||
var perform = function() {
|
||||
self.requestInProgress(true);
|
||||
OctoPrint.printerprofiles.delete(data.id, {url: data.resource})
|
||||
.done(function() {
|
||||
self.requestData();
|
||||
})
|
||||
.fail(function(xhr) {
|
||||
var text;
|
||||
if (xhr.status == 409) {
|
||||
text = gettext("Cannot delete the default profile or the currently active profile.");
|
||||
} else {
|
||||
text = gettext("There was unexpected error while removing the printer profile, please consult the logs.");
|
||||
}
|
||||
new PNotify({title: gettext("Could not delete profile"), text: text, type: "error", hide: false});
|
||||
})
|
||||
.always(function() {
|
||||
self.requestInProgress(false);
|
||||
});
|
||||
};
|
||||
|
||||
showConfirmationDialog(_.sprintf(gettext("You are about to delete the printer profile \"%(name)s\"."), {name: data.name}),
|
||||
perform);
|
||||
};
|
||||
|
||||
self.updateProfile = function(profile, callback) {
|
||||
|
|
@ -521,7 +539,7 @@ $(function() {
|
|||
})
|
||||
.fail(function() {
|
||||
var text = gettext("There was unexpected error while updating the printer profile, please consult the logs.");
|
||||
new PNotify({title: gettext("Saving failed"), text: text, type: "error", hide: false});
|
||||
new PNotify({title: gettext("Could not update profile"), text: text, type: "error", hide: false});
|
||||
})
|
||||
.always(function() {
|
||||
self.requestInProgress(false);
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@
|
|||
</thead>
|
||||
<tbody data-bind="foreach: printerProfiles.profiles.paginatedItems">
|
||||
<tr data-bind="attr: {title: name}">
|
||||
<td class="settings_printerProfiles_profiles_name"><span class="icon-star" data-bind="invisible: !isdefault()"></span> <span data-bind="text: name"></span></td>
|
||||
<td class="settings_printerProfiles_profiles_name"><span class="icon-star" data-bind="invisible: !isdefault()"></span> <span data-bind="text: name, style: { 'font-weight': iscurrent() ? 'bold' : 'normal' }"></span></td>
|
||||
<td class="settings_printerProfiles_profiles_model" data-bind="text: model"></td>
|
||||
<td class="settings_printerProfiles_profiles_action">
|
||||
<a href="#" class="icon-star" title="{{ _('Set as default profile') }}" data-bind="click: function() { $root.printerProfiles.makeDefault($data); }, css: {disabled: $root.printerProfiles.requestInProgress()}, enabled: !$root.printerProfiles.requestInProgress()"></a> | <a href="#" class="icon-pencil" title="{{ _('Edit Profile') }}" data-bind="click: function() { $root.printerProfiles.showEditProfileDialog($data); }, css: {disabled: $root.printerProfiles.requestInProgress()}, enabled: !$root.printerProfiles.requestInProgress()"></a> | <a href="#" class="icon-trash" title="{{ _('Delete Profile') }}" data-bind="click: function() { $root.printerProfiles.removeProfile($data); }, css: {disabled: $root.printerProfiles.requestInProgress()}, enabled: !$root.printerProfiles.requestInProgress()"></a>
|
||||
<a href="#" class="icon-star" title="{{ _('Set as default profile') }}" data-bind="click: function() { $root.printerProfiles.makeDefault($data); }, css: {disabled: !$root.printerProfiles.canMakeDefault($data) || $root.printerProfiles.requestInProgress()}, enabled: $root.printerProfile.canMakeDefault($data) && !$root.printerProfiles.requestInProgress()"></a> | <a href="#" class="icon-pencil" title="{{ _('Edit Profile') }}" data-bind="click: function() { $root.printerProfiles.showEditProfileDialog($data); }, css: {disabled: $root.printerProfiles.requestInProgress()}, enabled: !$root.printerProfiles.requestInProgress()"></a> | <a href="#" class="icon-trash" title="{{ _('Delete Profile') }}" data-bind="click: function() { $root.printerProfiles.removeProfile($data); }, css: {disabled: !$root.printerProfiles.canRemove($data) || $root.printerProfiles.requestInProgress()}, enabled: $root.printerProfiles.canRemove($data) && !$root.printerProfiles.requestInProgress()"></a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
|
|||
Loading…
Reference in a new issue