cronapi-js 3.2.1-SP.4 → 4.0.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/cronapi.js CHANGED
@@ -935,15 +935,24 @@ function cronapi() {
935
935
  'timezone': moment().utcOffset()
936
936
  };
937
937
 
938
- var resultData = $.ajax({
939
- type: 'POST',
938
+ // Make the POST request via $http
939
+ http({
940
+ method: 'POST',
940
941
  url: finalUrl,
941
- dataType: 'html',
942
- data : contentData,
942
+ data: contentData,
943
+ responseType: 'text',
943
944
  headers: headerValues,
944
- success : callbackSuccess,
945
- error : callbackError
946
- });
945
+ transformResponse: (value) => value
946
+ }).then(
947
+ function successCallback(response) {
948
+ // response.data will contain the server response
949
+ callbackSuccess(response.data);
950
+ },
951
+ function errorCallback(response) {
952
+ // Handle error; response might contain status and data
953
+ callbackError(response.data, response.status);
954
+ }
955
+ );
947
956
 
948
957
  };
949
958
  /**
@@ -1314,14 +1323,24 @@ function cronapi() {
1314
1323
 
1315
1324
  var header = Object.create(headers);
1316
1325
  header["Content-Type"] = contentType;
1317
- // Angular has a .run that inject X-AUTH-TOKEN, so we use JQuery
1318
- $.ajax({
1319
- method : method,
1320
- url : url,
1321
- data: params,
1322
- headers: header
1323
- }).done(this.cronapi.util.handleCallback(success).bind(this)).fail(this.cronapi.util.handleCallback(error.bind(this)));
1324
1326
 
1327
+ this.cronapi.$scope.http({
1328
+ method: method,
1329
+ url: url,
1330
+ data: params,
1331
+ headers: header,
1332
+ transformResponse: (value) => value
1333
+ }).then(
1334
+ function success(response) {
1335
+ this.cronapi.util.handleCallback(success)
1336
+ .bind(this)(response.data, response);
1337
+ }.bind(this),
1338
+
1339
+ function error(response) {
1340
+ this.cronapi.util.handleCallback(error)
1341
+ .bind(this)(response.data, response);
1342
+ }.bind(this)
1343
+ );
1325
1344
  };
1326
1345
 
1327
1346
 
@@ -6493,42 +6512,7 @@ function cronapi() {
6493
6512
  }
6494
6513
 
6495
6514
  this.cronapi.social.login = function (username, password, options) {
6496
- var item;
6497
- var baseUrl = this.cronapi.screen.getHostapp() ? `${this.cronapi.screen.getHostapp()}\auth` : `\auth`;
6498
- if (window.cordova && !this.cronapi.screen.getHostapp()) {
6499
- this.cronapi.screen.notify('error', 'HostApp is Required');
6500
- return;
6501
- }
6502
- this.cronapi.screen.showLoading();
6503
- this.cronapi.util.getURLFromOthers('POST',
6504
- 'application/x-www-form-urlencoded',
6505
- baseUrl,
6506
- this.cronapi.object.createObjectFromString(['{ \"username\": \"', username, '\" , \"password\": \"', password, '\" } '].join('')),
6507
- this.cronapi.object.createObjectFromString(['{ \"X-AUTH-TOKEN\": \"', options, '\" } '].join('')),
6508
- async (sender_item) => {
6509
- item = sender_item;
6510
- if (window.isUsingCookie()) {
6511
- delete item.token;
6512
- }
6513
- this.cronapi.screen.hide();
6514
- this.cronapi.util.setLocalStorage('_u', this.cronapi.object.serializeObject(item));
6515
- try {
6516
- if (this.cronapi.blockly.js.blockly.auth.Home.change) {
6517
- (await this.cronapi.client('blockly.js.blockly.auth.Home.change').run());
6518
- }
6519
- } catch (error) {
6520
- this.cronapi.screen.changeView("#/app/logged/home", []);
6521
- }
6522
- }, (sender_item) => {
6523
- item = sender_item;
6524
- if (this.cronapi.object.getProperty(item, 'status') == '403' || this.cronapi.object.getProperty(item, 'status') == '401') {
6525
- var messageLogin = this.cronapi.$translate.instant('Login.view.invalidPassword');
6526
- this.cronapi.screen.notify('error', messageLogin);
6527
- } else {
6528
- this.cronapi.screen.notify('error', this.cronapi.object.getProperty(item, 'responseJSON.message'));
6529
- }
6530
- this.cronapi.screen.hide();
6531
- });
6515
+ this.cronapi.$scope.login(username, password, options);
6532
6516
  }
6533
6517
 
6534
6518
  /**
@@ -6570,9 +6554,20 @@ function cronapi() {
6570
6554
  this.cronapi.social.ssoLogin = async function () {
6571
6555
  let scope = this.cronapi.$scope;
6572
6556
 
6557
+ let config = {
6558
+ method: "GET",
6559
+ url: this.cronapi.internal.getAddressWithHostApp("authproviders")
6560
+ };
6561
+
6562
+ let providers = await this.$http(config);
6563
+
6573
6564
  let future = new Promise((resolve, reject) => {
6565
+ let nextPage = "login";
6566
+ if (providers.data && providers.data.length == 1) {
6567
+ nextPage = providers.data[0].loginURL;
6568
+ }
6574
6569
  if (window.cordova && cordova.InAppBrowser) {
6575
- const ref = cordova.InAppBrowser.open(window.hostApp + 'login', '_blank', 'location=no,footer=yes,zoom=no,enableViewportScale=yes,hidenavigationbuttons=yes');
6570
+ const ref = cordova.InAppBrowser.open(this.cronapi.internal.getAddressWithHostApp(nextPage), '_blank', 'location=no,footer=yes,zoom=no,enableViewportScale=yes,hidenavigationbuttons=yes');
6576
6571
  const handlerChange = (event) => {
6577
6572
  const url = new URL(event.url);
6578
6573
  const urlParams = new URLSearchParams(url.search);
@@ -6584,7 +6579,7 @@ function cronapi() {
6584
6579
  ref.close();
6585
6580
 
6586
6581
  // If the page is reloaded the blockly sequence is interrupted
6587
- scope.login("#OAUTH#", "#OAUTH#", urlParams.get('_ctk'));
6582
+ scope.loginWithToken(urlParams.get('_ctk'));
6588
6583
  resolve();
6589
6584
 
6590
6585
  } else {
@@ -6594,24 +6589,9 @@ function cronapi() {
6594
6589
 
6595
6590
  ref.addEventListener('loadstart', handlerChange);
6596
6591
 
6597
- } else {
6598
- window.ssoWindow = window.open(this.cronapi.internal.getAddressWithHostApp("login"));
6599
-
6600
- window.addEventListener('message', function (e) {
6601
- if (e.data && e.data.type === 'sso_user') {
6602
-
6603
- // close sso window
6604
- if (window.ssoWindow) {
6605
- window.ssoWindow.close();
6606
- }
6607
-
6608
- // If the page is reloaded the blockly sequence is interrupted
6609
- scope.login("#OAUTH#", "#OAUTH#", e.data._ctk);
6610
- resolve();
6611
-
6612
- }
6613
- }, false);
6614
- }
6592
+ } else {
6593
+ window.location.href = this.cronapi.internal.getAddressWithHostApp(nextPage);
6594
+ }
6615
6595
  });
6616
6596
 
6617
6597
  return future;
@@ -7709,7 +7689,7 @@ function cronapi() {
7709
7689
  * @returns {ObjectType.VOID}
7710
7690
  */
