Skip to content

Commit

Permalink
Replace standard JavaScript Confirm with WAB dijit/Message on delete
Browse files Browse the repository at this point in the history
  • Loading branch information
jcornet committed Oct 21, 2015
1 parent 6f06ccf commit 51f3247
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 14 deletions.
96 changes: 84 additions & 12 deletions Widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,20 +271,80 @@ define([
this.showMessage(this.nls.noSelection, 'error');
return false;
}

if(this.config.confirmOnDelete){
this._confirmDeleteMessage = new Message({
message : '<i class="message-warning-icon"></i>&nbsp;' + this.nls.confirmDrawCheckedDelete,
buttons:[
{
label:this.nls.yes,
onClick:this._removeGraphics
},{
label:this.nls.no
}
]
});
}
else{
this._removeGraphics(graphics);
}
},

_removeClickedGraphic:function(){
if(!this._clickedGraphic)
return false;

this._removeGraphic(this._clickedGraphic);
this._editorConfig["graphicCurrent"] = false;
this.listGenerateDrawTable();

this._clickedGraphic = false;

if(this._confirmDeleteMessage && this._confirmDeleteMessage.close){
this._confirmDeleteMessage.close();
this._confirmDeleteMessage = false;
}
},

_removeGraphics:function(graphicsOrEvent){
if(graphicsOrEvent.target)
graphics = this.getCheckedGraphics(false);
else
graphics = graphicsOrEvent;



if (!this.config.confirmOnDelete || confirm(this.nls.clear)) {
// this.drawBox.drawLayer.clear();
for (var i = 0; i < nb; i++)
this.drawBox.drawLayer.remove(graphics[i]);
this.setInfoWindow(false);
this.setMode("list");
var nb = graphics.length;
console.log(graphics);
for (var i = 0; i < nb; i++) {
this._removeGraphic(graphics[i]);
}

if(this._confirmDeleteMessage && this._confirmDeleteMessage.close){
this._confirmDeleteMessage.close();
this._confirmDeleteMessage = false;
}

this.setInfoWindow(false);
this.setMode("list");
},

_removeGraphic : function (graphic) {
if (graphic.measure && graphic.measure.graphic) {
// graphic.measure.graphic.measureParent = false; //Remove link between graphic and it's measure label
this.drawBox.drawLayer.remove(graphic.measure.graphic); //Delete measure label
} else if (graphic.measureParent) {
graphic.measureParent.measure = false;
}
this.drawBox.drawLayer.remove(graphic);
},

drawingsGetJson : function (asString, onlyChecked) {
var graphics = (onlyChecked) ? this.getCheckedGraphics(false) : this.drawBox.drawLayer.graphics;

if (graphics.length < 1)

var nb_graphics = graphics.length;

if (nb_graphics < 1)
return (asString) ? '' : false;

var content = {
Expand Down Expand Up @@ -582,10 +642,22 @@ define([
this.listGenerateDrawTable();
break;
case 'draw-action-delete':
if (!this.config.confirmOnDelete || confirm(this.nls.confirmDrawDelete + ".")) {
g.getLayer().remove(g);
this._editorConfig["graphicCurrent"] = false;
this.listGenerateDrawTable();
this._clickedGraphic = g;
if(this.config.confirmOnDelete){
this._confirmDeleteMessage = new Message({
message : '<i class="message-warning-icon"></i>&nbsp;' + this.nls.confirmDrawDelete,
buttons:[
{
label:this.nls.yes,
onClick:this._removeClickedGraphic
},{
label:this.nls.no
}
]
});
}
else{
this._removeClickedGraphic();
}
break;
case 'draw-action-edit':
Expand Down
5 changes: 4 additions & 1 deletion nls/fr/strings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
define(
({
_widgetLabel : "Dessin",
yes:"Oui",
no:"Non",
selectDrawMode : "Sélectionner le mode de dessin",
clear : "Effacer",
point : "Point",
Expand Down Expand Up @@ -40,7 +42,8 @@ define(
squareMeters : "Mètres carrés",
squareFeet : "Pieds carrés",
squareYards : "Yards carrés",
confirmDrawDelete : "Ce dessin va être supprimé",
confirmDrawDelete : "Supprimer ce dessin ?",
confirmDrawCheckedDelete : "Supprimer les dessins sélectionnés ?",
all : "Tous",
draws : 'dessins',
addDrawTitle : 'Ajouter un dessin',
Expand Down
6 changes: 5 additions & 1 deletion nls/strings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
define({
root : ({
_widgetLabel : "Draw",
yes:"Yes",
yes:"Yes",
no:"No",
selectDrawMode : "Select drawing mode",
clear : "Clear",
point : "Point",
Expand Down Expand Up @@ -40,7 +43,8 @@ define({
squareMeters : "Square meters",
squareFeet : "Square feet",
squareYards : "Square yards",
confirmDrawDelete : "This drawing will be deleted",
confirmDrawDelete : "Delete this drawing ?",
confirmDrawCheckedDelete : "Delete checked drawing ?",
all : "All",
draws : 'drawings',
addDrawTitle : 'Add a drawing',
Expand Down

0 comments on commit 51f3247

Please sign in to comment.