dojo MultipleEditor 类

用于DataGrid 编辑时,根据不同数据类型展现不同的编辑样式

dojo.provide("widget.MultipleEditor");
dojo.require("dojox.grid.cells.dijit");

dojo.declare(
				"widget.MultipleEditor",
				[ dojox.grid.cells._Widget ],
				{

					_types : {
						"number": {
						     widgetClass: dijit.form.NumberTextBox
						 },
						"bool" : {
							widgetClass : dijit.form.CheckBox
						},
						"string" : {
							widgetClass : dijit.form.TextBox
						},
						"date" : {
							widgetClass : dijit.form.DateTextBox
						},
						"combo" : {
							widgetClass : dijit.form.ComboBox
						},
						"select" : {
							widgetClass : dijit.form.FilteringSelect
						}
					},
					setType : function(type, typeProps) {
						this.type = type;
						this.widgetClass = this._types[type] ? this._types[type].widgetClass
								: this.widgetClass;
						var props = {};

						var wprops = typeProps ? typeProps
								: this._types[type].widgetProps;
						for ( var i in wprops) {
							if (dojo.getObject(wprops[i])) {
								props[i] = dojo.getObject(wprops[i]);
							} else {
								props[i] = wprops[i];
							}
						}
						this.widgetProps = this._types[type] ? props
								: this.widgetProps;
					},
					format : function(inRowIndex, inItem) {
						//console.log("format");
						var f, i = this.grid.edit.info;
						var d = this.get ? this.get(inRowIndex, inItem)
								: (this.value || this.defaultValue);
						var s = this.grid.store;
						this.editableProp = true;

						if (s.isItem(inItem)
								&& s.hasAttribute(inItem, "editable")) {
							this.editableProp = s.getValue(inItem, "editable");
						}

						if (this.editable
								&& (this.alwaysEditing || (i.rowIndex == inRowIndex && i.cell == this))
								&& this.editableProp) {
							try {
								var type = this.grid.store.getValue(inItem,
										"type"), typeProps = {};
								var tprops = this.grid.store.getValue(inItem,
										"typeProps");
								if (tprops) {
									typeProps = dojo.isObject(tprops) ? tprops
											: dojo.getObject(tprops) ? dojo
													.getObject(tprops)
													: typeProps;
								}
								if (type) {
									this.widget = null;
									this.value = null;
									delete typeProps._value;
									this.constraint = typeProps.constraint ? typeProps.constraint
											: {};
									this.setType(type, typeProps);

								}
							} catch (e) {
							}
							//console.log("formatEditing!!!!!!!");
							return this.formatEditing(d, inRowIndex);
						} else {

							var v = (d != this.defaultValue && (f = this.formatter)) ? f
									.call(this, d, inRowIndex)
									: d;
							if (!this.editableProp) {
								this.value = d;
								//this.widget = null;	
							}
							return (typeof v == "undefined" ? this.defaultValue
									: v);
						}
					},
					sizeWidget : function(_32, _33, _34) {
						if (this.type != "bool") {
							this.inherited(arguments);
						} else {
							return;
						}
					},
					setValue : function(_30, _31) {
						if (this.editableProp == false) {
							return;
						}
						if (this.type == "bool") {
							//console.log("set value!!!!!!!!!!!!");
							this.widget.attr("checked", _31);
						} else if (this.type == "date") {
							this.widget.attr("value", new Date(_31));
						} else {
							this.inherited(arguments);
						}
					},
					isEditable : function(rowIndex) {
						var item = this.grid.getItem(rowIndex);

						var s = this.grid.store;

						if (s.isItem(item) && s.hasAttribute(item, "editable")) {
							return s.getValue(item, "editable");
						} else {
							return true;
						}
					},
					getValue : function(rowIndex) {
						//console.log("get value");
						if (this.isEditable(rowIndex) == false) {
							var item = this.grid.getItem(rowIndex);
							return this.grid.store.getValue(item, "value");
						}

						var val = this.widget ? this.widget.attr('value')
								|| this.value : this.value;

						if (this.type == "bool") {
							return this.widget.attr("checked");
						} else if (this.type == "date") {

							return val ? dojo.isString(val) ? val
									: dojo.date.locale.format(val,
											this.widget.constraints)
									: dojo.date.locale.format(new Date(),
											this.widget.constraints);
						} else if (this.type == "number") {
							return val ? val : 0;
						} else if (this.type == "select") {
							return val ? val : "";
						} else {
							return this.inherited(arguments);
						}
					},
					markupFactory : function() {
						this.inherited(arguments);
					},
					attachWidget : function(_d, _e, _f) {
						_d.appendChild(this.widget.domNode);
						this.setValue(_f, _e);
					},
					getWidgetProps : function(_2d) {
						if (this.type == "date") {

							var val = this.constraint.datePattern ? dojo.date.locale
									.parse(_2d, dojo.mixin(this.constraint, {
										selector : "date"
									}))
									: dojo.date.locale.parse(_2d, {
										datePattern : "dd/MM/yyyy",
										selector : "date"
									});
							return dojo.mixin(this.inherited(arguments), {
								value : val
							});
						} else {
							return this.inherited(arguments);
						}
					},
					formatNode : function(_10, _11, _12) {
						//console.log("formatNode ");
						//console.log(this.widget);
						//console.log("this!!!!!!!");
						//console.log(this);
						if (!this.widgetClass) {
							return _11;
						}

						if (!this.widget) {
							//console.log("create widget!!!!!");
							this.widget = this.createWidget.apply(this,
									arguments);
							if (this.type == "bool") {
								this.widget.attr("checked", _11 == "true"
										|| _11 == true ? true : false);
							}

						} else {
							//console.log("change widget value");
							this.attachWidget.apply(this, arguments);
						}

						this.sizeWidget.apply(this, arguments);
						this.focus();
						this.save();

					}
				});

数据类型:

({
    identifier: "prop",
    label: "prop",
    items: [{
        prop: "Left",
        group: "Properties",
        value: "",
                type:"date",
                typeProps:{_value:true,constraint:{_value:true,datePattern:"dd-MM-yyyy"}}
    }, {
        prop: "Top",
        group: "Properties",
        value: "50",
                editable:false,
                type:"number",
                typeProps :{_value:true,store:"ppcomboStore",searchAttr:"value",labelAttr:"label"}
    }, {
        prop: "Width",
        group: "Properties",
        value: "500",
                type:"string"
    }
})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值