directive.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. starter.directive('itemWrite', [function () {
  2. return {
  3. restrict: "E",
  4. scope: {
  5. item: "=itemData"
  6. },
  7. templateUrl: 'templates/template-itemWrite.html',
  8. controller: function ($scope, $cordovaDatePicker) {
  9. $scope.selectedChange = function (value) {
  10. $scope.item.text = value;
  11. }
  12. $scope.chooseDate = function (datetime) {
  13. var options = {
  14. mode: 'date',
  15. date: new Date(),
  16. androidTheme: 3
  17. };
  18. $cordovaDatePicker.show(options).then(function (date) {
  19. if (date == undefined) return;
  20. $scope.item.datetime_data = date;
  21. });
  22. }
  23. if ($scope.item.t__type in [1, 4]) {
  24. if ($scope.item.required) {
  25. $scope.note = '输入内容';
  26. } else {
  27. $scope.note = '输入内容(选填)';
  28. }
  29. } else if ($scope.item.t__type in [2, 3, 5]) {
  30. if ($scope.item.t__type == 5) {
  31. if ($scope.item.select_data == undefined)
  32. $scope.item.select_data = $scope.item.selecttext;
  33. data = JSON.parse($scope.item.extra)
  34. data = _.pluck(data, 'text')
  35. $scope.selectData = data;
  36. }
  37. if (!$scope.item.required)
  38. $scope.note = '(选填)';
  39. }
  40. }
  41. }
  42. }])
  43. .directive('setClassWhenAtTop', function ($window) {
  44. var $win = angular.element($window);
  45. return {
  46. restrict: 'A',
  47. link: function (scope, element, attrs) {
  48. var topClass = attrs.setClassWhenAtTop,
  49. offsetTop = element[0].offsetTop;
  50. $win.on('scroll', function (e) {
  51. if ($win.scrollTop() >= 44) {
  52. element.addClass(topClass);
  53. } else {
  54. element.removeClass(topClass);
  55. }
  56. });
  57. }
  58. };
  59. })
  60. .directive('daily', function () {
  61. return {
  62. restrict: "E",
  63. scope: {
  64. dailys: "=dailys",
  65. loading: "=loading"
  66. },
  67. templateUrl: 'templates/template-daily.html',
  68. controller: function ($scope, $state, Daily) {
  69. $scope.todetails = function (daily) {
  70. Daily.daily = _.clone(daily);
  71. $state.go('daily-details', {
  72. 'id': daily.id
  73. });
  74. }
  75. }
  76. }
  77. })
  78. .directive('dailyHeader', function () {
  79. return {
  80. restrict: "E",
  81. scope: {
  82. daily: "=daily"
  83. },
  84. template: '<div class="item item-avatar"><img ng-src="../../../img/panda.png" ng-click="showcardinfo(daily.create_user)"><span>{{daily.create_user_name}}</span><p>{{daily.create_date | date:"MM-dd HH:mm"}}</p><p class="time">日报({{daily.daily_dd | date:"M月d日"}})</p></div>'
  85. }
  86. })
  87. .directive('dailyContent', function () {
  88. return {
  89. restrict: "E",
  90. scope: {
  91. daily: "=daily"
  92. },
  93. template: '<div class="item item-body"><span ng-bind-html="itemContent | getHtmlContent" ng-repeat="itemContent in daily.daily_tfs"></span><div class="blob"><image-popover all-images="daily.files"></image-popover></div></div>'
  94. }
  95. })
  96. .filter('getHtmlContent', function () {
  97. return function (content) {
  98. if (!content.required)
  99. return null;
  100. fieldname = '';
  101. if (content.daily_template_item != 1)
  102. fieldname = content.name + '&nbsp:&nbsp';
  103. fielddata = content.text || '';
  104. var str = fieldname + fielddata + '<br/>';
  105. str = str.replace(/\n/g, '<br/>');
  106. return str;
  107. }
  108. })