Permalink
Browse files

feat: grid组件使用comboRender及radioRender时可以直接在column上定义datasource

  • Loading branch information...
LiuYueKai committed Mar 9, 2017
1 parent 1152e8f commit 2cbbe2a4f76f9b04fea0553e667f9c4963ffaf40
Showing with 21,402 additions and 25,101 deletions.
  1. +3 −2 .babelrc
  2. +16,875 −16,311 dist/neoui-kero.js
  3. +10 −10 dist/neoui-kero.min.js
  4. +0 −79 lib/baseAdapter.js
  5. +0 −245 lib/checkbox.js
  6. +0 −126 lib/checkboxGroup.js
  7. +0 −102 lib/ckeditor.js
  8. +0 −119 lib/combobox.js
  9. +0 −1 lib/core.js
  10. +0 −99 lib/currency.js
  11. +0 −210 lib/datetime.js
  12. +0 −41 lib/enableMixin.js
  13. +0 −139 lib/float.js
  14. +0 −1,158 lib/grid.js
  15. +63 −114 lib/index.js
  16. +0 −80 lib/integer.js
  17. +83 −80 lib/keroa-baseAdapter.js
  18. +268 −267 lib/keroa-checkbox.js
  19. +97 −88 lib/keroa-ckeditor.js
  20. +119 −118 lib/keroa-combo.js
  21. +85 −88 lib/keroa-currency.js
  22. +342 −349 lib/keroa-datetimepicker.js
  23. +143 −146 lib/keroa-float.js
  24. +1,373 −1,413 lib/keroa-grid.js
  25. +96 −99 lib/keroa-integer.js
  26. +53 −49 lib/keroa-landLine.js
  27. +60 −51 lib/keroa-month.js
  28. +59 −50 lib/keroa-monthdate.js
  29. +185 −180 lib/keroa-multilang.js
  30. +112 −107 lib/keroa-pagination.js
  31. +67 −63 lib/keroa-password.js
  32. +45 −41 lib/keroa-percent.js
  33. +53 −49 lib/keroa-phoneNumber.js
  34. +48 −39 lib/keroa-progress.js
  35. +225 −226 lib/keroa-radio.js
  36. +67 −62 lib/keroa-string.js
  37. +73 −64 lib/keroa-switch.js
  38. +52 −43 lib/keroa-textarea.js
  39. +60 −59 lib/keroa-textfield.js
  40. +97 −100 lib/keroa-time.js
  41. +402 −397 lib/keroa-tree.js
  42. +65 −56 lib/keroa-url.js
  43. +57 −48 lib/keroa-year.js
  44. +56 −47 lib/keroa-yearmonth.js
  45. +0 −120 lib/link.js
  46. +0 −50 lib/month.js
  47. +0 −109 lib/multilang.js
  48. +0 −129 lib/native-checkbox.js
  49. +0 −98 lib/native-radio.js
  50. +0 −111 lib/pagination.js
  51. +0 −69 lib/password.js
  52. +0 −43 lib/percent.js
  53. +0 −24 lib/progress.js
  54. +0 −162 lib/radio.js
  55. +0 −32 lib/requiredMixin.js
  56. +0 −67 lib/string.js
  57. +0 −46 lib/switch.js
  58. +0 −24 lib/textarea.js
  59. +0 −54 lib/textfield.js
  60. +0 −69 lib/time.js
  61. +0 −365 lib/tree.js
  62. +0 −44 lib/u.js
  63. +0 −50 lib/url.js
  64. +0 −77 lib/validateMixin.js
  65. +0 −79 lib/valueMixin.js
  66. +0 −31 lib/year.js
  67. +0 −31 lib/yearmonth.js
  68. +1 −0 package.json
  69. +8 −2 src/keroa-grid.js
View
@@ -2,8 +2,9 @@
"presets": [
"es2015","stage-0"
],
- "plugins": [
+ "plugins": [
"transform-es3-property-literals",
- "transform-es3-member-expression-literals"
+ "transform-es3-member-expression-literals",
+ "babel-plugin-transform-es2015-modules-umd"
]
}
View

