You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

apputils.business.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * Created by robin on 12/15/16.
  3. */
  4. (function () {
  5. 'use strict';
  6. angular.module('appSdk')
  7. .factory('AppUtilsBusiness', ['$rootScope', '$translate', 'luBusyBusiness', 'luRequest',
  8. function($rootScope, $translate, luBusyBusiness, luRequest) {
  9. var AppUtilsBusiness = {};
  10. AppUtilsBusiness.toolbarTitle = null;
  11. AppUtilsBusiness.convertOrderBy = function(orderBy)
  12. {
  13. if (orderBy[0] == '-') {
  14. orderBy = orderBy.substr(1) + ":DESC";
  15. }
  16. else {
  17. orderBy = orderBy + ":ASC";
  18. }
  19. return orderBy;
  20. };
  21. AppUtilsBusiness.setTitle = function(title)
  22. {
  23. $rootScope.title = title + ' - ' + AppUtilsBusiness.tr('common.appName');
  24. };
  25. AppUtilsBusiness.setToolbarTitle = function(title)
  26. {
  27. AppUtilsBusiness.toolbarTitle = title;
  28. $rootScope.$emit('toolbar.title', {title: title});
  29. };
  30. AppUtilsBusiness.getToolbarTitle = function()
  31. {
  32. return AppUtilsBusiness.toolbarTitle;
  33. };
  34. AppUtilsBusiness.mdTableLabels = function()
  35. {
  36. return {
  37. of: AppUtilsBusiness.tr('common.pagination.of'),
  38. page: AppUtilsBusiness.tr('common.pagination.page'),
  39. rowsPerPage: AppUtilsBusiness.tr('common.pagination.rowsPerPage')
  40. };
  41. };
  42. AppUtilsBusiness.cgBusy = function(luBusyGroup)
  43. {
  44. return {
  45. promise: luBusyBusiness.promise(luBusyGroup),
  46. message: AppUtilsBusiness.tr('common.busyLoading'),
  47. templateUrl:'views/busy-template.html'
  48. };
  49. };
  50. AppUtilsBusiness.tr = function(id, data)
  51. {
  52. return $translate.instant(id, data);
  53. };
  54. AppUtilsBusiness.addApiVersionChangedCallback = function(callback)
  55. {
  56. var apiVersion = null;
  57. luRequest.addHook('resolve', function(url, method, dataGet, dataPost, luBusyGroups, data)
  58. {
  59. if (apiVersion == null) {
  60. apiVersion = data.version;
  61. }
  62. else if (data.version != null && data.version != apiVersion) {
  63. callback(apiVersion, data.version);
  64. apiVersion = data.version;
  65. }
  66. });
  67. luRequest.addHook('reject', function(url, method, dataGet, dataPost, luBusyGroups, error)
  68. {
  69. if (apiVersion == null) {
  70. apiVersion = error.data.version;
  71. }
  72. else if (error.data.version != null && error.data.version != apiVersion) {
  73. callback(apiVersion, error.data.version);
  74. apiVersion = error.data.version;
  75. }
  76. });
  77. };
  78. AppUtilsBusiness.articleTypes = ['persons', 'locations', 'countries'];
  79. AppUtilsBusiness.articleFieldTypes = ['date/date', 'text/plain', 'number/number'];
  80. AppUtilsBusiness.articleFieldProperties = ['birthDate', 'deathDate', 'capital', 'language', 'area', 'population'];
  81. return AppUtilsBusiness;
  82. }]);
  83. })();