main.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* global app, angular */
  2. angular.module("robware", ['ngAnimate'], ["$httpProvider", function($httpProvider) {
  3. /*
  4. * Stolen from: http://stackoverflow.com/questions/19254029/angularjs-http-post-does-not-send-data
  5. * Reason: send payload as form data instead of JSON, bind to controller action parameters
  6. */
  7. // Use x-www-form-urlencoded Content-Type
  8. $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
  9. /**
  10. * The workhorse; converts an object to x-www-form-urlencoded serialization.
  11. * @param {Object} obj
  12. * @return {String}
  13. */
  14. var param = function(obj) {
  15. var query = '', name, value, fullSubName, subName, subValue, innerObj, i;
  16. for (name in obj) {
  17. value = obj[name];
  18. if (value instanceof Array) {
  19. for (i = 0; i < value.length; ++i) {
  20. subValue = value[i];
  21. fullSubName = name + '[' + i + ']';
  22. innerObj = {};
  23. innerObj[fullSubName] = subValue;
  24. query += param(innerObj) + '&';
  25. }
  26. }
  27. else if (value instanceof Object) {
  28. for (subName in value) {
  29. subValue = value[subName];
  30. fullSubName = name + '[' + subName + ']';
  31. innerObj = {};
  32. innerObj[fullSubName] = subValue;
  33. query += param(innerObj) + '&';
  34. }
  35. }
  36. else if (value !== undefined && value !== null)
  37. query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
  38. }
  39. return query.length ? query.substr(0, query.length - 1) : query;
  40. };
  41. // Override $http service's default transformRequest
  42. $httpProvider.defaults.transformRequest = [
  43. function(data) {
  44. return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
  45. }
  46. ];
  47. $httpProvider.interceptors.push([
  48. '$rootScope',
  49. '$q',
  50. function($rootScope, $q) {
  51. return {
  52. request: function(config) {
  53. if (config.showSpinner)
  54. $rootScope.showSpinner();
  55. return config;
  56. },
  57. requestError: function(rejection) {
  58. $rootScope.hideSpinner();
  59. return $q.reject(rejection);
  60. },
  61. response: function(response) {
  62. $rootScope.hideSpinner();
  63. return response;
  64. },
  65. responseError: function(rejection) {
  66. $rootScope.hideSpinner();
  67. return $q.reject(rejection);
  68. }
  69. };
  70. }
  71. ]);
  72. }]);
  73. angular.module("robware").controller("main", ['$scope', '$rootScope', function($scope, $rootScope) {
  74. var largeWindowBoundary = 1023;
  75. $scope.menuVisible = false;//window.innerWidth > largeWindowBoundary;
  76. $scope.shouldShowMenu = function() {
  77. return $scope.menuVisible || window.innerWidth > largeWindowBoundary;
  78. };
  79. $scope.spinnerVisible = false;
  80. $rootScope.showSpinner = function() {
  81. $scope.spinnerVisible = true;
  82. };
  83. $rootScope.hideSpinner = function() {
  84. $scope.spinnerVisible = false;
  85. };
  86. $(window).on("resize.doResize", function() {
  87. $scope.$apply(function() {
  88. //$scope.menuVisible = false;
  89. });
  90. });
  91. $scope.errors=[];
  92. $scope.showErrors=function(errors){
  93. $scope.errors=errors;
  94. }
  95. }]);