Large diffs are not rendered by default.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,79 +0,0 @@
-'use strict';
-
-Object.defineProperty(exports, "__esModule", {
- value: true
-});
-exports.BaseAdapter = undefined;
-
-var _class = require('neoui-sparrow/lib/class');
-
-var _util = require('neoui-sparrow/lib/util');
-
-/**
- * adapter基类
- */
-
-/**
- * Module : Kero adapter 基类
- * Author : Kvkens(yueming@yonyou.com)
- * Date : 2016-08-09 10:00:00
- */
-var BaseAdapter = _class.Class.create({
- /**
- *
- * @param comp
- * @param options
- * el: '#content', 对应的dom元素
- * options: {}, 配置
- * model:{} 模型,包括数据和事件
- */
- initialize: function initialize(options) {
- //组合mixin中的方法
- for (var i in this.mixins) {
- var mixin = this.mixins[i];
- for (var key in mixin['methods']) {
- if (!this[key]) {
- this[key] = mixin['methods'][key];
- }
- }
- }
-
- //this.comp = comp;
- this.element = options['el'];
- this.options = options['options'];
- this.viewModel = options['model'];
- this.dataModel = null;
- this.mixins = this.mixins || [];
- this.parseDataModel();
- this.init();
- //执行mixin中的初始化方法
- for (var i in this.mixins) {
- var mixin = this.mixins[i];
- if (mixin['init']) mixin.init.call(this);
- }
- },
- parseDataModel: function parseDataModel() {
- if (!this.options || !this.options["data"]) return;
- this.field = this.options["field"];
- var dtId = this.options["data"];
- this.dataModel = (0, _util.getJSObject)(this.viewModel, this.options["data"]);
- if (this.dataModel) {
- var opt = {};
- if (this.options.type === 'u-date') {
- opt.type = 'date';
- }
- if (this.field) this.dataModel.createField(this.field, opt);
- }
- },
- getOption: function getOption(key) {
- var rs = this.dataModel.getRowMeta(this.field, key);
- if (rs === 0) {
- return 0;
- } else {
- return rs || this.options[key];
- }
- },
- init: function init() {}
-});
-
-exports.BaseAdapter = BaseAdapter;
View
@@ -1,245 +0,0 @@
-'use strict';
-
-Object.defineProperty(exports, "__esModule", {
- value: true
-});
-exports.CheckboxAdapter = undefined;
-
-var _baseAdapter = require('./baseAdapter');
-
-var _valueMixin = require('./valueMixin');
-
-var _util = require('neoui-sparrow/lib/util');
-
-var _neouiCheckbox = require('neoui/lib/neoui-checkbox');
-
-var _compMgr = require('neoui-sparrow/lib/compMgr');
-
-/**
- * Module : Kero Check Adapter
- * Author : Kvkens(yueming@yonyou.com)
- * Date : 2016-08-08 15:50:03
- */
-
-var CheckboxAdapter = _baseAdapter.BaseAdapter.extend({
- mixins: [_valueMixin.ValueMixin, _valueMixin.EnableMixin, _valueMixin.RequiredMixin, _valueMixin.ValidateMixin],
- init: function init(options) {
- var self = this;
- // CheckboxAdapter.superclass.initialize.apply(this, arguments);
- this.isGroup = this.options['isGroup'] === true || this.options['isGroup'] === 'true';
- if (this.options['datasource'] || this.options['hasOther']) {
- // 存在datasource或者有其他选项,将当前dom元素保存,以后用于复制新的dom元素
- this.checkboxTemplateArray = [];
- for (var i = 0, count = this.element.childNodes.length; i < count; i++) {
- this.checkboxTemplateArray.push(this.element.childNodes[i]);
- }
- }
- if (this.options['datasource']) {
- this.isGroup = true;
- var datasource = (0, _util.getJSObject)(this.viewModel, this.options['datasource']);
-
- this.setComboData(datasource);
- } else {
- if (this.element['u.Checkbox']) {
- this.comp = this.element['u.Checkbox'];
- } else {
- this.comp = new _neouiCheckbox.Checkbox(this.element);
- this.element['u.Checkbox'] = this.comp;
- }
-
- this.checkedValue = this.options['checkedValue'] || this.comp._inputElement.value;
- this.unCheckedValue = this.options["unCheckedValue"];
-
- this.comp.on('change', function () {
- if (self.slice) return;
- if (!self.dataModel) return;
- var modelValue = self.dataModel.getValue(self.field);
- modelValue = modelValue ? modelValue : '';
- if (self.isGroup) {
- var valueArr = modelValue == '' ? [] : modelValue.split(',');
-
- if (self.comp._inputElement.checked) {
- valueArr.push(self.checkedValue);
- } else {
- var index = valueArr.indexOf(self.checkedValue);
- valueArr.splice(index, 1);
- }
- self.dataModel.setValue(self.field, valueArr.join(','));
- } else {
- if (self.comp._inputElement.checked) {
- self.dataModel.setValue(self.field, self.checkedValue);
- } else {
- self.dataModel.setValue(self.field, self.unCheckedValue);
- }
- }
- });
- }
- // 如果存在其他
- if (this.options['hasOther']) {
- var node = null;
- for (var j = 0; j < this.checkboxTemplateArray.length; j++) {
- this.element.appendChild(this.checkboxTemplateArray[j].cloneNode(true));
- }
- var LabelS = this.element.querySelectorAll('.u-checkbox');
- self.lastLabel = LabelS[LabelS.length - 1];
- var allCheckS = this.element.querySelectorAll('[type=checkbox]');
- self.lastCheck = allCheckS[allCheckS.length - 1];
- var nameDivs = this.element.querySelectorAll('[data-role=name]');
- self.lastNameDiv = nameDivs[nameDivs.length - 1];
- self.lastNameDiv.innerHTML = '其他';
- self.otherInput = makeDOM('<input type="text">');
- self.lastNameDiv.parentNode.appendChild(self.otherInput);
- self.lastCheck.value = '';
-
- var comp;
- if (self.lastLabel['u.Checkbox']) {
- comp = self.lastLabel['u.Checkbox'];
- } else {
- comp = new _neouiCheckbox.Checkbox(self.lastLabel);
- }
- self.lastLabel['u.Checkbox'] = comp;
- self.otherComp = comp;
- comp.on('change', function () {
- if (self.slice) return;
- var modelValue = self.dataModel.getValue(self.field);
- modelValue = modelValue ? modelValue : '';
- var valueArr = modelValue == '' ? [] : modelValue.split(',');
- if (comp._inputElement.checked) {
- var oldIndex = valueArr.indexOf(comp._inputElement.oldValue);
- if (oldIndex > -1) {
- valueArr.splice(oldIndex, 1);
- }
- if (comp._inputElement.value) valueArr.push(comp._inputElement.value);
- } else {
- var index = valueArr.indexOf(comp._inputElement.value);
- if (index > -1) {
- valueArr.splice(index, 1);
- }
- }
- //self.slice = true;
- self.dataModel.setValue(self.field, valueArr.join(','));
- //self.slice = false;
- });
-
- on(self.otherInput, 'blur', function (e) {
- self.lastCheck.oldValue = self.lastCheck.value;
- self.lastCheck.value = this.value;
- self.otherComp.trigger('change');
- });
- on(self.otherInput, 'click', function (e) {
- stopEvent(e);
- });
- }
-
- if (this.dataModel) {
- this.dataModel.ref(this.field).subscribe(function (value) {
- self.modelValueChange(value);
- });
- }
- },
- setComboData: function setComboData(comboData) {
- var self = this;
- //this.element.innerHTML = '';
- for (var i = 0, len = comboData.length; i < len - 1; i++) {
- for (var j = 0; j < this.checkboxTemplateArray.length; j++) {
- this.element.appendChild(this.checkboxTemplateArray[j].cloneNode(true));
- }
- }
- var allCheck = this.element.querySelectorAll('[type=checkbox]');
- var allName = this.element.querySelectorAll('[data-role=name]');
- for (var k = 0; k < allCheck.length; k++) {
- allCheck[k].value = comboData[k].pk || comboData[k].value;
- allName[k].innerHTML = comboData[k].name;
- }
- this.element.querySelectorAll('.u-checkbox').forEach(function (ele) {
- var comp;
- if (ele['u.Checkbox']) {
- comp = ele['u.Checkbox'];
- } else {
- comp = new _neouiCheckbox.Checkbox(ele);
- }
- ele['u.Checkbox'] = comp;
- comp.on('change', function () {
- if (self.slice) return;
- var modelValue = self.dataModel.getValue(self.field);
- modelValue = modelValue ? modelValue : '';
- var valueArr = modelValue == '' ? [] : modelValue.split(',');
- if (comp._inputElement.checked) {
- valueArr.push(comp._inputElement.value);
- } else {
- var index = valueArr.indexOf(comp._inputElement.value);
- valueArr.splice(index, 1);
- }
- //self.slice = true;
- self.dataModel.setValue(self.field, valueArr.join(','));
- //self.slice = false;
- });
- });
- },
- modelValueChange: function modelValueChange(val) {
- var self = this;
- if (this.slice) return;
-
- if (this.isGroup) {
- this.trueValue = val;
- if (this.options.hasOther) {
- otherVal = '';
- if (val) otherVal = val + ',';
- }
- this.element.querySelectorAll('.u-checkbox').forEach(function (ele) {
- var comp = ele['u.Checkbox'];
- var inputValue = comp._inputElement.value;
- if (inputValue && comp._inputElement.checked != (val + ',').indexOf(inputValue + ',') > -1) {
- self.slice = true;
- comp.toggle();
- self.slice = false;
- }
- if (inputValue && (val + ',').indexOf(inputValue + ',') > -1) {
- if (self.options.hasOther) {
- otherVal = otherVal.replace(inputValue + ',', '');
- }
- }
- });
- if (this.options.hasOther) {
- otherVal = otherVal.replace(/\,/g, '');
- if (otherVal) {
- self.lastCheck.value = otherVal;
- self.otherInput.value = otherVal;
- }
- }
- } else {
- if (this.comp._inputElement.checked != (val === this.checkedValue)) {
- this.slice = true;
- this.comp.toggle();
- this.slice = false;
- }
- }
- },
-
- setEnable: function setEnable(enable) {
- this.enable = enable === true || enable === 'true';
- if (this.isGroup) {
- this.element.querySelectorAll('.u-checkbox').forEach(function (ele) {
- var comp = ele['u.Checkbox'];
- if (enable === true || enable === 'true') {
- comp.enable();
- } else {
- comp.disable();
- }
- });
- } else {
- if (this.enable) {
- this.comp.enable();
- } else {
- this.comp.disable();
- }
- }
- }
-});
-
-_compMgr.compMgr.addDataAdapter({
- adapter: CheckboxAdapter,
- name: 'u-checkbox'
-});
-
-exports.CheckboxAdapter = CheckboxAdapter;
Oops, something went wrong.

0 comments on commit 2cbbe2a

Please sign in to comment.