Skip to content

Commit

Permalink
Add pattern Delete option.
Browse files Browse the repository at this point in the history
  • Loading branch information
gskinner committed Jun 18, 2018
1 parent 402f305 commit ee5fab1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 4 deletions.
24 changes: 24 additions & 0 deletions dev/icons/delete.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion dev/inject/icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion dev/sass/colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $light-shadow: rgba(0,0,0, 0.1);
$strong-shadow: rgba(0,0,0, 0.45);

// syntax coloring:
$error-color: #C24;
$error-color: #C22;

$group-color: #090;
$groupbg-color: #0E0;
Expand Down
4 changes: 4 additions & 0 deletions dev/sass/views/share.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
display: none;
}

.delete.row:hover {
background: rgba($error-color, 0.6);
}

> .save {
background: $darker;
margin: $pad;
Expand Down
22 changes: 21 additions & 1 deletion dev/src/views/Share.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ export default class Share extends EventDispatcher {
this._favoritesStatus = new Status($.query(".status", this._favoritesRow));
this._communityRow = $.query(".row.community", this.mainEl);
this._communityRow.addEventListener("click", ()=> this._showCommunity());
this._deleteRow = $.query(".row.delete", this.mainEl);
this._deleteRow.addEventListener("click", ()=> this._doDelete());
this._deleteStatus = new Status($.query(".status", this._deleteRow));
$.query(".row.signin a", this.mainEl).addEventListener("click", ()=> this._doSignin());

// set up link row:
Expand Down Expand Up @@ -158,6 +161,7 @@ export default class Share extends EventDispatcher {
$.toggleClass(this._privateRow, "disabled", isNew || !isOwned);
$.toggleClass(this._favoritesRow, "disabled", isNew || !isOwned);
$.toggleClass(this._communityRow, "disabled", isNew || !isOwned);
$.toggleClass(this._deleteRow, "disabled", isNew || !isOwned);

$.toggleClass(this._privateRow, "active", o.access === "private");
$.toggleClass(this._favoritesRow, "active", !!o.favorite);
Expand Down Expand Up @@ -275,7 +279,7 @@ export default class Share extends EventDispatcher {
.then((data) => this._handleFavorite(data))
.catch((err) => this._handleErr(err, this._favoritesStatus));
}

_handleFavorite(data) {
if (data.id === this._pattern.id) {
this._pattern.favorite = data.favorite;
Expand All @@ -284,6 +288,22 @@ export default class Share extends EventDispatcher {
}
}

_doDelete() {
let o = this._pattern;
if (!confirm("Are you sure you want to permanently delete this pattern?")) { return; }
this._deleteStatus.distract();
Server.delete(o.id)
.then((data) => this._handleDelete(data))
.catch((err) => this._handleErr(err, this._deleteStatus));
}

_handleDelete(data) {
this._deleteStatus.hide();
app.state = {
flavor: app.flavor.value
}
}

_handleErr(err, status) {
status.error(this._getErrMsg(err)).hide(6);
}
Expand Down
Loading

0 comments on commit ee5fab1

Please sign in to comment.