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

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
@@ -83,8 +83,14 @@
83
83
  return {
84
84
  restrict: 'E',
85
85
  link: async function (scope, element, attrs, ngModelCtrl) {
86
-
87
- let options = scope.$eval(attrs.options) || {};
86
+ let options = {};
87
+
88
+ try {
89
+ options = JSON.parse(attrs.options);
90
+ } catch (e) {
91
+ console.error(e);
92
+ }
93
+
88
94
  const cronCalendarElement = $(element);
89
95
 
90
96
  const culture = navigator.language || navigator.userLanguage;
@@ -4183,26 +4189,95 @@
4183
4189
  });
4184
4190
  }
4185
4191
 
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);
4192
+ options.virtual.valueMapper = async function(options) {
4193
+ await waitRender();
4194
+
4195
+ $log.debug("valueMapper | " + attrs['id'] + " | " + options.value);
4196
+
4197
+ if (lastValueMapper && !lastValueMapper.completed) {
4198
+ $log.debug("valueMapper Canceling | " + lastValueMapper.value);
4199
+ lastValueMapper.canceled = true;
4200
+ }
4201
+
4202
+ lastValueMapper = options;
4203
+
4204
+ var _combobox = _options.combobox;
4205
+ if (options.canceled) {
4206
+ $log.debug("valueMapper CANCELED | " + options.value);
4207
+ return;
4208
+ }
4209
+
4210
+ if (options.value || options.value === "") {
4211
+ if(_combobox.options.optionLabel[_combobox.options.dataValueField] !== null && options.value === ""){
4212
+ options.completed = true;
4213
+ $log.debug("valueMapper.success | " + attrs['id'] + " | NULL");
4214
+ options.success(null);
4201
4215
  }
4202
- } catch (e) {
4216
+ else{
4217
+ _combobox.isEvaluating = true;
4218
+ var _dataSource = _options.dataSource.transport.options.cronappDatasource;
4219
+ if (options.value === undefined || options.value === null || options.value === "") {
4220
+ options.completed = true;
4221
+ $log.debug("valueMapper.success | " + attrs['id'] + " | NULL");
4222
+ options.success(null);
4223
+ _combobox.isEvaluating = false;
4224
+ } else {
4225
+ $log.debug("valueMapper.findObj | " + attrs['id'] + " | " + options.value);
4226
+ _dataSource.findObj([options.value], false, function(data) {
4227
+ options.completed = true;
4228
+
4229
+ if (options.canceled) {
4230
+ $log.debug("valueMapper CANCELED | " + options.value);
4231
+ _combobox.isEvaluating = false;
4232
+ return;
4233
+ }
4234
+ if (Array.isArray(data)) {
4235
+ data = data[0];
4236
+ }
4237
+ $log.debug("valueMapper.success | " + attrs['id'] + " | " + data);
4238
+ options.success(data);
4239
+ _combobox.isEvaluating = false;
4240
+
4241
+ if (select.changeCursor) {
4242
+ scope.safeApply(function() {
4243
+ if (options.canceled) {
4244
+ $log.debug("valueMapper CANCELED | " + options.value);
4245
+ return;
4246
+ }
4247
+ if (data != null) {
4248
+ var found = _goTo(_scope, _combobox, data);
4249
+ if (!found) {
4250
+ _dataSource.data.push(data);
4251
+ found = _goTo(_scope, _combobox, data);
4252
+ }
4253
+ if (found) {
4254
+ modelSetter(_scope, found[select.dataValueField]);
4255
+ }
4256
+ } else {
4257
+ modelSetter(_scope, null);
4258
+ }
4259
+ });
4260
+ } else {
4261
+ if (data == null) {
4262
+ modelSetter(_scope, null);
4263
+ }
4264
+ }
4265
+ }, function() {
4266
+ options.completed = true;
4267
+ if (options.canceled) {
4268
+ $log.debug("valueMapper CANCELED | " + options.value);
4269
+ _combobox.isEvaluating = false;
4270
+ return;
4271
+ }
4272
+ $log.debug("valueMapper.success | " + attrs['id'] + " | NULL");
4273
+ options.success(null);
4274
+ _combobox.isEvaluating = false;
4275
+ }, [combobox.options.dataValueField]);
4276
+ }
4277
+ }
4278
+ } else {
4279
+ $log.debug("valueMapper.success | " + attrs['id'] + " | NULL");
4203
4280
  options.success(null);
4204
- } finally {
4205
- combobox.isEvaluating = false;
4206
4281
  }
4207
4282
  };
