Skip to content
This repository has been archived by the owner on Oct 6, 2019. It is now read-only.

Commit

Permalink
Asking user to confirm deletion of records, before deleting row
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Hansen committed Sep 25, 2017
1 parent 39683d4 commit f8609e7
Showing 1 changed file with 94 additions and 33 deletions.
127 changes: 94 additions & 33 deletions template/helpers/edit-item-template-widgets.hl
Original file line number Diff line number Diff line change
Expand Up @@ -83,41 +83,102 @@ Edit
onclick

/*
* Deleting row.
* Deleting row, asking user to confirm action first.
*/
p5.web.get-location
split:x:/@p5.web.get-location?value
=:/
=:?
p5.web.widgets.find-first-ancestor:x:/../*/_event?value
.id
get-widget-property:x:/-/*/*?value
.id
p5.mysql.connect:[camphora]
p5.mysql.delete:@"delete from `{0}` where id = @id"
:x:/@split/2?name
@id:x:/@get-widget-property/*/*?value
eval-x:x:/+/**/_widget
create-widgets
micro.widgets.modal:camphora-confirm-deletion
widgets
h3
innerValue:Please confirm deletion
p
innerValue:Do you really wish to delete this item? This action is permanent.
div
class:right
widgets
div
class:strip
style:"display:inline-block;"
widgets
button
innerValue:Yes
style:"margin-bottom:0;"
oninit

/*
* Deleting row wrapping record.
*/
delete-widget:x:/@p5.web.widgets.find-first-ancestor/*/*?value
/*
* Setting initial focus to "Yes" button.
*/
micro.page.set-focus:x:/../*/_event?value

/*
* Checking if item is currently being edited, and if so, making sure
* we delete its "edit widget".
*/
p5.web.widgets.find
.edit:x:/@get-widget-property/*/*?value
if:x:/@p5.web.widgets.find/*/*?value
onclick

/*
* Item is being edited, making sure we delete its edit widget.
*/
delete-widget:x:/@p5.web.widgets.find/*/*?value
/*
* Forward evaluated above.
*/
_widget:x:/../*/_event?value

/*
* Giving user visual feedback.
*/
micro.windows.info:Record was deleted
class:micro-windows-info success
/*
* Retrieving location of client, to determine app's name
*/
p5.web.get-location
p5.web.get-root-location
replace:x:/@p5.web.get-location?value
src:x:/@p5.web.get-root-location?value
split:x:/@replace?value
=:/
=:?

/*
* Figuring out database ID of record to delete.
*/
p5.web.widgets.find-first-ancestor:x:/../*/_widget?value
.id
get-widget-property:x:/@p5.web.widgets.find-first-ancestor/*/*?value
.id

/*
* Deleting record from database.
*/
p5.mysql.connect:[camphora]
p5.mysql.delete:@"delete from `{0}` where id = @id"
:x:/@split/0?name
@id:x:/@get-widget-property/*/*?value

/*
* Deleting row wrapping record in datagrid.
*/
delete-widget:x:/@p5.web.widgets.find-first-ancestor/*/*?value

/*
* Checking if item is currently being edited, and if so, making sure
* we delete its "edit widget".
*/
p5.web.widgets.find
.edit:x:/@get-widget-property/*/*?value
if:x:/@p5.web.widgets.find/*/*?value

/*
* Item is being edited, making sure we delete its edit widget.
*/
delete-widget:x:/@p5.web.widgets.find/*/*?value

/*
* Giving user some visual feedback.
*/
micro.windows.info:Record was deleted
class:micro-windows-info

/*
* Making sure we delete modal confirmation widget.
*/
delete-widget:camphora-confirm-deletion

button
innerValue:No
style:"margin-bottom:0;"
onclick

/*
* Deleting modal confirmation widget.
*/
delete-widget:camphora-confirm-deletion

0 comments on commit f8609e7

Please sign in to comment.