react-hook-core 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/components.js CHANGED
@@ -117,7 +117,7 @@ var ViewComponent = (function (_super) {
117
117
  ViewComponent.prototype.handleNotFound = function (form) {
118
118
  var msg = core_2.message(this.resourceService.value, 'error_not_found', 'error');
119
119
  if (form) {
120
- formutil_1.readOnly(form);
120
+ formutil_1.setReadOnly(form);
121
121
  }
122
122
  this.showError(msg.message, msg.title);
123
123
  };
@@ -300,9 +300,6 @@ var BaseSearchComponent = (function (_super) {
300
300
  _this.tmpPageIndex = 1;
301
301
  _this.pageMaxSize = 7;
302
302
  _this.pageSizes = core_2.pageSizes;
303
- _this.viewable = true;
304
- _this.addable = true;
305
- _this.editable = true;
306
303
  _this.pageSizeOnClick = function () {
307
304
  _this.setState(function (prevState) { return ({ isPageSizeOpenDropDown: !prevState.isPageSizeOpenDropDown }); });
308
305
  };
@@ -645,7 +642,6 @@ var BaseEditComponent = (function (_super) {
645
642
  _this.loading = loading;
646
643
  _this.backOnSuccess = true;
647
644
  _this.patchable = true;
648
- _this.addable = true;
649
645
  _this.create = function (event) {
650
646
  if (event) {
651
647
  event.preventDefault();
@@ -714,7 +710,7 @@ var BaseEditComponent = (function (_super) {
714
710
  BaseEditComponent.prototype.handleNotFound = function (form) {
715
711
  var msg = core_2.message(this.resourceService.value, 'error_not_found', 'error');
716
712
  if (form) {
717
- formutil_1.readOnly(form);
713
+ formutil_1.setReadOnly(form);
718
714
  }
719
715
  this.showError(msg.message, msg.title);
720
716
  };
@@ -736,7 +732,7 @@ var BaseEditComponent = (function (_super) {
736
732
  objSet[modelName] = model;
737
733
  this.setState(objSet, function () {
738
734
  if (_this.readOnly) {
739
- formutil_1.readOnly(f);
735
+ formutil_1.setReadOnly(f);
740
736
  }
741
737
  });
742
738
  };
@@ -753,45 +749,33 @@ var BaseEditComponent = (function (_super) {
753
749
  BaseEditComponent.prototype.onSave = function (isBack) {
754
750
  var _this = this;
755
751
  var r = this.resourceService;
756
- if (this.newMode && !this.addable) {
757
- var m = core_2.message(r.value, 'error_permission_add', 'error_permission');
758
- this.showError(m.message, m.title);
752
+ if (this.running) {
759
753
  return;
760
754
  }
761
- else if (!this.newMode && this.readOnly) {
762
- var msg = core_2.message(r.value, 'error_permission_edit', 'error_permission');
763
- this.showError(msg.message, msg.title);
764
- return;
755
+ var com = this;
756
+ var obj = com.getModel();
757
+ if (this.newMode) {
758
+ com.validate(obj, function () {
759
+ var msg = core_2.message(r.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
760
+ _this.confirm(msg.message, msg.title, function () {
761
+ com.doSave(obj, obj, isBack);
762
+ }, msg.no, msg.yes);
763
+ });
765
764
  }
766
765
  else {
767
- if (this.running) {
768
- return;
766
+ var diffObj_1 = reflect_1.makeDiff(edit_1.initPropertyNullInModel(this.orginalModel, this.metadata), obj, this.keys, this.version);
767
+ var keys = Object.keys(diffObj_1);
768
+ if (keys.length === 0) {
769
+ this.showMessage(r.value('msg_no_change'));
769
770
  }
770
- var com_2 = this;
771
- var obj_1 = com_2.getModel();
772
- if (this.newMode) {
773
- com_2.validate(obj_1, function () {
771
+ else {
772
+ com.validate(obj, function () {
774
773
  var msg = core_2.message(r.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
775
774
  _this.confirm(msg.message, msg.title, function () {
776
- com_2.doSave(obj_1, obj_1, isBack);
775
+ com.doSave(obj, diffObj_1, isBack);
777
776
  }, msg.no, msg.yes);
778
777
  });
779
778
  }
780
- else {
781
- var diffObj_1 = reflect_1.makeDiff(edit_1.initPropertyNullInModel(this.orginalModel, this.metadata), obj_1, this.keys, this.version);
782
- var keys = Object.keys(diffObj_1);
783
- if (keys.length === 0) {
784
- this.showMessage(r.value('msg_no_change'));
785
- }
786
- else {
787
- com_2.validate(obj_1, function () {
788
- var msg = core_2.message(r.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
789
- _this.confirm(msg.message, msg.title, function () {
790
- com_2.doSave(obj_1, diffObj_1, isBack);
791
- }, msg.no, msg.yes);
792
- });
793
- }
794
- }
795
779
  }
796
780
  };
797
781
  BaseEditComponent.prototype.validate = function (obj, callback) {
@@ -937,45 +921,45 @@ var EditComponent = (function (_super) {
937
921
  var _this = this;
938
922
  var id = _id;
939
923
  if (id != null && id !== '') {
940
- var com_3 = this;
924
+ var com_2 = this;
941
925
  this.running = true;
942
- core_1.showLoading(com_3.loading);
926
+ core_1.showLoading(com_2.loading);
943
927
  this.service.load(id).then(function (obj) {
944
928
  if (!obj) {
945
- com_3.handleNotFound(_this.form);
929
+ com_2.handleNotFound(_this.form);
946
930
  }
947
931
  else {
948
- com_3.newMode = false;
949
- com_3.orginalModel = reflect_1.clone(obj);
932
+ com_2.newMode = false;
933
+ com_2.orginalModel = reflect_1.clone(obj);
950
934
  if (!callback) {
951
- com_3.showModel(obj);
935
+ com_2.showModel(obj);
952
936
  }
953
937
  else {
954
- callback(obj, com_3.showModel);
938
+ callback(obj, com_2.showModel);
955
939
  }
956
940
  }
957
- com_3.running = false;
958
- core_1.hideLoading(com_3.loading);
941
+ com_2.running = false;
942
+ core_1.hideLoading(com_2.loading);
959
943
  }).catch(function (err) {
960
944
  var data = (err && err.response) ? err.response : err;
961
- var r = com_3.resourceService;
945
+ var r = com_2.resourceService;
962
946
  var gv = r.value;
963
947
  var title = gv('error');
964
948
  var msg = gv('error_internal');
965
949
  if (data && data.status === 404) {
966
- com_3.handleNotFound(com_3.form);
950
+ com_2.handleNotFound(com_2.form);
967
951
  }
968
952
  else {
969
953
  if (data.status && !isNaN(data.status)) {
970
954
  msg = core_2.messageByHttpStatus(data.status, gv);
971
955
  }
972
956
  if (data && (data.status === 401 || data.status === 403)) {
973
- formutil_1.readOnly(com_3.form);
957
+ formutil_1.setReadOnly(com_2.form);
974
958
  }
975
- com_3.showError(msg, title);
959
+ com_2.showError(msg, title);
976
960
  }
977
- com_3.running = false;
978
- core_1.hideLoading(com_3.loading);
961
+ com_2.running = false;
962
+ core_1.hideLoading(com_2.loading);
979
963
  });
980
964
  }
981
965
  else {
@@ -1142,32 +1126,32 @@ var DiffApprComponent = (function (_super) {
1142
1126
  var id = _id;
1143
1127
  if (id != null && id !== '') {
1144
1128
  this.id = _id;
1145
- var com_4 = this;
1129
+ var com_3 = this;
1146
1130
  this.running = true;
1147
1131
  core_1.showLoading(this.loading);
1148
1132
  this.service.diff(id).then(function (dobj) {
1149
1133
  if (!dobj) {
1150
- com_4.handleNotFound();
1134
+ com_3.handleNotFound();
1151
1135
  }
1152
1136
  else {
1153
- var formatdDiff = diff_1.formatDiffModel(dobj, com_4.formatFields);
1154
- com_4.setState({
1137
+ var formatdDiff = diff_1.formatDiffModel(dobj, com_3.formatFields);
1138
+ com_3.setState({
1155
1139
  origin: formatdDiff.origin,
1156
1140
  value: formatdDiff.value
1157
- }, com_4.format);
1141
+ }, com_3.format);
1158
1142
  }
1159
- com_4.running = false;
1160
- core_1.hideLoading(com_4.loading);
1143
+ com_3.running = false;
1144
+ core_1.hideLoading(com_3.loading);
1161
1145
  }).catch(function (err) {
1162
1146
  var data = (err && err.response) ? err.response : err;
1163
1147
  if (data && data.status === 404) {
1164
- com_4.handleNotFound();
1148
+ com_3.handleNotFound();
1165
1149
  }
1166
1150
  else {
1167
- core_2.error(err, com_4.resourceService.value, com_4.showError);
1151
+ core_2.error(err, com_3.resourceService.value, com_3.showError);
1168
1152
  }
1169
- com_4.running = false;
1170
- core_1.hideLoading(com_4.loading);
1153
+ com_3.running = false;
1154
+ core_1.hideLoading(com_3.loading);
1171
1155
  });
1172
1156
  }
1173
1157
  };
package/lib/formutil.js CHANGED
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- function readOnly(form) {
3
+ function setReadOnly(form) {
4
+ var args = [];
5
+ for (var _i = 1; _i < arguments.length; _i++) {
6
+ args[_i - 1] = arguments[_i];
7
+ }
4
8
  if (!form) {
5
9
  return;
6
10
  }
@@ -8,34 +12,44 @@ function readOnly(form) {
8
12
  for (var i = 0; i < len; i++) {
9
13
  var ctrl = form[i];
10
14
  var name_1 = ctrl.getAttribute('name');
15
+ var skip = false;
11
16
  if (name_1 != null && name_1.length > 0 && name_1 !== 'btnBack') {
12
- var nodeName = ctrl.nodeName;
13
- var type = ctrl.getAttribute('type');
14
- if (nodeName === 'INPUT' && type !== null) {
15
- nodeName = type.toUpperCase();
16
- }
17
- if (nodeName !== 'BUTTON'
18
- && nodeName !== 'RESET'
19
- && nodeName !== 'SUBMIT'
20
- && nodeName !== 'SELECT') {
21
- switch (type) {
22
- case 'checkbox':
23
- ctrl.disabled = true;
24
- break;
25
- case 'radio':
26
- ctrl.disabled = true;
27
- break;
28
- default:
29
- ctrl.readOnly = true;
17
+ if (arguments.length > 1) {
18
+ for (var j = 1; j < arguments.length; j++) {
19
+ if (arguments[j] === name_1) {
20
+ skip = true;
21
+ }
30
22
  }
31
23
  }
32
- else {
33
- ctrl.disabled = true;
24
+ if (skip === false) {
25
+ var nodeName = ctrl.nodeName;
26
+ var type = ctrl.getAttribute('type');
27
+ if (nodeName === 'INPUT' && type !== null) {
28
+ nodeName = type.toUpperCase();
29
+ }
30
+ if (nodeName !== 'BUTTON'
31
+ && nodeName !== 'RESET'
32
+ && nodeName !== 'SUBMIT'
33
+ && nodeName !== 'SELECT') {
34
+ switch (type) {
35
+ case 'checkbox':
36
+ ctrl.disabled = true;
37
+ break;
38
+ case 'radio':
39
+ ctrl.disabled = true;
40
+ break;
41
+ default:
42
+ ctrl.readOnly = true;
43
+ }
44
+ }
45
+ else {
46
+ ctrl.disabled = true;
47
+ }
34
48
  }
35
49
  }
36
50
  }
37
51
  }
38
- exports.readOnly = readOnly;
52
+ exports.setReadOnly = setReadOnly;
39
53
  function focusFirstElement(form) {
40
54
  var i = 0;
41
55
  var len = form.length;