| 1 |
dojo.provide("dojox.mobile.app.AlertDialog"); |
| 2 |
dojo.experimental("dojox.mobile.app.AlertDialog"); |
| 3 |
dojo.require("dijit._WidgetBase"); |
| 4 |
|
| 5 |
dojo.declare("dojox.mobile.app.AlertDialog", dijit._WidgetBase, { |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
title: "", |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
text: "", |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
controller: null, |
| 18 |
|
| 19 |
|
| 20 |
buttons: null, |
| 21 |
|
| 22 |
defaultButtonLabel: "OK", |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
onChoose: null, |
| 28 |
|
| 29 |
constructor: function(){ |
| 30 |
this.onClick = dojo.hitch(this, this.onClick); |
| 31 |
this._handleSelect = dojo.hitch(this, this._handleSelect); |
| 32 |
}, |
| 33 |
|
| 34 |
buildRendering: function(){ |
| 35 |
this.domNode = dojo.create("div",{ |
| 36 |
"class": "alertDialog" |
| 37 |
}); |
| 38 |
|
| 39 |
|
| 40 |
var dlgBody = dojo.create("div", {"class": "alertDialogBody"}, this.domNode); |
| 41 |
|
| 42 |
|
| 43 |
dojo.create("div", {"class": "alertTitle", innerHTML: this.title || ""}, dlgBody); |
| 44 |
|
| 45 |
|
| 46 |
dojo.create("div", {"class": "alertText", innerHTML: this.text || ""}, dlgBody); |
| 47 |
|
| 48 |
|
| 49 |
var btnContainer = dojo.create("div", {"class": "alertBtns"}, dlgBody); |
| 50 |
|
| 51 |
|
| 52 |
if(!this.buttons || this.buttons.length == 0){ |
| 53 |
this.buttons = [{ |
| 54 |
label: this.defaultButtonLabel, |
| 55 |
value: "ok", |
| 56 |
"class": "affirmative" |
| 57 |
}]; |
| 58 |
} |
| 59 |
|
| 60 |
var _this = this; |
| 61 |
|
| 62 |
|
| 63 |
dojo.forEach(this.buttons, function(btnInfo){ |
| 64 |
var btn = new dojox.mobile.Button({ |
| 65 |
btnClass: btnInfo["class"] || "", |
| 66 |
label: btnInfo.label |
| 67 |
}); |
| 68 |
btn._dialogValue = btnInfo.value; |
| 69 |
dojo.place(btn.domNode, btnContainer); |
| 70 |
_this.connect(btn, "onClick", _this._handleSelect); |
| 71 |
}); |
| 72 |
|
| 73 |
var viewportSize = this.controller.getWindowSize(); |
| 74 |
|
| 75 |
|
| 76 |
this.mask = dojo.create("div", {"class": "dialogUnderlayWrapper", |
| 77 |
innerHTML: "<div class=\"dialogUnderlay\"></div>", |
| 78 |
style: { |
| 79 |
width: viewportSize.w + "px", |
| 80 |
height: viewportSize.h + "px" |
| 81 |
} |
| 82 |
}, this.controller.assistant.domNode); |
| 83 |
|
| 84 |
this.connect(this.mask, "onclick", function(){ |
| 85 |
_this.onChoose && _this.onChoose(); |
| 86 |
_this.hide(); |
| 87 |
}); |
| 88 |
}, |
| 89 |
|
| 90 |
postCreate: function(){ |
| 91 |
this.subscribe("/dojox/mobile/app/goback", this._handleSelect); |
| 92 |
}, |
| 93 |
|
| 94 |
_handleSelect: function(event){ |
| 95 |
|
| 96 |
|
| 97 |
var node; |
| 98 |
console.log("handleSelect"); |
| 99 |
if(event && event.target){ |
| 100 |
node = event.target; |
| 101 |
|
| 102 |
|
| 103 |
while(!dijit.byNode(node)){ |
| 104 |
node = node.parentNode; |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
if(this.onChoose){ |
| 111 |
this.onChoose(node ? dijit.byNode(node)._dialogValue: undefined); |
| 112 |
} |
| 113 |
|
| 114 |
this.hide(); |
| 115 |
}, |
| 116 |
|
| 117 |
show: function(){ |
| 118 |
|
| 119 |
|
| 120 |
this._doTransition(1); |
| 121 |
}, |
| 122 |
|
| 123 |
hide: function(){ |
| 124 |
|
| 125 |
|
| 126 |
this._doTransition(-1); |
| 127 |
}, |
| 128 |
|
| 129 |
_doTransition: function(dir){ |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
var anim; |
| 139 |
var h = dojo.marginBox(this.domNode.firstChild).h; |
| 140 |
|
| 141 |
|
| 142 |
var bodyHeight = this.controller.getWindowSize().h; |
| 143 |
console.log("dialog height = " + h, " body height = " + bodyHeight); |
| 144 |
|
| 145 |
var high = bodyHeight - h; |
| 146 |
var low = bodyHeight; |
| 147 |
|
| 148 |
var anim1 = dojo.fx.slideTo({ |
| 149 |
node: this.domNode, |
| 150 |
duration: 400, |
| 151 |
top: {start: dir < 0 ? high : low, end: dir < 0 ? low: high} |
| 152 |
}); |
| 153 |
|
| 154 |
var anim2 = dojo[dir < 0 ? "fadeOut" : "fadeIn"]({ |
| 155 |
node: this.mask, |
| 156 |
duration: 400 |
| 157 |
}); |
| 158 |
|
| 159 |
var anim = dojo.fx.combine([anim1, anim2]); |
| 160 |
|
| 161 |
var _this = this; |
| 162 |
|
| 163 |
dojo.connect(anim, "onEnd", this, function(){ |
| 164 |
if(dir < 0){ |
| 165 |
_this.domNode.style.display = "none"; |
| 166 |
dojo.destroy(_this.domNode); |
| 167 |
dojo.destroy(_this.mask); |
| 168 |
} |
| 169 |
}); |
| 170 |
anim.play(); |
| 171 |
}, |
| 172 |
|
| 173 |
destroy: function(){ |
| 174 |
this.inherited(arguments); |
| 175 |
dojo.destroy(this.mask); |
| 176 |
}, |
| 177 |
|
| 178 |
|
| 179 |
onClick: function(){ |
| 180 |
|
| 181 |
} |
| 182 |
}); |