cronapp-framework-js 3.0.0-SP.51 → 3.0.0-SP.53

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/js/directives.js CHANGED
@@ -4183,95 +4183,26 @@
4183
4183
  });
4184
4184
  }
4185
4185
 
4186
- options.virtual.valueMapper = async function(options) {
4187
- await waitRender();
4188
-
4189
- $log.debug("valueMapper | " + attrs['id'] + " | " + options.value);
4190
-
4191
- if (lastValueMapper && !lastValueMapper.completed) {
4192
- $log.debug("valueMapper Canceling | " + lastValueMapper.value);
4193
- lastValueMapper.canceled = true;
4194
- }
4195
-
4196
- lastValueMapper = options;
4197
-
4198
- var _combobox = _options.combobox;
4199
- if (options.canceled) {
4200
- $log.debug("valueMapper CANCELED | " + options.value);
4201
- return;
4202
- }
4203
-
4204
- if (options.value || options.value === "") {
4205
- if(_combobox.options.optionLabel[_combobox.options.dataValueField] !== null && options.value === ""){
4206
- options.completed = true;
4207
- $log.debug("valueMapper.success | " + attrs['id'] + " | NULL");
4208
- options.success(null);
4209
- }
4210
- else{
4211
- _combobox.isEvaluating = true;
4212
- var _dataSource = _options.dataSource.transport.options.cronappDatasource;
4213
- if (options.value === undefined || options.value === null || options.value === "") {
4214
- options.completed = true;
4215
- $log.debug("valueMapper.success | " + attrs['id'] + " | NULL");
4216
- options.success(null);
4217
- _combobox.isEvaluating = false;
4218
- } else {
4219
- $log.debug("valueMapper.findObj | " + attrs['id'] + " | " + options.value);
4220
- _dataSource.findObj([options.value], false, function(data) {
4221
- options.completed = true;
4222
-
4223
- if (options.canceled) {
4224
- $log.debug("valueMapper CANCELED | " + options.value);
4225
- _combobox.isEvaluating = false;
4226
- return;
4227
- }
4228
- if (Array.isArray(data)) {
4229
- data = data[0];
4230
- }
4231
- $log.debug("valueMapper.success | " + attrs['id'] + " | " + data);
4232
- options.success(data);
4233
- _combobox.isEvaluating = false;
4234
-
4235
- if (select.changeCursor) {
4236
- scope.safeApply(function() {
4237
- if (options.canceled) {
4238
- $log.debug("valueMapper CANCELED | " + options.value);
4239
- return;
4240
- }
4241
- if (data != null) {
4242
- var found = _goTo(_scope, _combobox, data);
4243
- if (!found) {
4244
- _dataSource.data.push(data);
4245
- found = _goTo(_scope, _combobox, data);
4246
- }
4247
- if (found) {
4248
- modelSetter(_scope, found[select.dataValueField]);
4249
- }
4250
- } else {
4251
- modelSetter(_scope, null);
4252
- }
4253
- });
4254
- } else {
4255
- if (data == null) {
4256
- modelSetter(_scope, null);
4257
- }
4258
- }
4259
- }, function() {
4260
- options.completed = true;
4261
- if (options.canceled) {
4262
- $log.debug("valueMapper CANCELED | " + options.value);
4263
- _combobox.isEvaluating = false;
4264
- return;
4265
- }
4266
- $log.debug("valueMapper.success | " + attrs['id'] + " | NULL");
4267
- options.success(null);
4268
- _combobox.isEvaluating = false;
4269
- }, [combobox.options.dataValueField]);
4270
- }
4186
+ options.virtual.valueMapper = async function (options) {
4187
+ if (!combobox || combobox.isEvaluating) return;
4188
+ combobox.isEvaluating = true;
4189
+
4190
+ var _dataSource = _options.dataSource.transport.options.cronappDatasource;
4191
+ $log.debug("valueMapper.findObj | " + attrs['id'] + " | " + options.value);
4192
+
4193
+ try {
4194
+ let currentValue = combobox.value();
4195
+
4196
+ let data = await _dataSource.findObj([options.value], false);
4197
+ if (Array.isArray(data)) data = data[0];
4198
+
4199
+ if (currentValue === combobox.value()) {
4200
+ options.success(data);
4271
4201
  }
4272
- } else {
4273
- $log.debug("valueMapper.success | " + attrs['id'] + " | NULL");
4202
+ } catch (e) {
4274
4203
  options.success(null);
4204
+ } finally {
4205
+ combobox.isEvaluating = false;
4275
4206
  }
4276
4207
  };
4277
4208
  }
@@ -4285,24 +4216,42 @@
4285
4216
  scope.safeApply(() => {
4286
4217
  var contextVars = {
4287
4218
  'selected' : dataItem,
4288
- 'selectedKey' : dataItem[options.dataValueField],
4289
- 'selectedValue' : dataItem[options.dataTextField]
4219
+ 'selectedKey' : dataItem ? dataItem[options.dataValueField] : "",
4220
+ 'selectedValue' : dataItem ? dataItem[options.dataTextField] : " "
4290
4221
  };
4291
- scope.$eval(attrs.ngChange, contextVars);
4222
+ scope.$eval(attrs.ngChange, contextVars);
4292
4223
  });
4293
4224
  } : undefined;
4294
4225
 
4295
- options.close = attrs.ngClose ? function (){scope.$eval(attrs.ngClose)}: undefined;
4296
- options.dataBound = attrs.ngDataBound ? function (){scope.$eval(attrs.ngDataBound)}: undefined;
4297
- options.filtering = attrs.ngFiltering ? function (){scope.$eval(attrs.ngFiltering)}: undefined;
4298
- options.open = function(e) {
4226
+
4227
+ options.close = attrs.ngClose ? function () {
4228
+ scope.$eval(attrs.ngClose);
4229
+ } : undefined;
4230
+
4231
+ options.dataBound = function () {
4232
+ if (!scope.$$phase && !scope.$root.$$phase) {
4233
+ _compileAngular(scope, combobox.element[0]);
4234
+ }
4235
+ };
4236
+
4237
+
4238
+ options.filtering = attrs.ngFiltering ? function () {
4239
+ scope.$eval(attrs.ngFiltering);
4240
+ } : undefined;
4241
+
4242
+ options.open = function (e) {
4299
4243
  if (!dataSourceScreen.fetched || (dataSourceScreen.lastLoadedTime !== combobox.dataSource.lastLoadedTime)) {
4300
4244
  combobox.options.firstLazyRead = true;
4301
4245
  combobox.dataSource.read();
4302
4246
  combobox.dataSource.lastLoadedTime = dataSourceScreen.lastLoadedTime;
4303
4247
  }
4248
+
4249
+ let emptyOption = { [combobox.options.dataValueField]: "", [combobox.options.dataTextField]: " " };
4250
+ if (!combobox.dataSource.data().some(item => item[combobox.options.dataValueField] === "")) {
4251
+ combobox.dataSource.add(emptyOption);
4252
+ }
4304
4253
  };
4305
-
4254
+
4306
4255
  options.select = attrs.ngSelect ? function (e) {
4307
4256
  scope.safeApply(() => {
4308
4257
  var contextVars = {
@@ -4333,6 +4282,51 @@
4333
4282
  dataSourceScreen.__ignoreFirstFetch = true;
4334
4283
  }
4335
4284
  var combobox = $element.kendoDropDownList(options).data('kendoDropDownList');
4285
+ combobox.isEvaluating = false;
4286
+
4287
+ function forceEmptyLineSelected() {
4288
+ var optionLabel = combobox.list.find('.k-list-optionlabel');
4289
+
4290
+ if (optionLabel && optionLabel.length) {
4291
+ optionLabel.addClass("k-state-selected k-state-focused");
4292
+ }
4293
+
4294
+ $log.debug("Linha vazia marcada como ativa:", optionLabel);
4295
+ }
4296
+
4297
+ var scrolling = false;
4298
+
4299
+ combobox.bind("open", function () {
4300
+ if (scrolling) return;
4301
+ scrolling = true;
4302
+
4303
+ setTimeout(() => {
4304
+ scrolling = false;
4305
+ }, 300);
4306
+ });
4307
+
4308
+ combobox.bind("change", function () {
4309
+ if (combobox.isEvaluating) return;
4310
+ combobox.isEvaluating = true;
4311
+
4312
+ try {
4313
+ let selectedItem = combobox.dataItem();
4314
+
4315
+ if (selectedItem && selectedItem[options.dataValueField] === "") {
4316
+ modelSetter(scope, "");
4317
+ modelTextFieldSetter(scope, " ");
4318
+ } else {
4319
+ modelSetter(scope, selectedItem[options.dataValueField]);
4320
+ modelTextFieldSetter(scope, selectedItem[options.dataTextField]);
4321
+ }
4322
+
4323
+ forceEmptyLineSelected();
4324
+ } finally {
4325
+ combobox.isEvaluating = false;
4326
+ }
4327
+ });
4328
+
4329
+
4336
4330
  options.combobox = combobox;
4337
4331
  $(combobox.element[0]).attr('tabindex','-1');
4338
4332
  if (dataSourceScreen != null && dataSourceScreen != undefined) {
@@ -4397,63 +4391,22 @@
4397
4391
  /**
4398
4392
  * Observa o read do datasource para setar o primeiro valor ou valor inicial.
4399
4393
  */
4400
- var defineInitialValue = function() {
4394
+ var defineInitialValue = function () {
4401
4395
  if (combobox.definingInitialValue) {
4402
4396
  return;
4403
4397
  }
4404
4398
  if (!combobox.isEvaluating) {
4405
- var currentValue = returnTypedValue(combobox.value());
4399
+ var currentValue = combobox.value();
4406
4400
  var nextValue = null;
4407
-
4408
- var found = dataSourceScreen.goTo(currentValue);
4409
-
4410
- if (!found) {
4411
- if ((combobox.options.lazyFirstInitialValue || !dataSourceScreen.lazy) && select.initValue != undefined && select.initValue != null) {
4412
- combobox.options.lazyFirstInitialValue = false;
4413
- found = dataSourceScreen.goTo(select.initValue);
4414
- if (found) {
4415
- nextValue = select.initValue;
4416
- }
4417
- }
4418
-
4419
-
4420
- if (nextValue == null && select.firstValue) {
4421
- if (dataSourceScreen) {
4422
- combobox.definingInitialValue = true;
4423
- dataSourceScreen.fetch({
4424
- params: {
4425
- $top: 1
4426
- }
4427
- }, {
4428
- success: function(data) {
4429
- if (data.length) {
4430
- dataSourceScreen.data.push(data[0]);
4431
- nextValue = data[0][select.dataValueField];
4432
- }
4433
- modelSetter(_scope, nextValue);
4434
- forceChangeModel(nextValue);
4435
- combobox.definingInitialValue = false;
4436
- },
4437
- error: function() {
4438
- combobox.definingInitialValue = false;
4439
- },
4440
- canceled: function() {
4441
- combobox.definingInitialValue = false;
4442
- }
4443
- }, undefined, {lookup : true});
4444
- }
4445
- } else {
4446
- modelSetter(_scope, nextValue);
4447
- forceChangeModel(nextValue);
4448
- combobox.definingInitialValue = false;
4449
- }
4401
+
4402
+ if (!currentValue || currentValue === "") {
4403
+ nextValue = "";
4404
+ modelSetter(scope, nextValue);
4405
+ forceEmptyLineSelected();
4450
4406
  }
4451
4407
  }
4452
- else {
4453
- setTimeout(()=>defineInitialValue(),300);
4454
- }
4455
- }
4456
-
4408
+ };
4409
+
4457
4410
  var _ngModelCtrl = ngModelCtrl;
4458
4411
  if (dataSourceScreen != null && dataSourceScreen != undefined) {
4459
4412
  dataSourceScreen.addDataSourceEvents({
@@ -4476,50 +4429,46 @@
4476
4429
  return;
4477
4430
  }
4478
4431
  _scope.$apply(function() {
4479
- modelSetter(_scope, combobox.dataItem()[select.dataValueField]);
4480
- modelTextFieldSetter(_scope, combobox.dataItem()[select.dataTextField]);
4481
- if(select.changeValueBasedOnLabel){
4482
- let comboLabelValue = combobox.dataItem()[select.dataTextField];
4483
- // Try to eval it first in pure vanilla and then if it was not possible in angular context.
4484
- try {
4485
- eval(select.changeValueBasedOnLabel + '=' + '"' + comboLabelValue + '"');
4486
- }catch (e) {
4487
- try {
4488
- _scope.$eval(select.changeValueBasedOnLabel + '=' + '"' + comboLabelValue + '"')
4489
- }catch (e) {
4490
- console.error("Não foi possível atribuir o texto do combobox ", comboLabelValue, " no compo informado ", select.changeValueBasedOnLabel);
4491
- }
4492
- }
4432
+ let selectedItem = combobox.dataItem();
4433
+
4434
+ if (!selectedItem || selectedItem[select.dataValueField] === "") {
4435
+ combobox.value("");
4436
+ modelSetter(_scope, "");
4437
+ modelTextFieldSetter(_scope, " ");
4438
+ } else {
4439
+ modelSetter(_scope, selectedItem[select.dataValueField]);
4440
+ modelTextFieldSetter(_scope, selectedItem[select.dataTextField]);
4493
4441
  }
4494
-
4442
+
4495
4443
  _compileAngular(scope, options.combobox.element[0]);
4496
4444
  if (options?.combobox?.span) {
4497
4445
  _compileAngular(scope, options.combobox.span);
4498
4446
  }
4499
4447
  });
4500
-
4501
- }
4502
-
4448
+ };
4449
+
4503
4450
  applyChange();
4504
-
4505
4451
  });
4506
-
4452
+
4507
4453
  /**
4508
4454
  * Observando model do DropdownList.
4509
4455
  */
4510
4456
  if (ngModelCtrl) {
4511
4457
  ngModelCtrl.$formatters.push(function (value) {
4512
- $log.debug("$formatters | " + attrs['id'] + " | " + value);
4513
- var x = combobox.value();
4514
- if (value === undefined || (value === "" && select.optionLabelValue === undefined)) {
4515
- value = null;
4516
- modelSetter(_scope, value);
4458
+ if (value === undefined || value === "") {
4459
+ value = "";
4460
+ modelSetter(scope, value);
4517
4461
  }
4518
- forceChangeModel(value);
4519
-
4520
4462
  return value;
4521
4463
  });
4522
-
4464
+
4465
+ ngModelCtrl.$parsers.push(function (value) {
4466
+ if (!value || value === "") {
4467
+ return "";
4468
+ }
4469
+ return value;
4470
+ });
4471
+
4523
4472
  ngModelCtrl.$parsers.push(function (value) {
4524
4473
  $log.debug("$parsers | " + attrs['id'] + " | " + value);
4525
4474
  if ((typeof value === 'boolean') || value) {
@@ -4554,9 +4503,11 @@
4554
4503
  select.initValue = null;
4555
4504
  }
4556
4505
 
4557
- if (select.initValue == '') {
4558
- select.initValue = null;
4506
+ if (select.initValue === null || select.initValue === "" || !select.initValue) {
4507
+ combobox.value("");
4508
+ modelSetter(_scope, "");
4559
4509
  }
4510
+
4560
4511
 
4561
4512
  if (combobox.dataSource.transport && combobox.dataSource.transport.options) {
4562
4513
  combobox.dataSource.transport.options.combobox = combobox;
@@ -4604,7 +4555,7 @@
4604
4555
  }
4605
4556
  };
4606
4557
  })
4607
-
4558
+
4608
4559
  .directive('cronMultiSelect', function ($compile, $parse) {
4609
4560
  return {
4610
4561
  restrict: 'E',
@@ -5971,54 +5922,56 @@
5971
5922
  }
5972
5923
  })
5973
5924
 
5974
- .directive('crnInfiniteScroll', ['$compile', function($compile) {
5975
- 'use strict';
5976
- return {
5977
- restrict: 'EA',
5978
- link: function(scope, element, attrs) {
5979
- var dataSource = scope.$eval(attrs.crnInfiniteScroll || attrs.crnDatasource);
5980
-
5981
- if (dataSource) {
5982
- let nextPageInfinite = {
5983
- isVisible: false,
5984
- checkVisibility: function() {
5985
- var topElem = element.offset().top;
5986
- var botElem = element.offset().top + element.outerHeight();
5987
- var botScrn = $(window).scrollTop() + $(window).innerHeight();
5988
- var topScrn = $(window).scrollTop();
5989
-
5990
- return (botScrn > topElem) && (topScrn < botElem);
5991
- },
5992
- eventScroll: function() {
5993
- let visible = nextPageInfinite.checkVisibility();
5994
-
5995
- if (visible && dataSource.loaded && dataSource.loadedFinish) {
5996
- dataSource.nextPage();
5997
- } else if (visible && !(dataSource.loaded && dataSource.loadedFinish)) {
5998
- let intervalNextPage = setInterval(function() {
5999
- if (dataSource.loaded && dataSource.loadedFinish) {
6000
- dataSource.nextPage();
6001
- clearInterval(intervalNextPage);
5925
+ .directive('crnInfiniteScroll', ['$compile', function($compile) {
5926
+ 'use strict';
5927
+ return {
5928
+ restrict: 'EA',
5929
+ link: function(scope, element, attrs) {
5930
+ var dataSource = scope.$eval(attrs.crnInfiniteScroll || attrs.crnDatasource);
5931
+
5932
+ if (dataSource) {
5933
+ let nextPageInfinite = {
5934
+ isVisible: false,
5935
+ isLoading: false,
5936
+
5937
+ checkVisibility: function() {
5938
+ var topElem = element.offset().top;
5939
+ var botElem = element.offset().top + element.outerHeight();
5940
+ var botScrn = $(window).scrollTop() + $(window).innerHeight();
5941
+ var topScrn = $(window).scrollTop();
5942
+
5943
+ return (botScrn > topElem) && (topScrn < botElem);
5944
+ },
5945
+
5946
+ loadNextPage: function() {
5947
+ if (!nextPageInfinite.isLoading && dataSource.loaded && dataSource.loadedFinish) {
5948
+ nextPageInfinite.isLoading = true;
5949
+ dataSource.nextPage().finally(() => {
5950
+ nextPageInfinite.isLoading = false;
5951
+ });
5952
+ }
5953
+ },
5954
+
5955
+ eventScroll: function() {
5956
+ let visible = nextPageInfinite.checkVisibility();
5957
+ if (visible) {
5958
+ nextPageInfinite.loadNextPage();
5959
+ }
6002
5960
  }
6003
- }, 250);
5961
+ };
5962
+
5963
+ $(window).on('scroll', nextPageInfinite.eventScroll);
5964
+ $(window).ready(nextPageInfinite.eventScroll);
5965
+ scope.$on('$destroy', function() {
5966
+ $(window).off('scroll', nextPageInfinite.eventScroll);
5967
+ });
5968
+ } else {
5969
+ console.error('DataSource não foi definido ou não está acessível.');
6004
5970
  }
6005
5971
  }
6006
5972
  };
6007
-
6008
- $(window).on('scroll', nextPageInfinite.eventScroll);
6009
- $(window).on('load', nextPageInfinite.eventScroll);
6010
-
6011
- scope.$on('$destroy', function() {
6012
- $(window).off('scroll', nextPageInfinite.eventScroll);
6013
- $(window).off('load', nextPageInfinite.eventScroll);
6014
- });
6015
- } else {
6016
- console.error('DataSource não foi definido ou não está acessível.');
6017
5973
  }
6018
- }
6019
- };
6020
- }])
6021
-
5974
+ ]);
6022
5975
  }(app));
6023
5976
 
6024
5977
  function maskDirectiveAsDate($compile, $translate, $parse) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cronapp-framework-js",
3
- "version": "3.0.0-SP.51",
3
+ "version": "3.0.0-SP.53",
4
4
  "description": "Javascript library for CronApp's projects",
5
5
  "main": "cronapp.framework.js",
6
6
  "scripts": {