source : CarNumberExtended.js

  1. 'use strict';
  2. /**
  3. * This widget displays the car number along with the drivers name.
  4. * <p>
  5. * Example:
  6. * <p><b>
  7. * <sra-car-number-extended data-sra-car-number-extended="REFERENCE"></sra-car-number-extended><br />
  8. * </b>
  9. * <img src="../widgets/CarNumberExtended/icon.png" />
  10. *
  11. * @ngdoc directive
  12. * @name sra-car-number-extended
  13. * @param {carIdentifier} data-sra-car-number-extended The <a href="../JavaDoc/com/SIMRacingApps/Session.html#getCar-java.lang.String-" target="_blank">Car Identifier</a> to get the number from. Defaults to REFERENCE.
  14. * @param show-short-name Set to false to show the long name. Default is true.
  15. * @param {function} data-sra-args-on-click (Optional) A function to call when this widget is clicked.
  16. * @param {integer} data-sra-args-interval The interval, in milliseconds, that this widget will update from the server. Default is 100.
  17. * @author Jeffrey Gilliam
  18. * @since 1.0
  19. * @copyright Copyright (C) 2015 - 2024 Jeffrey Gilliam
  20. * @license Apache License 2.0
  21. */
  22. define(['SIMRacingApps','widgets/CarNumber/CarNumber','css!widgets/CarNumberExtended/CarNumberExtended'],
  23. function(SIMRacingApps) {
  24. var self = {
  25. name: "sraCarNumberExtended",
  26. url: 'CarNumberExtended',
  27. template: 'CarNumberExtended.html',
  28. defaultWidth: 480,
  29. defaultHeight: 480,
  30. defaultInterval: 100 //initialize with the default interval
  31. };
  32. self.module = angular.module('SIMRacingApps'); //get the main module
  33. self.module.directive(self.name,
  34. ['sraDispatcher', '$filter', '$rootScope',
  35. function(sraDispatcher, $filter, $rootScope) {
  36. return {
  37. restrict: 'EA',
  38. scope: true,
  39. templateUrl: sraDispatcher.getWidgetUrl(self.url) + '/' + self.template,
  40. controller: [ '$scope', function($scope) {
  41. $scope.directiveName = self.name;
  42. $scope.defaultWidth = self.defaultWidth;
  43. $scope.defaultHeight = self.defaultHeight;
  44. $scope.defaultInterval = self.defaultInterval;
  45. $scope.showShortName = true;
  46. $scope.sraOnClick = "";
  47. $scope.clickedState = 'none'; //either none or clicked
  48. $scope.getClickedState = function() { return $scope.clickedState; };
  49. $scope.setClickedState = function(state) { $scope.clickedState = state || 'none'; };
  50. $scope.sraCarNumber = "";
  51. $scope.sraCarDriverName= "";
  52. $scope.onClickListener = function() {
  53. $scope.sraCarNumber = $scope.data.Car[$scope.value].Number.ValueFormatted;
  54. $scope.sraCarDriverName = $scope.data.Car[$scope.value].DriverName.ValueFormatted;
  55. if ($scope.$parent[$scope.sraOnClick] && angular.isFunction($scope.$parent[$scope.sraOnClick]))
  56. $scope.$parent[$scope.sraOnClick]($scope,$scope.data.Car[$scope.value].Number.ValueFormatted);
  57. }
  58. //load translations, if you have any un-comment this
  59. // sraDispatcher.loadTranslations(sraDispatcher.getWidgetUrl(self.url),'text',function(path) {
  60. // $scope.translations = sraDispatcher.getTranslation(path);
  61. // });
  62. /** your code goes here **/
  63. }]
  64. , link: function($scope,$element,$attrs) {
  65. //copy arguments to our $scope. First if using attribute, second tag, else default to something.
  66. $attrs.sraArgsData = $attrs.sraArgsData || "";
  67. $scope.value =
  68. $scope[self.name] = sraDispatcher.getTruthy($scope.sraArgsVALUE, $attrs.sraArgsCarNumberExtended, $attrs[self.name], $attrs.sraArgsValue, "REFERENCE");
  69. $scope.showShortName = sraDispatcher.getBoolean($scope.sraArgsSHOWSHORTNAME,$attrs.sraArgsShowShortName,$scope.showShortName);
  70. $scope.sraOnClick = $attrs.sraArgsOnClick;
  71. /** your code goes here **/
  72. $attrs.sraArgsData += ";Car/"+$scope[self.name]+"/Number";
  73. $attrs.sraArgsData += ";Car/"+$scope[self.name]+"/DriverName";
  74. $attrs.sraArgsData += ";Car/"+$scope[self.name]+"/DriverNameShort";
  75. $attrs.sraArgsData += ";Car/"+$scope[self.name]+"/StatusClass";
  76. $attrs.sraArgsData += ";Car/"+$scope[self.name]+"/ClassColor";
  77. $attrs.sraArgsData += ";Session/NumberOfCarClasses";
  78. $attrs.sraArgsData += ";Session/DiffCars/LEADER/"+$scope[self.name];
  79. /**standard code that should be in every directive **/
  80. $rootScope.$on('sraResize', sraDispatcher.resize($scope,$element,self.defaultWidth,self.defaultHeight));
  81. sraDispatcher.onClick($scope,$element,$scope.onClickListener);
  82. //register with the dispatcher
  83. $scope.names = sraDispatcher.subscribe($scope,$attrs,self.defaultInterval); //register subscriptions and options to the dispatcher
  84. }
  85. };
  86. }]);
  87. return self;
  88. });