Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var app = angular.module("app", ['kendo.directives']);
- app.controller('contentTypesController', ['$scope', '$log', 'contentTypesRepository',
- function ($scope, $log, contentTypesRepository) {
- var a = {};
- $scope.status;
- $scope.contentTypes;
- $scope.contentTypeOptions;
- // for testing purposes, but not used - used for navigation properties
- $scope.users;
- getContentTypes();
- function getContentTypes() {
- // call the data repository
- contentTypesRepository.getList()
- .success(function (contentTypes) {
- //console.log(contentTypes.value[0].Description);
- //$log.log(contentTypes.value[0].Description)
- $scope.contentTypes = contentTypes;
- $scope.contentTypeOptions = {
- dataSource: {
- data: contentTypes
- },
- dataTextField: "Description",
- dataValueField: "ContentTypeId",
- optionLabel: "Select a Content Type"
- };
- })
- .error(function (error) {
- $scope.status = 'Unable to load data: ' + error.message;
- });
- }
- $scope.updateContentTypes = function (id) {
- var contentType;
- for (var i = 0; i < $scope.contentTypes.length; i++) {
- var currentType = $scope.contentTypes[i];
- if (currentType.ID === id) {
- contentType = currentType;
- break;
- }
- }
- };
- $scope.insertContentType = function () {
- // get contentType description from the client
- var contentType = { 'Description': $scope.newContentType };
- contentTypesRepository.insert(contentType)
- .success(function () {
- $scope.status = 'Added new content type. Refreshing list.';
- // add the new content type to the client-side collection
- $scope.contentTypes.value.push(
- { 'Description': $scope.newContentType }
- );
- $scope.newContentType = "";
- })
- .error(function (error) {
- $scope.status = 'Unable to insert new content type: ' + error.message;
- });
- };
- $scope.deleteContentType = function(id) {
- contentTypesRepository.remove(id)
- .success(function () {
- $scope.status = 'Deleted content type. Refreshing list.';
- for (var i = 0; i < $scope.contentTypes.length; i++) {
- var contentType = $scope.contentTypes[i];
- if (contentType.ID === id) {
- // remove the content type from the client-side collection
- $scope.contentTypes.splice(i, 1);
- break;
- }
- }
- // navigation properties = null
- // $scope.xxxx = null;
- })
- .error(function (error) {
- $scope.status = 'Unable to delete content type: ' + error.message;
- });
- };
- // get some navigation property
- //$scope.getCustomerOrders = function (id) {
- // dataFactory.getOrders(id)
- // .success(function (orders) {
- // $scope.status = 'Retrieved orders!';
- // $scope.orders = orders;
- // })
- // .error(function (error) {
- // $scope.status = 'Error retrieving customers! ' + error.message;
- // });
- //};
- $scope.addContentType = function () {
- //return $scope.newContentType.$save();
- $scope.contentTypes.value.push(
- { 'Description': $scope.newContentType }
- );
- $scope.newContentType = "";
- }
- <select kendo-drop-down-list k-options="contentTypeOptions"></select>
- <ul>
- <li ng-repeat="contentType in contentTypes.value">
- {{ contentType.Description }}
- </li>
- </ul>
- $scope.contentTypeOptions = {
- dataSource: {
- data: contentTypes.value // tried both contentTypes and contentTypes.value
- },
- dataTextField: "Description",
- dataValueField: "ContentTypeId",
- optionLabel: "Select a Content Type"
- };
- $scope.contentTypeOptions.dataSource.data(contentType.value);
- k-data-source="contentTypes"
Add Comment
Please, Sign In to add comment