cronapp-framework-js 3.1.0 → 3.2.0

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/controllers.js CHANGED
@@ -50,17 +50,15 @@ if (!window.hostApp) {
50
50
  return;
51
51
  }
52
52
 
53
- let headerValues = window.isUsingCookie() ? {
54
- 'Content-Type': 'application/x-www-form-urlencoded'
55
- } : {
56
- 'Content-Type': 'application/x-www-form-urlencoded',
57
- 'X-AUTH-TOKEN' : $location.search().token
58
- };
53
+ // O token vem como parametro do link de redefinição de senha, não pode usar cookie nesta requisição
59
54
  $http({
60
55
  method: 'POST',
61
56
  url: window.hostApp + 'auth/confirm-reset-password',
62
57
  data: $.param({password: passwordNew.value}),
63
- headers: headerValues
58
+ headers: {
59
+ 'Content-Type': 'application/x-www-form-urlencoded',
60
+ 'X-AUTH-TOKEN' : $location.search().token
61
+ }
64
62
  }).then(() => {
65
63
  Notification.info($translate.instant('ResetPasswordSuccess'));
66
64
  passwordNew.value = "";
package/js/directives.js CHANGED
@@ -4032,7 +4032,7 @@
4032
4032
  }
4033
4033
  };
4034
4034
  })
4035
-
4035
+
4036
4036
  .directive('cronDynamicSelect', function ($compile, $timeout, $parse, $translate, $log) {
4037
4037
  return {
4038
4038
  restrict: 'E',
@@ -4220,97 +4220,28 @@
4220
4220
  });
4221
4221
  }
4222
4222
 
