summaryrefslogtreecommitdiff
path: root/js/dojo/dojox/mvc/_patches.js
blob: 326c734e359bfe53d03be44fbb0c810d9ce25631 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//>>built
define("dojox/mvc/_patches", [
	"dojo/_base/lang",
	"dojo/_base/array",
	"dijit/_WidgetBase",
	"./_DataBindingMixin",
	"dijit/form/ValidationTextBox",
	"dijit/form/NumberTextBox"
], function(lang, array, wb, dbm, vtb, ntb){
	/*=====
		vtb = dijit.form.ValidationTextBox;
		ntb = dijit.form.NumberTextBox;
		dbm = dojox.mvc._DataBindingMixin;
		wb = dijit._WidgetBase;
	=====*/

	//Apply the data binding mixin to all dijits, see mixin class description for details
	lang.extend(wb, new dbm());

	// monkey patch dijit._WidgetBase.startup to get data binds set up
	var oldWidgetBaseStartup = wb.prototype.startup;
	wb.prototype.startup = function(){
		this._dbstartup();
		oldWidgetBaseStartup.apply(this);
	};

	// monkey patch dijit._WidgetBase.destroy to remove watches setup in _DataBindingMixin
	var oldWidgetBaseDestroy = wb.prototype.destroy;
	wb.prototype.destroy = function(/*Boolean*/ preserveDom){
		if(this._modelWatchHandles){
			array.forEach(this._modelWatchHandles, function(h){ h.unwatch(); });
		}
		if(this._viewWatchHandles){
			array.forEach(this._viewWatchHandles, function(h){ h.unwatch(); });
		}
		oldWidgetBaseDestroy.apply(this, [preserveDom]);		
	};

	// monkey patch dijit.form.ValidationTextBox.isValid to check this.inherited for isValid
	var oldValidationTextBoxIsValid = vtb.prototype.isValid;
	vtb.prototype.isValid = function(/*Boolean*/ isFocused){
		return (this.inherited("isValid", arguments) !== false && oldValidationTextBoxIsValid.apply(this, [isFocused]));
	};

	// monkey patch dijit.form.NumberTextBox.isValid to check this.inherited for isValid
	var oldNumberTextBoxIsValid = ntb.prototype.isValid;
	ntb.prototype.isValid = function(/*Boolean*/ isFocused){
		return (this.inherited("isValid", arguments) !== false && oldNumberTextBoxIsValid.apply(this, [isFocused]));
	};
});