| 1 |
define([ |
| 2 |
"dojo/_base/kernel", |
| 3 |
"dojo/_base/lang", |
| 4 |
"dojo/_base/array", |
| 5 |
"dojo/_base/json", |
| 6 |
"dojo/_base/fx", |
| 7 |
"dojo/_base/window", |
| 8 |
"dojo/_base/connect", |
| 9 |
"dojo/dom-class", |
| 10 |
"dojo/dom-style", |
| 11 |
"dojo/dom-construct", |
| 12 |
"dojo/dom-geometry", |
| 13 |
"dojo/keys", |
| 14 |
"dijit/_Widget", |
| 15 |
"dijit/_TemplatedMixin", |
| 16 |
"dijit/form/_FormValueWidget", |
| 17 |
"dijit/form/ValidationTextBox", |
| 18 |
"dijit/InlineEditBox", |
| 19 |
"dojo/i18n!dijit/nls/common", |
| 20 |
"dojo/_base/declare" |
| 21 |
], function(kernel, lang, array, jsonUtil, fx, win, connect, domClass, domStyle, domConstruct, domGeometry, keys, Widget, TemplatedMixin, FormValueWidget, ValidationTextBox, InlineEditBox, i18nCommon, declare){ |
| 22 |
kernel.experimental("dojox.form.ListInput"); |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
var ListInput = declare("dojox.form.ListInput", [FormValueWidget], |
| 34 |
{ |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
constructor: function(){ |
| 42 |
this._items = []; |
| 43 |
|
| 44 |
|
| 45 |
if(!lang.isArray(this.delimiter)){ |
| 46 |
this.delimiter=[this.delimiter]; |
| 47 |
} |
| 48 |
var r="("+this.delimiter.join("|")+")?"; |
| 49 |
this.regExp="^"+this.regExp+r+"$"; |
| 50 |
}, |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
inputClass: "dojox.form._ListInputInputBox", |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
inputHandler: "onChange", |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
inputProperties: { |
| 68 |
minWidth:50 |
| 69 |
}, |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
submitOnlyValidValue:true, |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
useOnBlur:true, |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
readOnlyInput: false, |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
maxItems: null, |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
showCloseButtonWhenValid: true, |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
showCloseButtonWhenInvalid: true, |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
regExp: ".*", |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
delimiter: ",", |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
constraints: {}, |
| 110 |
|
| 111 |
baseClass:"dojoxListInput", |
| 112 |
|
| 113 |
type: "select", |
| 114 |
|
| 115 |
value: "", |
| 116 |
|
| 117 |
templateString: "<div dojoAttachPoint=\"focusNode\" class=\"dijit dijitReset dijitLeft dojoxListInput\"><select dojoAttachpoint=\"_selectNode\" multiple=\"multiple\" class=\"dijitHidden\" ${!nameAttrSetting}></select><ul dojoAttachPoint=\"_listInput\"><li dojoAttachEvent=\"onclick: _onClick\" class=\"dijitInputField dojoxListInputNode dijitHidden\" dojoAttachPoint=\"_inputNode\"></li></ul></div>", |
| 118 |
|
| 119 |
_setNameAttr: "_selectNode", |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
useAnim: true, |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
duration: 500, |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
easingIn: null, |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
easingOut: null, |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
readOnlyItem: false, |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
useArrowForEdit: true, |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
_items: null, |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
_lastAddedItem: null, |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
_currentItem: null, |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
_input: null, |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
_count: 0, |
| 167 |
|
| 168 |
postCreate: function(){ |
| 169 |
|
| 170 |
|
| 171 |
this.inherited(arguments); |
| 172 |
this._createInputBox(); |
| 173 |
}, |
| 174 |
|
| 175 |
_setReadOnlyInputAttr: function( value){ |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
if(!this._started){ return this._createInputBox(); } |
| 181 |
this.readOnlyInput = value; |
| 182 |
this._createInputBox(); |
| 183 |
}, |
| 184 |
|
| 185 |
_setReadOnlyItemAttr: function( value){ |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
if(!this._started){ return; } |
| 191 |
for(var i in this._items){ |
| 192 |
this._items[i].set("readOnlyItem", value); |
| 193 |
} |
| 194 |
}, |
| 195 |
|
| 196 |
_createInputBox: function(){ |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
domClass.toggle(this._inputNode, "dijitHidden", this.readOnlyInput); |
| 202 |
if(this.readOnlyInput){ return; } |
| 203 |
if(this._input){ return; } |
| 204 |
|
| 205 |
if(this.inputHandler === null){ |
| 206 |
console.warn("you must add some handler to connect to input field"); |
| 207 |
return false; |
| 208 |
} |
| 209 |
if(lang.isString(this.inputHandler)){ |
| 210 |
this.inputHandler = this.inputHandler.split(","); |
| 211 |
} |
| 212 |
if(lang.isString(this.inputProperties)){ |
| 213 |
this.inputProperties = jsonUtil.fromJson(this.inputProperties); |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
var input = lang.getObject(this.inputClass, false); |
| 218 |
|
| 219 |
this.inputProperties.regExp = this.regExpGen(this.constraints); |
| 220 |
|
| 221 |
this._input = new input(this.inputProperties); |
| 222 |
this._input.startup(); |
| 223 |
this._inputNode.appendChild(this._input.domNode); |
| 224 |
array.forEach(this.inputHandler, function(handler){ |
| 225 |
this.connect(this._input,lang.trim(handler),"_onHandler"); |
| 226 |
},this); |
| 227 |
|
| 228 |
this.connect(this._input, "onKeyDown", "_inputOnKeyDown"); |
| 229 |
this.connect(this._input, "onBlur", "_inputOnBlur"); |
| 230 |
}, |
| 231 |
|
| 232 |
compare: function( val1, val2){ |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
val1 = val1.join(","); |
| 238 |
val2 = val2.join(","); |
| 239 |
if(val1 > val2){ |
| 240 |
return 1; |
| 241 |
}else if(val1 < val2){ |
| 242 |
return -1; |
| 243 |
}else{ |
| 244 |
return 0; |
| 245 |
} |
| 246 |
}, |
| 247 |
|
| 248 |
add: function( values){ |
| 249 |
|
| 250 |
|
| 251 |
if(this._count>=this.maxItems && this.maxItems !== null){return;} |
| 252 |
this._lastValueReported = this._getValues(); |
| 253 |
|
| 254 |
if(!lang.isArray(values)){ |
| 255 |
values = [values]; |
| 256 |
} |
| 257 |
|
| 258 |
for(var i in values){ |
| 259 |
var value=values[i]; |
| 260 |
if(value === "" || typeof value != "string"){ |
| 261 |
continue; |
| 262 |
} |
| 263 |
this._count++; |
| 264 |
var re = new RegExp(this.regExpGen(this.constraints)); |
| 265 |
|
| 266 |
this._lastAddedItem = new _ListInputInputItem({ |
| 267 |
"index" : this._items.length, |
| 268 |
readOnlyItem : this.readOnlyItem, |
| 269 |
value : value, |
| 270 |
regExp: this.regExpGen(this.constraints) |
| 271 |
}); |
| 272 |
this._lastAddedItem.startup(); |
| 273 |
|
| 274 |
this._testItem(this._lastAddedItem,value); |
| 275 |
|
| 276 |
this._lastAddedItem.onClose = lang.hitch(this,"_onItemClose",this._lastAddedItem); |
| 277 |
this._lastAddedItem.onChange = lang.hitch(this,"_onItemChange",this._lastAddedItem); |
| 278 |
this._lastAddedItem.onEdit = lang.hitch(this,"_onItemEdit",this._lastAddedItem); |
| 279 |
this._lastAddedItem.onKeyDown = lang.hitch(this,"_onItemKeyDown",this._lastAddedItem); |
| 280 |
|
| 281 |
if(this.useAnim){ |
| 282 |
domStyle.set(this._lastAddedItem.domNode, {opacity:0, display:""}); |
| 283 |
} |
| 284 |
|
| 285 |
this._placeItem(this._lastAddedItem.domNode); |
| 286 |
|
| 287 |
if(this.useAnim){ |
| 288 |
var anim = fx.fadeIn({ |
| 289 |
node : this._lastAddedItem.domNode, |
| 290 |
duration : this.duration, |
| 291 |
easing : this.easingIn |
| 292 |
}).play(); |
| 293 |
} |
| 294 |
|
| 295 |
this._items[this._lastAddedItem.index] = this._lastAddedItem; |
| 296 |
|
| 297 |
if(this._onChangeActive && this.intermediateChanges){ this.onChange(value); } |
| 298 |
|
| 299 |
if(this._count>=this.maxItems && this.maxItems !== null){ |
| 300 |
break; |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
this._updateValues(); |
| 305 |
if(this._lastValueReported.length==0){ |
| 306 |
this._lastValueReported = this.value; |
| 307 |
} |
| 308 |
|
| 309 |
if(!this.readOnlyInput){ |
| 310 |
this._input.set("value", ""); |
| 311 |
} |
| 312 |
|
| 313 |
if(this._onChangeActive){ this.onChange(this.value); } |
| 314 |
|
| 315 |
this._setReadOnlyWhenMaxItemsReached(); |
| 316 |
}, |
| 317 |
|
| 318 |
_setReadOnlyWhenMaxItemsReached: function(){ |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
this.set("readOnlyInput",(this._count>=this.maxItems && this.maxItems !== null)); |
| 324 |
}, |
| 325 |
|
| 326 |
_setSelectNode: function(){ |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
this._selectNode.options.length = 0; |
| 332 |
|
| 333 |
var values=this.submitOnlyValidValue?this.get("MatchedValue"):this.value; |
| 334 |
|
| 335 |
if(!lang.isArray(values)){ |
| 336 |
return; |
| 337 |
} |
| 338 |
array.forEach(values,function(item){ |
| 339 |
this._selectNode.options[this._selectNode.options.length]=new Option(item,item,true,true); |
| 340 |
},this); |
| 341 |
}, |
| 342 |
|
| 343 |
_placeItem: function( node){ |
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
domConstruct.place(node,this._inputNode, "before"); |
| 349 |
}, |
| 350 |
|
| 351 |
_getCursorPos: function( node){ |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
if(typeof node.selectionStart != 'undefined'){ |
| 357 |
return node.selectionStart; |
| 358 |
} |
| 359 |
|
| 360 |
|
| 361 |
try{ node.focus(); }catch(e){} |
| 362 |
var range = node.createTextRange(); |
| 363 |
range.moveToBookmark(win.doc.selection.createRange().getBookmark()); |
| 364 |
range.moveEnd('character', node.value.length); |
| 365 |
try{ |
| 366 |
return node.value.length - range.text.length; |
| 367 |
}finally{ range=null; } |
| 368 |
}, |
| 369 |
|
| 370 |
_onItemClose: function( item){ |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
if(this.disabled){ return; } |
| 376 |
|
| 377 |
if(this.useAnim){ |
| 378 |
var anim = fx.fadeOut({ |
| 379 |
node : item.domNode, |
| 380 |
duration : this.duration, |
| 381 |
easing : this.easingOut, |
| 382 |
onEnd : lang.hitch(this, "_destroyItem", item) |
| 383 |
}).play(); |
| 384 |
}else{ |
| 385 |
this._destroyItem(item); |
| 386 |
} |
| 387 |
}, |
| 388 |
|
| 389 |
_onItemKeyDown: function( item, e){ |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
if(this.readOnlyItem || !this.useArrowForEdit){ return; } |
| 395 |
|
| 396 |
if(e.keyCode == keys.LEFT_ARROW && this._getCursorPos(e.target)==0){ |
| 397 |
this._editBefore(item); |
| 398 |
}else if(e.keyCode == keys.RIGHT_ARROW && this._getCursorPos(e.target)==e.target.value.length){ |
| 399 |
this._editAfter(item); |
| 400 |
} |
| 401 |
}, |
| 402 |
|
| 403 |
_editBefore: function( item){ |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
this._currentItem = this._getPreviousItem(item); |
| 409 |
if(this._currentItem !== null){ |
| 410 |
this._currentItem.edit(); |
| 411 |
} |
| 412 |
}, |
| 413 |
_editAfter: function( item){ |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
this._currentItem = this._getNextItem(item); |
| 419 |
if(this._currentItem !== null){ |
| 420 |
this._currentItem.edit(); |
| 421 |
} |
| 422 |
|
| 423 |
if(!this.readOnlyInput){ |
| 424 |
if(this._currentItem === null){ |
| 425 |
|
| 426 |
|
| 427 |
this._focusInput(); |
| 428 |
} |
| 429 |
} |
| 430 |
}, |
| 431 |
|
| 432 |
_onItemChange: function( item, value){ |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
value = value || item.get("value"); |
| 439 |
|
| 440 |
|
| 441 |
this._testItem(item,value); |
| 442 |
|
| 443 |
|
| 444 |
this._updateValues(); |
| 445 |
}, |
| 446 |
|
| 447 |
_onItemEdit: function( item){ |
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
domClass.remove(item.domNode,["dijitError", this.baseClass + "Match", this.baseClass + "Mismatch"]); |
| 453 |
}, |
| 454 |
|
| 455 |
_testItem: function( item, value){ |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
var re = new RegExp(this.regExpGen(this.constraints)); |
| 461 |
var match = ('' + value).match(re); |
| 462 |
|
| 463 |
domClass.remove(item.domNode, this.baseClass + (!match ? "Match" : "Mismatch")); |
| 464 |
domClass.add(item.domNode, this.baseClass + (match ? "Match" : "Mismatch")); |
| 465 |
domClass.toggle(item.domNode, "dijitError", !match); |
| 466 |
|
| 467 |
if((this.showCloseButtonWhenValid && match) || |
| 468 |
(this.showCloseButtonWhenInvalid && !match)){ |
| 469 |
domClass.add(item.domNode,this.baseClass+"Closable"); |
| 470 |
}else { |
| 471 |
domClass.remove(item.domNode,this.baseClass+"Closable"); |
| 472 |
} |
| 473 |
}, |
| 474 |
|
| 475 |
_getValueAttr: function(){ |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
return this.value; |
| 481 |
}, |
| 482 |
|
| 483 |
_setValueAttr: function( newValue){ |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
this._destroyAllItems(); |
| 491 |
|
| 492 |
this.add(this._parseValue(newValue)); |
| 493 |
}, |
| 494 |
|
| 495 |
_parseValue: function( newValue){ |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
if(typeof newValue == "string"){ |
| 501 |
if(lang.isString(this.delimiter)){ |
| 502 |
this.delimiter = [this.delimiter]; |
| 503 |
} |
| 504 |
var re = new RegExp("^.*("+this.delimiter.join("|")+").*"); |
| 505 |
if(newValue.match(re)){ |
| 506 |
re = new RegExp(this.delimiter.join("|")); |
| 507 |
return newValue.split(re); |
| 508 |
} |
| 509 |
} |
| 510 |
return newValue; |
| 511 |
}, |
| 512 |
|
| 513 |
regExpGen: function( constraints){ |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
return this.regExp; |
| 520 |
}, |
| 521 |
|
| 522 |
_setDisabledAttr: function( value){ |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
if(!this.readOnlyItem){ |
| 528 |
for(var i in this._items){ |
| 529 |
this._items[i].set("disabled", value); |
| 530 |
} |
| 531 |
} |
| 532 |
|
| 533 |
if(!this.readOnlyInput){ |
| 534 |
this._input.set("disabled", value); |
| 535 |
} |
| 536 |
this.inherited(arguments); |
| 537 |
}, |
| 538 |
|
| 539 |
_onHandler: function( value){ |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
var parsedValue = this._parseValue(value); |
| 545 |
if(lang.isArray(parsedValue)){ |
| 546 |
this.add(parsedValue); |
| 547 |
} |
| 548 |
}, |
| 549 |
|
| 550 |
_onClick: function( e){ |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
this._focusInput(); |
| 556 |
}, |
| 557 |
|
| 558 |
_focusInput: function(){ |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
if(!this.readOnlyInput && this._input.focus){ |
| 564 |
this._input.focus(); |
| 565 |
} |
| 566 |
}, |
| 567 |
|
| 568 |
_inputOnKeyDown: function( e){ |
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
this._currentItem = null; |
| 574 |
var val = this._input.get("value"); |
| 575 |
|
| 576 |
if(e.keyCode == keys.BACKSPACE && val == "" && this.get("lastItem")){ |
| 577 |
this._destroyItem(this.get("lastItem")); |
| 578 |
}else if(e.keyCode == keys.ENTER && val != ""){ |
| 579 |
this.add(val); |
| 580 |
}else if(e.keyCode == keys.LEFT_ARROW && this._getCursorPos(this._input.focusNode) == 0 && |
| 581 |
!this.readOnlyItem && this.useArrowForEdit){ |
| 582 |
this._editBefore(); |
| 583 |
} |
| 584 |
}, |
| 585 |
|
| 586 |
_inputOnBlur: function(){ |
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
var val = this._input.get('value'); |
| 592 |
if(this.useOnBlur && val != ""){ |
| 593 |
this.add(val); |
| 594 |
} |
| 595 |
}, |
| 596 |
|
| 597 |
_getMatchedValueAttr: function(){ |
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
return this._getValues(lang.hitch(this,this._matchValidator)); |
| 603 |
}, |
| 604 |
|
| 605 |
_getMismatchedValueAttr: function(){ |
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
return this._getValues(lang.hitch(this,this._mismatchValidator)); |
| 611 |
}, |
| 612 |
|
| 613 |
_getValues: function( validator){ |
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
var value = []; |
| 619 |
validator = validator||this._nullValidator; |
| 620 |
for(var i in this._items){ |
| 621 |
var item = this._items[i]; |
| 622 |
if(item === null){ |
| 623 |
continue; |
| 624 |
} |
| 625 |
var itemValue = item.get("value"); |
| 626 |
if(validator(itemValue)){ |
| 627 |
value.push(itemValue); |
| 628 |
} |
| 629 |
} |
| 630 |
return value; |
| 631 |
}, |
| 632 |
|
| 633 |
_nullValidator: function( itemValue){ |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
return true; |
| 639 |
}, |
| 640 |
_matchValidator: function( itemValue){ |
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
var re = new RegExp(this.regExpGen(this.constraints)); |
| 646 |
return itemValue.match(re); |
| 647 |
}, |
| 648 |
_mismatchValidator: function( itemValue){ |
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
var re = new RegExp(this.regExpGen(this.constraints)); |
| 654 |
return !(itemValue.match(re)); |
| 655 |
}, |
| 656 |
|
| 657 |
_getLastItemAttr: function(){ |
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
return this._getSomeItem(); |
| 663 |
}, |
| 664 |
_getSomeItem: function( item, position){ |
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
item=item||false; |
| 670 |
position=position||"last"; |
| 671 |
|
| 672 |
var lastItem = null; |
| 673 |
var stop=-1; |
| 674 |
for(var i in this._items){ |
| 675 |
if(this._items[i] === null){ continue; } |
| 676 |
|
| 677 |
if(position=="before" && this._items[i] === item){ |
| 678 |
break; |
| 679 |
} |
| 680 |
|
| 681 |
lastItem = this._items[i]; |
| 682 |
|
| 683 |
if(position=="first" ||stop==0){ |
| 684 |
stop=1; |
| 685 |
break; |
| 686 |
} |
| 687 |
if(position=="after" && this._items[i] === item){ |
| 688 |
stop=0; |
| 689 |
} |
| 690 |
} |
| 691 |
if(position=="after" && stop==0){ |
| 692 |
lastItem = null; |
| 693 |
} |
| 694 |
return lastItem; |
| 695 |
}, |
| 696 |
_getPreviousItem: function( item){ |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
return this._getSomeItem(item,"before"); |
| 702 |
}, |
| 703 |
_getNextItem: function( item){ |
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
return this._getSomeItem(item,"after"); |
| 709 |
}, |
| 710 |
|
| 711 |
_destroyItem: function( item, updateValue){ |
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
this._items[item.index] = null; |
| 717 |
item.destroy(); |
| 718 |
this._count--; |
| 719 |
if(updateValue!==false){ |
| 720 |
this._updateValues(); |
| 721 |
this._setReadOnlyWhenMaxItemsReached(); |
| 722 |
} |
| 723 |
}, |
| 724 |
|
| 725 |
_updateValues: function(){ |
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
this.value = this._getValues(); |
| 731 |
this._setSelectNode(); |
| 732 |
}, |
| 733 |
|
| 734 |
_destroyAllItems: function(){ |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
for(var i in this._items){ |
| 740 |
if(this._items[i]==null){ continue; } |
| 741 |
this._destroyItem(this._items[i],false); |
| 742 |
} |
| 743 |
this._items = []; |
| 744 |
this._count = 0; |
| 745 |
this.value = null; |
| 746 |
this._setSelectNode(); |
| 747 |
this._setReadOnlyWhenMaxItemsReached(); |
| 748 |
}, |
| 749 |
|
| 750 |
destroy: function(){ |
| 751 |
|
| 752 |
|
| 753 |
this._destroyAllItems(); |
| 754 |
this._lastAddedItem = null; |
| 755 |
|
| 756 |
if(!this._input){ |
| 757 |
this._input.destroy(); |
| 758 |
} |
| 759 |
|
| 760 |
this.inherited(arguments); |
| 761 |
} |
| 762 |
}); |
| 763 |
|
| 764 |
var _ListInputInputItem = declare("dojox.form._ListInputInputItem", [Widget, TemplatedMixin], |
| 765 |
{ |
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
templateString: "<li class=\"dijit dijitReset dijitLeft dojoxListInputItem\" dojoAttachEvent=\"onclick: onClick\" ><span dojoAttachPoint=\"labelNode\"></span></li>", |
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
closeButtonNode: null, |
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
readOnlyItem: true, |
| 780 |
|
| 781 |
baseClass:"dojoxListInputItem", |
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
value: "", |
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
regExp: ".*", |
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
_editBox: null, |
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
_handleKeyDown: null, |
| 799 |
|
| 800 |
attributeMap: { |
| 801 |
value: { node: "labelNode", type: "innerHTML" } |
| 802 |
}, |
| 803 |
|
| 804 |
postMixInProperties: function(){ |
| 805 |
var _nlsResources = i18nCommon; |
| 806 |
lang.mixin(this, _nlsResources); |
| 807 |
this.inherited(arguments); |
| 808 |
}, |
| 809 |
|
| 810 |
postCreate: function(){ |
| 811 |
|
| 812 |
|
| 813 |
this.inherited(arguments); |
| 814 |
|
| 815 |
this.closeButtonNode = domConstruct.create("span",{ |
| 816 |
"class" : "dijitButtonNode dijitDialogCloseIcon", |
| 817 |
title : this.itemClose, |
| 818 |
onclick: lang.hitch(this, "onClose"), |
| 819 |
onmouseenter: lang.hitch(this, "_onCloseEnter"), |
| 820 |
onmouseleave: lang.hitch(this, "_onCloseLeave") |
| 821 |
}, this.domNode); |
| 822 |
|
| 823 |
domConstruct.create("span",{ |
| 824 |
"class" : "closeText", |
| 825 |
title : this.itemClose, |
| 826 |
innerHTML : "x" |
| 827 |
}, this.closeButtonNode); |
| 828 |
}, |
| 829 |
|
| 830 |
startup: function(){ |
| 831 |
|
| 832 |
|
| 833 |
this.inherited(arguments); |
| 834 |
this._createInlineEditBox(); |
| 835 |
}, |
| 836 |
|
| 837 |
_setReadOnlyItemAttr: function( value){ |
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
this.readOnlyItem = value; |
| 843 |
if(!value){ |
| 844 |
this._createInlineEditBox(); |
| 845 |
}else if(this._editBox){ |
| 846 |
this._editBox.set("disabled", true); |
| 847 |
} |
| 848 |
}, |
| 849 |
|
| 850 |
_createInlineEditBox: function(){ |
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
if(this.readOnlyItem){ return; } |
| 856 |
if(!this._started){ return; } |
| 857 |
if(this._editBox){ |
| 858 |
this._editBox.set("disabled",false); |
| 859 |
return; |
| 860 |
} |
| 861 |
this._editBox = new InlineEditBox({ |
| 862 |
value:this.value, |
| 863 |
editor: "dijit.form.ValidationTextBox", |
| 864 |
editorParams:{ |
| 865 |
regExp:this.regExp |
| 866 |
} |
| 867 |
},this.labelNode); |
| 868 |
this.connect(this._editBox,"edit","_onEdit"); |
| 869 |
this.connect(this._editBox,"onChange","_onCloseEdit"); |
| 870 |
this.connect(this._editBox,"onCancel","_onCloseEdit"); |
| 871 |
}, |
| 872 |
|
| 873 |
edit: function(){ |
| 874 |
|
| 875 |
|
| 876 |
if(!this.readOnlyItem){ |
| 877 |
this._editBox.edit(); |
| 878 |
} |
| 879 |
}, |
| 880 |
|
| 881 |
_onCloseEdit: function( value){ |
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
domClass.remove(this.closeButtonNode,this.baseClass + "Edited"); |
| 887 |
connect.disconnect(this._handleKeyDown); |
| 888 |
this.onChange(value); |
| 889 |
}, |
| 890 |
|
| 891 |
_onEdit: function(){ |
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
domClass.add(this.closeButtonNode,this.baseClass + "Edited"); |
| 897 |
this._handleKeyDown = connect.connect(this._editBox.editWidget,"_onKeyPress",this,"onKeyDown"); |
| 898 |
this.onEdit(); |
| 899 |
}, |
| 900 |
|
| 901 |
_setDisabledAttr: function( value){ |
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
if(!this.readOnlyItem){ |
| 907 |
this._editBox.set("disabled", value); |
| 908 |
} |
| 909 |
}, |
| 910 |
|
| 911 |
_getValueAttr: function(){ |
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
return (!this.readOnlyItem && this._started ? this._editBox.get("value") : this.value); |
| 917 |
}, |
| 918 |
|
| 919 |
destroy: function(){ |
| 920 |
|
| 921 |
|
| 922 |
if(this._editBox){ |
| 923 |
this._editBox.destroy(); |
| 924 |
} |
| 925 |
this.inherited(arguments); |
| 926 |
}, |
| 927 |
|
| 928 |
_onCloseEnter: function(){ |
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
domClass.add(this.closeButtonNode, "dijitDialogCloseIcon-hover"); |
| 934 |
}, |
| 935 |
|
| 936 |
_onCloseLeave: function(){ |
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
domClass.remove(this.closeButtonNode, "dijitDialogCloseIcon-hover"); |
| 942 |
}, |
| 943 |
|
| 944 |
onClose: function(){ |
| 945 |
|
| 946 |
|
| 947 |
}, |
| 948 |
|
| 949 |
onEdit: function(){ |
| 950 |
|
| 951 |
|
| 952 |
}, |
| 953 |
|
| 954 |
onClick: function(){ |
| 955 |
|
| 956 |
|
| 957 |
}, |
| 958 |
|
| 959 |
onChange: function( value){ |
| 960 |
|
| 961 |
|
| 962 |
}, |
| 963 |
|
| 964 |
|
| 965 |
onKeyDown: function( value){ |
| 966 |
|
| 967 |
|
| 968 |
} |
| 969 |
}); |
| 970 |
var _ListInputInputBox = declare("dojox.form._ListInputInputBox", [ValidationTextBox], |
| 971 |
{ |
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
minWidth:50, |
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
intermediateChanges:true, |
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
regExp: ".*", |
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
_sizer:null, |
| 994 |
|
| 995 |
onChange: function( value){ |
| 996 |
|
| 997 |
|
| 998 |
this.inherited(arguments); |
| 999 |
if(this._sizer === null){ |
| 1000 |
this._sizer = domConstruct.create("div",{ |
| 1001 |
style : { |
| 1002 |
position : "absolute", |
| 1003 |
left : "-10000px", |
| 1004 |
top : "-10000px" |
| 1005 |
} |
| 1006 |
},win.body()); |
| 1007 |
} |
| 1008 |
this._sizer.innerHTML = value; |
| 1009 |
var w = domGeometry.getContentBox(this._sizer).w + this.minWidth; |
| 1010 |
domGeometry.setContentSize(this.domNode,{ w : w }); |
| 1011 |
}, |
| 1012 |
|
| 1013 |
destroy: function(){ |
| 1014 |
|
| 1015 |
|
| 1016 |
domConstruct.destroy(this._sizer); |
| 1017 |
this.inherited(arguments); |
| 1018 |
} |
| 1019 |
}); |
| 1020 |
return ListInput; |
| 1021 |
}); |