4208
4283
  }
@@ -4216,42 +4291,24 @@
4216
4291
  scope.safeApply(() => {
4217
4292
  var contextVars = {
4218
4293
  'selected' : dataItem,
4219
- 'selectedKey' : dataItem ? dataItem[options.dataValueField] : "",
4220
- 'selectedValue' : dataItem ? dataItem[options.dataTextField] : " "
4294
+ 'selectedKey' : dataItem[options.dataValueField],
4295
+ 'selectedValue' : dataItem[options.dataTextField]
4221
4296
  };
4222
- scope.$eval(attrs.ngChange, contextVars);
4297
+ scope.$eval(attrs.ngChange, contextVars);
4223
4298
  });
4224
4299
  } : undefined;
4225
4300
 
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) {
4301
+ options.close = attrs.ngClose ? function (){scope.$eval(attrs.ngClose)}: undefined;
4302
+ options.dataBound = attrs.ngDataBound ? function (){scope.$eval(attrs.ngDataBound)}: undefined;
4303
+ options.filtering = attrs.ngFiltering ? function (){scope.$eval(attrs.ngFiltering)}: undefined;
4304
+ options.open = function(e) {
4243
4305
  if (!dataSourceScreen.fetched || (dataSourceScreen.lastLoadedTime !== combobox.dataSource.lastLoadedTime)) {
4244
4306
  combobox.options.firstLazyRead = true;
4245
4307
  combobox.dataSource.read();
4246
4308
  combobox.dataSource.lastLoadedTime = dataSourceScreen.lastLoadedTime;
4247
4309
  }
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
- }
4253
4310
  };
