Guest User

Untitled

a guest
Jan 21st, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. var app = angular.module("app", ['kendo.directives']);
  2.  
  3. app.controller('contentTypesController', ['$scope', '$log', 'contentTypesRepository',
  4. function ($scope, $log, contentTypesRepository) {
  5.  
  6. var a = {};
  7.  
  8. $scope.status;
  9. $scope.contentTypes;
  10.  
  11. $scope.contentTypeOptions;
  12.  
  13. // for testing purposes, but not used - used for navigation properties
  14. $scope.users;
  15.  
  16. getContentTypes();
  17.  
  18. function getContentTypes() {
  19. // call the data repository
  20. contentTypesRepository.getList()
  21. .success(function (contentTypes) {
  22. //console.log(contentTypes.value[0].Description);
  23. //$log.log(contentTypes.value[0].Description)
  24. $scope.contentTypes = contentTypes;
  25. $scope.contentTypeOptions = {
  26. dataSource: {
  27. data: contentTypes
  28. },
  29. dataTextField: "Description",
  30. dataValueField: "ContentTypeId",
  31. optionLabel: "Select a Content Type"
  32. };
  33.  
  34. })
  35. .error(function (error) {
  36. $scope.status = 'Unable to load data: ' + error.message;
  37. });
  38. }
  39.  
  40. $scope.updateContentTypes = function (id) {
  41. var contentType;
  42.  
  43. for (var i = 0; i < $scope.contentTypes.length; i++) {
  44. var currentType = $scope.contentTypes[i];
  45. if (currentType.ID === id) {
  46. contentType = currentType;
  47. break;
  48. }
  49. }
  50. };
  51.  
  52. $scope.insertContentType = function () {
  53. // get contentType description from the client
  54. var contentType = { 'Description': $scope.newContentType };
  55.  
  56. contentTypesRepository.insert(contentType)
  57. .success(function () {
  58. $scope.status = 'Added new content type. Refreshing list.';
  59. // add the new content type to the client-side collection
  60. $scope.contentTypes.value.push(
  61. { 'Description': $scope.newContentType }
  62. );
  63. $scope.newContentType = "";
  64. })
  65. .error(function (error) {
  66. $scope.status = 'Unable to insert new content type: ' + error.message;
  67. });
  68. };
  69.  
  70. $scope.deleteContentType = function(id) {
  71. contentTypesRepository.remove(id)
  72. .success(function () {
  73. $scope.status = 'Deleted content type. Refreshing list.';
  74. for (var i = 0; i < $scope.contentTypes.length; i++) {
  75. var contentType = $scope.contentTypes[i];
  76. if (contentType.ID === id) {
  77. // remove the content type from the client-side collection
  78. $scope.contentTypes.splice(i, 1);
  79. break;
  80. }
  81. }
  82. // navigation properties = null
  83. // $scope.xxxx = null;
  84. })
  85. .error(function (error) {
  86. $scope.status = 'Unable to delete content type: ' + error.message;
  87. });
  88. };
  89.  
  90. // get some navigation property
  91. //$scope.getCustomerOrders = function (id) {
  92. // dataFactory.getOrders(id)
  93. // .success(function (orders) {
  94. // $scope.status = 'Retrieved orders!';
  95. // $scope.orders = orders;
  96. // })
  97. // .error(function (error) {
  98. // $scope.status = 'Error retrieving customers! ' + error.message;
  99. // });
  100. //};
  101.  
  102.  
  103. $scope.addContentType = function () {
  104.  
  105. //return $scope.newContentType.$save();
  106. $scope.contentTypes.value.push(
  107. { 'Description': $scope.newContentType }
  108. );
  109. $scope.newContentType = "";
  110. }
  111.  
  112. <select kendo-drop-down-list k-options="contentTypeOptions"></select>
  113.  
  114. <ul>
  115. <li ng-repeat="contentType in contentTypes.value">
  116. {{ contentType.Description }}
  117. </li>
  118. </ul>
  119.  
  120. $scope.contentTypeOptions = {
  121. dataSource: {
  122. data: contentTypes.value // tried both contentTypes and contentTypes.value
  123. },
  124. dataTextField: "Description",
  125. dataValueField: "ContentTypeId",
  126. optionLabel: "Select a Content Type"
  127. };
  128.  
  129. $scope.contentTypeOptions.dataSource.data(contentType.value);
  130.  
  131. k-data-source="contentTypes"
Add Comment
Please, Sign In to add comment