4223
- options.virtual.valueMapper = async function(options) {
4224
- await waitRender();
4225
-
4226
- $log.debug("valueMapper | " + attrs['id'] + " | " + options.value);
4227
-
4228
- if (lastValueMapper && !lastValueMapper.completed) {
4229
- $log.debug("valueMapper Canceling | " + lastValueMapper.value);
4230
- lastValueMapper.canceled = true;
4231
- }
4232
-
4233
- lastValueMapper = options;
4234
-
4235
- var _combobox = _options.combobox;
4236
- if (options.canceled) {
4237
- $log.debug("valueMapper CANCELED | " + options.value);
4238
- return;
4239
- }
4240
-
4241
- if (options.value || options.value === "") {
4242
- if(_combobox.options.optionLabel[_combobox.options.dataValueField] !== null && options.value === ""){
4243
- options.completed = true;
4244
- $log.debug("valueMapper.success | " + attrs['id'] + " | NULL");
4245
- options.success(null);
4246
- }
4247
- else{
4248
- _combobox.isEvaluating = true;
4249
- var _dataSource = _options.dataSource.transport.options.cronappDatasource;
4250
- if (options.value === undefined || options.value === null || options.value === "") {
4251
- options.completed = true;
4252
- $log.debug("valueMapper.success | " + attrs['id'] + " | NULL");
4253
- options.success(null);
4254
- _combobox.isEvaluating = false;
4255
- } else {
4256
- $log.debug("valueMapper.findObj | " + attrs['id'] + " | " + options.value);
4257
- _dataSource.findObj([options.value], false, function(data) {
4258
- options.completed = true;
4259
-
4260
- if (options.canceled) {
4261
- $log.debug("valueMapper CANCELED | " + options.value);
4262
- _combobox.isEvaluating = false;
4263
- return;
4264
- }
4265
- if (Array.isArray(data)) {
4266
- data = data[0];
4267
- }
4268
- $log.debug("valueMapper.success | " + attrs['id'] + " | " + data);
4269
- options.success(data);
4270
- _combobox.isEvaluating = false;
4271
-
4272
- if (select.changeCursor) {
4273
- scope.safeApply(function() {
4274
- if (options.canceled) {
4275
- $log.debug("valueMapper CANCELED | " + options.value);
4276
- return;
4277
- }
4278
- if (data != null) {
4279
- var found = _goTo(_scope, _combobox, data);
4280
- if (!found) {
4281
- _dataSource.data.push(data);
4282
- found = _goTo(_scope, _combobox, data);
4283
- }
4284
- if (found) {
4285
- modelSetter(_scope, found[select.dataValueField]);
4286
- }
4287
- } else {
4288
- modelSetter(_scope, null);
4289
- }
4290
- });
4291
- } else {
4292
- if (data == null) {
4293
- modelSetter(_scope, null);
4294
- }
4295
- }
4296
- }, function() {
4297
- options.completed = true;
4298
- if (options.canceled) {
4299
- $log.debug("valueMapper CANCELED | " + options.value);
4300
- _combobox.isEvaluating = false;
4301
- return;
4302
- }
4303
- $log.debug("valueMapper.success | " + attrs['id'] + " | NULL");
4304
- options.success(null);
4305
- _combobox.isEvaluating = false;
4306
- }, [combobox.options.dataValueField]);
4307
- }
4223
+ options.virtual.valueMapper = async function (options) {
4224
+ if (!combobox || combobox.isEvaluating) return;
4225
+ combobox.isEvaluating = true;
4226
+
4227
+ var _dataSource = _options.dataSource.transport.options.cronappDatasource;
4228
+ $log.debug("valueMapper.findObj | " + attrs['id'] + " | " + options.value);
4229
+
4230
+ try {
4231
+ let currentValue = combobox.value();
4232
+
4233
+ let data = await _dataSource.findObj([options.value], false);
4234
+ if (Array.isArray(data)) data = data[0];
4235
+
4236
+ if (currentValue === combobox.value()) {
4237
+ options.success(data);
4308
4238
  }
4309
- } else {
4310
- $log.debug("valueMapper.success | " + attrs['id'] + " | NULL");
4239
+ } catch (e) {
4311
4240
  options.success(null);
4241
+ } finally {
4242
+ combobox.isEvaluating = false;
4312
4243
  }
4313
- };
4244
+ };
4314
4245
  }
4315
4246
 
4316
4247
  options.messages = {
@@ -4322,24 +4253,42 @@
4322
4253
  scope.safeApply(() => {
4323
4254
  var contextVars = {
4324
4255
  'selected' : dataItem,
4325
- 'selectedKey' : dataItem[options.dataValueField],
4326
- 'selectedValue' : dataItem[options.dataTextField]
4256
+ 'selectedKey' : dataItem ? dataItem[options.dataValueField] : "",
4257
+ 'selectedValue' : dataItem ? dataItem[options.dataTextField] : ""
4327
4258
  };
4328
- scope.$eval(attrs.ngChange, contextVars);
4259
+ scope.$eval(attrs.ngChange, contextVars);
4329
4260
  });
4330
4261
  } : undefined;
4331
4262
 
4332
- options.close = attrs.ngClose ? function (){scope.$eval(attrs.ngClose)}: undefined;
4333
- options.dataBound = attrs.ngDataBound ? function (){scope.$eval(attrs.ngDataBound)}: undefined;
4334
- options.filtering = attrs.ngFiltering ? function (){scope.$eval(attrs.ngFiltering)}: undefined;
4335
- options.open = function(e) {
4263
+
4264
+ options.close = attrs.ngClose ? function () {
4265
+ scope.$eval(attrs.ngClose);
4266
+ } : undefined;
4267
+
4268
+ options.dataBound = function () {
4269
+ if (!scope.$$phase && !scope.$root.$$phase) {
4270
+ _compileAngular(scope, combobox.element[0]);
4271
+ }
4272
+ };
4273
+
4274
+
4275
+ options.filtering = attrs.ngFiltering ? function () {
4276
+ scope.$eval(attrs.ngFiltering);
4277
+ } : undefined;
4278
+
4279
+ options.open = function (e) {
4336
4280
  if (!dataSourceScreen.fetched || (dataSourceScreen.lastLoadedTime !== combobox.dataSource.lastLoadedTime)) {
4337
4281
  combobox.options.firstLazyRead = true;
4338
4282
  combobox.dataSource.read();
4339
4283
  combobox.dataSource.lastLoadedTime = dataSourceScreen.lastLoadedTime;
4340
4284
  }
4285
+
4286
+ let emptyOption = { [combobox.options.dataValueField]: "", [combobox.options.dataTextField]: "" };
4287
+ if (!combobox.dataSource.data().some(item => item[combobox.options.dataValueField] === "")) {
4288
+ combobox.dataSource.add(emptyOption);
4289
+ }
4341
4290
  };
4342
-
4291
+
4343
4292
  options.select = attrs.ngSelect ? function (e) {
4344
4293
  scope.safeApply(() => {
4345
4294
  var contextVars = {
@@ -4370,6 +4319,49 @@
4370
4319
  dataSourceScreen.__ignoreFirstFetch = true;
4371
4320
  }
4372
4321
  var combobox = $element.kendoDropDownList(options).data('kendoDropDownList');
4322
+ combobox.isEvaluating = false;
4323
+
4324
+ function forceEmptyLineSelected() {
4325
+ var optionLabel = combobox.list.find('.k-list-optionlabel');
4326
+
4327
+ if (optionLabel && optionLabel.length) {
4328
+ optionLabel.addClass("k-state-selected k-state-focused");
4329
+ }
4330
+ $log.debug("Linha vazia marcada como ativa:", optionLabel);
4331
+ }
4332
+
4333
+ var scrolling = false;
4334
+
4335
+ combobox.bind("open", function () {
4336
+ if (scrolling) return;
4337
+ scrolling = true;
4338
+
4339
+ setTimeout(() => {
4340
+ scrolling = false;
4341
+ }, 300);
4342
+ });
4343
+
4344
+ combobox.bind("change", function () {
4345
+ if (combobox.isEvaluating) return;
4346
+ combobox.isEvaluating = true;
4347
+
4348
+ try {
4349
+ let selectedItem = combobox.dataItem();
4350
+
4351
+ if (selectedItem && selectedItem[options.dataValueField] === "") {
4352
+ modelSetter(scope, "");
4353
+ modelTextFieldSetter(scope, "");
4354
+ } else {
4355
+ modelSetter(scope, selectedItem[options.dataValueField]);
4356
+ modelTextFieldSetter(scope, selectedItem[options.dataTextField]);
4357
+ }
4358
+
4359
+ forceEmptyLineSelected();
4360
+ } finally {
4361
+ combobox.isEvaluating = false;
4362
+ }
4363
+ });
4364
+
4373
4365
  options.combobox = combobox;
4374
4366
  $(combobox.element[0]).attr('tabindex','-1');
4375
4367
  if (dataSourceScreen != null && dataSourceScreen != undefined) {
@@ -4434,63 +4426,22 @@
4434
4426
  /**
4435
4427
  * Observa o read do datasource para setar o primeiro valor ou valor inicial.
4436
4428
  */
4437
- var defineInitialValue = function() {
4429
+ var defineInitialValue = function () {
4438
4430
  if (combobox.definingInitialValue) {
4439
4431
  return;
4440
4432
  }
4441
4433
  if (!combobox.isEvaluating) {
4442
- var currentValue = returnTypedValue(combobox.value());
4434
+ var currentValue = combobox.value();
4443
4435
  var nextValue = null;
4444
-
4445
- var found = dataSourceScreen.goTo(currentValue);
4446
-
4447
- if (!found) {
4448
- if ((combobox.options.lazyFirstInitialValue || !dataSourceScreen.lazy) && select.initValue != undefined && select.initValue != null) {
4449
- combobox.options.lazyFirstInitialValue = false;
4450
- found = dataSourceScreen.goTo(select.initValue);
4451
- if (found) {
4452
- nextValue = select.initValue;
4453
- }
4454
- }
4455
-
4456
-
4457
- if (nextValue == null && select.firstValue) {
4458
- if (dataSourceScreen) {
4459
- combobox.definingInitialValue = true;
4460
- dataSourceScreen.fetch({
4461
- params: {
4462
- $top: 1
4463
- }
4464
- }, {
4465
- success: function(data) {
4466
- if (data.length) {
4467
- dataSourceScreen.data.push(data[0]);
4468
- nextValue = data[0][select.dataValueField];
4469
- }
4470
- modelSetter(_scope, nextValue);
4471
- forceChangeModel(nextValue);
4472
- combobox.definingInitialValue = false;
4473
- },
4474
- error: function() {
4475
- combobox.definingInitialValue = false;
4476
- },
4477
- canceled: function() {
4478
- combobox.definingInitialValue = false;
4479
- }
4480
- }, undefined, {lookup : true});
4481
- }
4482
- } else {
4483
- modelSetter(_scope, nextValue);
4484
- forceChangeModel(nextValue);
4485
- combobox.definingInitialValue = false;
4486
- }
4436
+
4437
+ if (!currentValue || currentValue === "") {
4438
+ nextValue = "";
4439
+ modelSetter(scope, nextValue);
4440
+ forceEmptyLineSelected();
4487
4441
  }
4488
4442
  }
4489
- else {
4490
- setTimeout(()=>defineInitialValue(),300);
4491
- }
4492
- }
4493
-
4443
+ };
4444
+
4494
4445
  var _ngModelCtrl = ngModelCtrl;
4495
4446
  if (dataSourceScreen != null && dataSourceScreen != undefined) {
4496
4447
  dataSourceScreen.addDataSourceEvents({
@@ -4513,50 +4464,46 @@
4513
4464
  return;
4514
4465
  }
4515
4466
  _scope.$apply(function() {
4516
- modelSetter(_scope, combobox.dataItem()[select.dataValueField]);
4517
- modelTextFieldSetter(_scope, combobox.dataItem()[select.dataTextField]);
4518
- if(select.changeValueBasedOnLabel){
4519
- let comboLabelValue = combobox.dataItem()[select.dataTextField];
4520
- // Try to eval it first in pure vanilla and then if it was not possible in angular context.
4521
- try {
4522
- eval(select.changeValueBasedOnLabel + '=' + '"' + comboLabelValue + '"');
4523
- }catch (e) {
4524
- try {
4525
- _scope.$eval(select.changeValueBasedOnLabel + '=' + '"' + comboLabelValue + '"')
4526
- }catch (e) {
4527
- console.error("Não foi possível atribuir o texto do combobox ", comboLabelValue, " no compo informado ", select.changeValueBasedOnLabel);
4528
- }
4529
- }
4467
+ let selectedItem = combobox.dataItem();
4468
+
4469
+ if (!selectedItem || selectedItem[select.dataValueField] === "") {
4470
+ combobox.value("");
4471
+ modelSetter(_scope, "");
4472
+ modelTextFieldSetter(_scope, "");
4473
+ } else {
4474
+ modelSetter(_scope, selectedItem[select.dataValueField]);
4475
+ modelTextFieldSetter(_scope, selectedItem[select.dataTextField]);
4530
4476
  }
4531
-
4477
+
4532
4478
  _compileAngular(scope, options.combobox.element[0]);
4533
4479
  if (options?.combobox?.span) {
4534
4480
  _compileAngular(scope, options.combobox.span);
4535
4481
  }
4536
4482
  });
4537
-
4538
- }
4539
-
4483
+ };
4484
+
4540
4485
  applyChange();
4541
-
4542
4486
  });
4543
-
4487
+
4544
4488
  /**
4545
4489
  * Observando model do DropdownList.
4546
4490
  */
4547
4491
  if (ngModelCtrl) {
4548
4492
  ngModelCtrl.$formatters.push(function (value) {
4549
- $log.debug("$formatters | " + attrs['id'] + " | " + value);
4550
- var x = combobox.value();
4551
- if (value === undefined || (value === "" && select.optionLabelValue === undefined)) {
4552
- value = null;
4553
- modelSetter(_scope, value);
4493
+ if (value === undefined || value === "") {
4494
+ value = "";
4495
+ modelSetter(scope, value);
4554
4496
  }
4555
- forceChangeModel(value);
4556
-
4557
4497
  return value;
4558
4498
  });
4559
-
4499
+
4500
+ ngModelCtrl.$parsers.push(function (value) {
4501
+ if (!value || value === "") {
4502
+ return "";
4503
+ }
4504
+ return value;
4505
+ });
4506
+
4560
4507
  ngModelCtrl.$parsers.push(function (value) {
4561
4508
  $log.debug("$parsers | " + attrs['id'] + " | " + value);
4562
4509
  if ((typeof value === 'boolean') || value) {
@@ -4591,9 +4538,11 @@
4591
4538
  select.initValue = null;
4592
4539
  }
4593
4540
 
4594
- if (select.initValue == '') {
4595
- select.initValue = null;
4541
+ if (select.initValue === null || select.initValue === "" || !select.initValue) {
4542
+ combobox.value("");
4543
+ modelSetter(_scope, "");
4596
4544
  }
4545
+
4597
4546
 
4598
4547
  if (combobox.dataSource.transport && combobox.dataSource.transport.options) {
4599
4548
  combobox.dataSource.transport.options.combobox = combobox;
@@ -4641,7 +4590,7 @@
4641
4590
  }
4642
4591
  };
4643
4592
  })
4644
-
4593
+
4645
4594
  .directive('cronMultiSelect', function ($compile, $parse) {
4646
4595
  return {
4647
4596
  restrict: 'E',
@@ -4651,6 +4600,15 @@
4651
4600
  var modelSetter = modelGetter.assign;
4652
4601
  var model = attrs['ngModel'];
4653
4602
 
4603
+ let jumpThread = () => {
4604
+ return new Promise((resolve) => {
4605
+ let jumpWait = setInterval(() => {
4606
+ clearInterval(jumpWait);
4607
+ resolve();
4608
+ });
4609
+ });
4610
+ };
4611
+
4654
4612
  var _self = this;
4655
4613
  var select = {};
4656
4614
  try {
@@ -4662,12 +4620,29 @@
4662
4620
  var _scope = scope;
4663
4621
  var _ngModelCtrl = ngModelCtrl;
4664
4622
 
4623
+ if (select.relationDataSource != null) {
4624
+ try {
4625
+ eval(select.relationDataSource.name);
4626
+ }
4627
+ catch (e) {
4628
+ await jumpThread();
4629
+ }
4630
+ }
4665
4631
  var relactionDS = {
4666
4632
  relationDataSource: (select.relationDataSource != null ? eval(select.relationDataSource.name) : null),
4667
4633
  relationField: (select.relationField != null ? select.relationField : '')
4668
4634
  }
4669
4635
 
4670
- var options = await app.kendoHelper.getConfigCombobox(select, scope);
4636
+ var options = undefined;
4637
+ try {
4638
+ eval(select.dataSourceScreen.name);
4639
+ options = await app.kendoHelper.getConfigCombobox(select, scope);
4640
+ }
4641
+ catch (e) {
4642
+ await jumpThread();
4643
+ options = await app.kendoHelper.getConfigCombobox(select, scope);
4644
+ }
4645
+
4671
4646
 
4672
4647
  try {
4673
4648
  delete options.dataSource.schema.model.id;
@@ -6008,16 +5983,16 @@
6008
5983
  }
6009
5984
  })
6010
5985
 
6011
- .directive('crnInfiniteScroll', ['$compile', function($compile){
5986
+ .directive('crnInfiniteScroll', ['$compile', function($compile) {
6012
5987
  'use strict';
6013
5988
  return {
6014
5989
  restrict: 'EA',
6015
5990
  link: function(scope, element, attrs) {
6016
- var dataSource = attrs.crnInfiniteScroll ? eval(attrs.crnInfiniteScroll) : attrs.crnDatasource ? eval(attrs.crnDatasource): undefined;
6017
- if (dataSource) {
6018
- let nextPageInfinite = {
6019
- isVisible: false,
6020
- checkVisibility: function(visible) {
5991
+ let nextPageInfinite = {
5992
+ isVisible: false,
5993
+ checkVisibility: function(visible) {
5994
+ var dataSource = attrs.crnInfiniteScroll ? scope.$eval(attrs.crnInfiniteScroll) : attrs.crnDatasource ? scope.$eval(attrs.crnDatasource): undefined;
5995
+ if (dataSource) {
6021
5996
  if (nextPageInfinite.isVisible !== visible) {
6022
5997
  nextPageInfinite.isVisible = visible;
6023
5998
  if (nextPageInfinite.isVisible) {
@@ -6033,21 +6008,21 @@
6033
6008
  }
6034
6009
  }
6035
6010
  }
6036
- },
6037
- eventScroll: function() {
6038
- var topElem = element.offset().top;
6039
- var botElem = element.offset().top + element.outerHeight();
6040
- var botScrn = $(window).scrollTop() + $(window).innerHeight();
6041
- var topScrn = $(window).scrollTop();
6042
- nextPageInfinite.checkVisibility((botScrn > topElem) && (topScrn < botElem));
6043
6011
  }
6044
- };
6045
- $(window).scroll(nextPageInfinite.eventScroll);
6046
- $(window).ready(nextPageInfinite.eventScroll);
6047
- }
6012
+ },
6013
+ eventScroll: function() {
6014
+ var topElem = element.offset().top;
6015
+ var botElem = element.offset().top + element.outerHeight();
6016
+ var botScrn = $(window).scrollTop() + $(window).innerHeight();
6017
+ var topScrn = $(window).scrollTop();
6018
+ nextPageInfinite.checkVisibility((botScrn > topElem) && (topScrn < botElem));
6019
+ }
6020
+ };
6021
+ $(window).scroll(nextPageInfinite.eventScroll);
6022
+ $(window).ready(nextPageInfinite.eventScroll);
6048
6023
  }
6049
- }
6050
- }])
6024
+ };
6025
+ }]);
6051
6026
 
6052
6027
  }(app));
6053
6028
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cronapp-framework-js",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Javascript library for CronApp's projects",
5
5
  "main": "cronapp.framework.js",
6
6
  "scripts": {