source : WaitingForSIM.js

  1. 'use strict';
  2. /**
  3. * This widget displays a message that we are waiting on the SIM to connect.
  4. *
  5. * Users can override the message with an image file of their own.
  6. * Place a file called "WaitingForSIM.png" your "Documents/SIMRacingApps" folder.
  7. * This image will be scaled to the window size, but the aspect ratio will be maintained.
  8. * The default ratio is 16x9.
  9. * <p>
  10. * Example(s):
  11. * <p><b>
  12. * <sra-waiting-for-s-i-m></sra-waiting-for-s-i-m><br />
  13. * </b>
  14. * <img src="../widgets/WaitingForSIM/icon.png" />
  15. * @ngdoc directive
  16. * @name sra-waiting-for-s-i-m
  17. * @param {integer} data-sra-args-interval The interval, in milliseconds, that this widget will update from the server. Default is 1000.
  18. * @author Jeffrey Gilliam
  19. * @since 1.0
  20. * @copyright Copyright (C) 2015 - 2024 Jeffrey Gilliam
  21. * @license Apache License 2.0
  22. */
  23. define(['SIMRacingApps','css!widgets/WaitingForSIM/WaitingForSIM'],
  24. function(SIMRacingApps) {
  25. var self = {
  26. name: "sraWaitingForSIM",
  27. url: 'WaitingForSIM',
  28. template: 'WaitingForSIM.html',
  29. defaultWidth: 1920,
  30. defaultHeight: 1080,
  31. defaultInterval: 1000 //initialize with the default interval
  32. };
  33. self.module = angular.module('SIMRacingApps'); //get the main module
  34. self.module.directive(self.name,
  35. ['sraDispatcher', '$filter', '$rootScope', '$interval', '$timeout',
  36. function(sraDispatcher, $filter, $rootScope, $interval, $timeout) {
  37. return {
  38. restrict: 'EA',
  39. scope: true,
  40. templateUrl: sraDispatcher.getWidgetUrl(self.url) + '/' + self.template,
  41. controller: [ '$scope', function($scope) {
  42. $scope.directiveName = self.name;
  43. $scope.defaultWidth = self.defaultWidth;
  44. $scope.defaultHeight = self.defaultHeight;
  45. $scope.defaultInterval = self.defaultInterval;
  46. sraDispatcher.loadTranslations(sraDispatcher.getWidgetUrl(self.url),'text',function(path) {
  47. $scope.translations = sraDispatcher.getTranslation(path);
  48. });
  49. /** your code goes here **/
  50. $scope.message = "";
  51. $scope.update = function () {
  52. var value = $scope.data.Session.Messages.Value;
  53. $scope.message = "";
  54. var messages = value.split(";");
  55. for (var i = 0; i < messages.length; i++) {
  56. if (messages[i] == "DISCONNECTED") {
  57. $scope.message = $scope.translations && $scope.translations["WAITINGFORSIM"]
  58. ? $scope.translations["WAITINGFORSIM"] : "Waiting For SIM";
  59. }
  60. }
  61. };
  62. }]
  63. , link: function($scope,$element,$attrs) {
  64. //copy arguments to our $scope. First if using attribute, second tag, else default to something.
  65. $attrs.sraArgsData = $attrs.sraArgsData || "";
  66. $scope.value =
  67. $scope[self.name] = sraDispatcher.getTruthy($scope.sraArgsVALUE, $attrs[self.name], $attrs.sraArgsValue, "DefaultValue");
  68. /** your code goes here **/
  69. $attrs.sraArgsData += ";Session/Messages";
  70. $scope.$watch("data.Session.Messages.Value", $scope.update);
  71. /**standard code that should be in every directive **/
  72. $rootScope.$on('sraResize', sraDispatcher.resize($scope,$element,self.defaultWidth,self.defaultHeight));
  73. //register with the dispatcher
  74. $scope.names = sraDispatcher.subscribe($scope,$attrs,self.defaultInterval); //register subscriptions and options to the dispatcher
  75. }
  76. };
  77. }]);
  78. return self;
  79. });