7711
7691
  this.cronapi.authentication.login = function(/** @type {ObjectType.STRING} **/ username,/** @type {ObjectType.STRING} **/ password, /** @type {ObjectType.OBJECT} **/options) {
7712
- this.cronapi.social.login(username, password, options);
7692
+ this.cronapi.$scope.login(username, password, options);
7713
7693
  }
7714
7694
 
7715
7695
  /**
@@ -8271,7 +8251,27 @@ function cronapi() {
8271
8251
 
8272
8252
  const audioRecorded = await mediaPromise;
8273
8253
  return audioRecorded;
8274
- };
8254
+ };
8255
+
8256
+ /**
8257
+ * @type function
8258
+ * @name {{getLastDayOfMonth}}
8259
+ * @nameTags lastDayOfMonth|day
8260
+ * @description {{functionToNewDate}}
8261
+ * @param {ObjectType.LONG} month {{month}}
8262
+ * @param {ObjectType.LONG} year {{year}}
8263
+ * @returns {ObjectType.DATETIME}
8264
+ */
8265
+ this.cronapi.dateTime.getLastDayOfMonth = function(month, year) {
8266
+ if (month < 1 || month > 12) return "invalid month";
8267
+ if (year < 1) return "invalid year";
8268
+ let date = new Date();
8269
+ date.setYear(year);
8270
+ date.setDate(1);
8271
+ date.setMonth(month);
8272
+ date.setDate(date.getDate()-1)
8273
+ return date.getDate();
8274
+ };
8275
8275
  }
8276
8276
 
8277
8277
  (cronapi).bind(window)();