Skip to content

Commit

Permalink
Better feedback of current vs selected profile & available actions
Browse files Browse the repository at this point in the history
Also part of fixing core reason of #1734
  • Loading branch information
foosel committed Mar 21, 2017
1 parent 5535a9a commit 880b99f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
48 changes: 33 additions & 15 deletions src/octoprint/static/js/app/viewmodels/printerprofiles.js
Expand Up @@ -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);
Expand Down Expand Up @@ -482,28 +490,38 @@ $(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);
});
};

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) {
Expand All @@ -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);
Expand Down
Expand Up @@ -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>&nbsp;|&nbsp;<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>&nbsp;|&nbsp;<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>&nbsp;|&nbsp;<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>&nbsp;|&nbsp;<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>
Expand Down

0 comments on commit 880b99f

Please sign in to comment.