4254
-
4311
+
4255
4312
  options.select = attrs.ngSelect ? function (e) {
4256
4313
  scope.safeApply(() => {
4257
4314
  var contextVars = {
@@ -4282,51 +4339,6 @@
4282
4339
  dataSourceScreen.__ignoreFirstFetch = true;
4283
4340
  }
4284
4341
  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
-
4330
4342
  options.combobox = combobox;
4331
4343
  $(combobox.element[0]).attr('tabindex','-1');
4332
4344
  if (dataSourceScreen != null && dataSourceScreen != undefined) {
@@ -4391,22 +4403,63 @@
4391
4403
  /**
4392
4404
  * Observa o read do datasource para setar o primeiro valor ou valor inicial.
4393
4405
  */
4394
- var defineInitialValue = function () {
4406
+ var defineInitialValue = function() {
4395
4407
  if (combobox.definingInitialValue) {
4396
4408
  return;
4397
4409
  }
4398
4410
  if (!combobox.isEvaluating) {
4399
- var currentValue = combobox.value();
4411
+ var currentValue = returnTypedValue(combobox.value());
4400
4412
  var nextValue = null;
4401
-
4402
- if (!currentValue || currentValue === "") {
4403
- nextValue = "";
4404
- modelSetter(scope, nextValue);
4405
- forceEmptyLineSelected();
4413
+
4414
+ var found = dataSourceScreen.goTo(currentValue);
4415
+
4416
+ if (!found) {
4417
+ if ((combobox.options.lazyFirstInitialValue || !dataSourceScreen.lazy) && select.initValue != undefined && select.initValue != null) {
4418
+ combobox.options.lazyFirstInitialValue = false;
4419
+ found = dataSourceScreen.goTo(select.initValue);
4420
+ if (found) {
4421
+ nextValue = select.initValue;
4422
+ }
4423
+ }
4424
+
4425
+
4426
+ if (nextValue == null && select.firstValue) {
4427
+ if (dataSourceScreen) {
4428
+ combobox.definingInitialValue = true;
4429
+ dataSourceScreen.fetch({
4430
+ params: {
4431
+ $top: 1
4432
+ }
4433
+ }, {
4434
+ success: function(data) {
4435
+ if (data.length) {
4436
+ dataSourceScreen.data.push(data[0]);
4437
+ nextValue = data[0][select.dataValueField];
4438
+ }
4439
+ modelSetter(_scope, nextValue);
4440
+ forceChangeModel(nextValue);
4441
+ combobox.definingInitialValue = false;
4442
+ },
4443
+ error: function() {
4444
+ combobox.definingInitialValue = false;
4445
+ },
4446
+ canceled: function() {
4447
+ combobox.definingInitialValue = false;
4448
+ }
4449
+ }, undefined, {lookup : true});
4450
+ }
4451
+ } else {
4452
+ modelSetter(_scope, nextValue);
4453
+ forceChangeModel(nextValue);
4454
+ combobox.definingInitialValue = false;
4455
+ }
4406
4456
  }
4407
4457
  }
4408
- };
4409
-
4458
+ else {
4459
+ setTimeout(()=>defineInitialValue(),300);
4460
+ }
4461
+ }
4462
+
4410
4463
  var _ngModelCtrl = ngModelCtrl;
4411
4464
  if (dataSourceScreen != null && dataSourceScreen != undefined) {
4412
4465
  dataSourceScreen.addDataSourceEvents({
@@ -4429,46 +4482,50 @@
4429
4482
  return;
4430
4483
  }
4431
4484
  _scope.$apply(function() {
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]);
4485
+ modelSetter(_scope, combobox.dataItem()[select.dataValueField]);
4486
+ modelTextFieldSetter(_scope, combobox.dataItem()[select.dataTextField]);
4487
+ if(select.changeValueBasedOnLabel){
4488
+ let comboLabelValue = combobox.dataItem()[select.dataTextField];
4489
+ // Try to eval it first in pure vanilla and then if it was not possible in angular context.
4490
+ try {
4491
+ eval(select.changeValueBasedOnLabel + '=' + '"' + comboLabelValue + '"');
4492
+ }catch (e) {
4493
+ try {
4494
+ _scope.$eval(select.changeValueBasedOnLabel + '=' + '"' + comboLabelValue + '"')
4495
+ }catch (e) {
4496
+ console.error("Não foi possível atribuir o texto do combobox ", comboLabelValue, " no compo informado ", select.changeValueBasedOnLabel);
4497
+ }
4498
+ }
4441
4499
  }
4442
-
4500
+
4443
4501
  _compileAngular(scope, options.combobox.element[0]);
4444
4502
  if (options?.combobox?.span) {
4445
4503
  _compileAngular(scope, options.combobox.span);
4446
4504
  }
4447
4505
  });
4448
- };
4449
-
4506
+
4507
+ }
4508
+
4450
4509
  applyChange();
4510
+
4451
4511
  });
4452
-
4512
+
4453
4513
  /**
4454
4514
  * Observando model do DropdownList.
4455
4515
  */
4456
4516
  if (ngModelCtrl) {
4457
4517
  ngModelCtrl.$formatters.push(function (value) {
4458
- if (value === undefined || value === "") {
4459
- value = "";
4460
- modelSetter(scope, value);
4461
- }
4462
- return value;
4463
- });
4464
-
4465
- ngModelCtrl.$parsers.push(function (value) {
4466
- if (!value || value === "") {
4467
- return "";
4518
+ $log.debug("$formatters | " + attrs['id'] + " | " + value);
4519
+ var x = combobox.value();
4520
+ if (value === undefined || (value === "" && select.optionLabelValue === undefined)) {
4521
+ value = null;
4522
+ modelSetter(_scope, value);
4468
4523
  }
4524
+ forceChangeModel(value);
4525
+
4469
4526
  return value;
4470
4527
  });
4471
-
4528
+
4472
4529
  ngModelCtrl.$parsers.push(function (value) {
4473
4530
  $log.debug("$parsers | " + attrs['id'] + " | " + value);
4474
4531
  if ((typeof value === 'boolean') || value) {
@@ -4503,11 +4560,9 @@
4503
4560
  select.initValue = null;
4504
4561
  }
4505
4562
 
4506
- if (select.initValue === null || select.initValue === "" || !select.initValue) {
4507
- combobox.value("");
4508
- modelSetter(_scope, "");
4563
+ if (select.initValue == '') {
4564
+ select.initValue = null;
4509
4565
  }
4510
-
4511
4566
 
4512
4567
  if (combobox.dataSource.transport && combobox.dataSource.transport.options) {
4513
4568
  combobox.dataSource.transport.options.combobox = combobox;
@@ -4555,7 +4610,7 @@
4555
4610
  }
4556
4611
  };
4557
4612
  })
4558
-
4613
+
4559
4614
  .directive('cronMultiSelect', function ($compile, $parse) {
4560
4615
  return {
4561
4616
  restrict: 'E',
@@ -5922,56 +5977,47 @@
5922
5977
  }
5923
5978
  })
5924
5979
 
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();
5980
+ .directive('crnInfiniteScroll', ['$compile', function($compile){
5981
+ 'use strict';
5982
+ return {
5983
+ restrict: 'EA',
5984
+ link: function(scope, element, attrs) {
5985
+ var dataSource = attrs.crnInfiniteScroll ? eval(attrs.crnInfiniteScroll) : attrs.crnDatasource ? eval(attrs.crnDatasource): undefined;
5986
+ if (dataSource) {
5987
+ let nextPageInfinite = {
5988
+ isVisible: false,
5989
+ checkVisibility: function(visible) {
5990
+ if (nextPageInfinite.isVisible !== visible) {
5991
+ nextPageInfinite.isVisible = visible;
5992
+ if (nextPageInfinite.isVisible) {
5993
+ if (dataSource.loaded && dataSource.loadedFinish) {
5994
+ dataSource.nextPage();
5995
+ } else {
5996
+ let intervalNextPage = setInterval(function() {
5997
+ if (dataSource.loaded && dataSource.loadedFinish) {
5998
+ dataSource.nextPage();
5999
+ clearInterval(intervalNextPage);
6000
+ }
6001
+ }, 250);
5959
6002
  }
5960
6003
  }
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
+ }
6005
+ },
6006
+ eventScroll: function() {
6007
+ var topElem = element.offset().top;
6008
+ var botElem = element.offset().top + element.outerHeight();
6009
+ var botScrn = $(window).scrollTop() + $(window).innerHeight();
6010
+ var topScrn = $(window).scrollTop();
6011
+ nextPageInfinite.checkVisibility((botScrn > topElem) && (topScrn < botElem));
5970
6012
  }
5971
- }
5972
- };
6013
+ };
6014
+ $(window).scroll(nextPageInfinite.eventScroll);
6015
+ $(window).ready(nextPageInfinite.eventScroll);
6016
+ }
5973
6017
  }
5974
- ]);
6018
+ }
6019
+ }])
6020
+
5975
6021
  }(app));
5976
6022
 
5977
6023
  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.53",
3
+ "version": "3.0.0-SP.55",
4
4
  "description": "Javascript library for CronApp's projects",
5
5
  "main": "cronapp.framework.js",
6
6
  "scripts": {