'use strict';
var myApp = angular.module('qrzk', [
    'ui.router',
    'ngCookies',
    'ngAnimate',
    'mgcrea.ngStrap',
    'smart-table',
    'widget.scrollbar',
    'ui.select',
    'cgBusy',
    'angularFileUpload',
    'xeditable',
    'toaster',
    'ncy-angular-breadcrumb',
    'ngSanitize'
])
    .constant('appConst', {
            context: 'qrzk',
            formHeaders: {'Content-Type': 'application/x-www-form-urlencoded'}
        }
    )
    .constant('learnCenter', {
            categories: [{code: 'gzzd', name: '工作制度'}
                , {code: 'rwsm', name: '任务说明'}
                , {code: 'ywjs', name: '业务介绍'}
                , {code: 'kcjc', name: '课程教材'}
                , {code: 'kcdg', name: '课程大纲'}
                , {code: 'lszt', name: '历史真题'}
                , {code: 'sczx', name: '素材中心'}
            ]
        }
    )

    /**
     * ckeditor Directive
     * @author 张世民 @ 数云图
     */
    .directive('ckeditor', function () {
        return {
            require: '?ngModel',
            link: function (scope, element, attrs, ngModel) {
                var ckeditor = CKEDITOR.replace(element[0], {
                    height: attrs.height, width: attrs.width
                });
                if (!ngModel) {
                    return;
                }
                ckeditor.on('instanceReady', function () {
                    ckeditor.setData(ngModel.$viewValue);
                });
                ckeditor.on('pasteState', function () {
                    scope.$apply(function () {
                        ngModel.$setViewValue(ckeditor.getData());
                    });
                });
                ngModel.$render = function (value) {
                    ckeditor.setData(ngModel.$viewValue);
                };
            }
        };
    })

    //集成underscore.js
    .constant('_', window._)
    .run(
        ['$rootScope', '$state', '$stateParams', 'editableOptions',
            function ($rootScope, $state, $stateParams, editableOptions) {
                $rootScope.$state = $state;
                $rootScope.$stateParams = $stateParams;
                $rootScope.favors = [];
                $rootScope._ = window._;
                editableOptions.theme = 'bs3';
            }
        ]
    );

myApp.config(function ($stateProvider, $urlRouterProvider, $httpProvider, $breadcrumbProvider) {
    //$httpProvider.defaults.useXDomain = true;
    //delete $httpProvider.defaults.headers.common['X-Requested-With'];
    $breadcrumbProvider.setOptions({
        //prefixStateName: 'home',
        templateUrl: 'resources/app/breadcrumb.html'
    });

    //路由设置
    //缺省url
    $urlRouterProvider.otherwise("/home");
    $stateProvider
        //主菜单
        .state('home', {
            url: "/home",
            templateUrl: "resources/app/home.html",
            controller: function ($scope) {
            },
            ncyBreadcrumb: {
                label: '菜单和书签'
            }
        })
        .state('learnCenter', {
            url: "/learnCenter",
            abstract: true,
            templateUrl: "resources/app/common/top.html"
        })
        .state('learnCenter.category', {
            url: "/category",
            templateUrl: "resources/app/learnCenter/category.html",
            ncyBreadcrumb: {
                label: '帮助中心'
            }
        })
        .state('learnCenter.list', {
            url: "/list/:categoryCode",
            params: {categoryCode: null, categoryName: null},
            templateUrl: "resources/app/learnCenter/list.html",
            ncyBreadcrumb: {
                label: '{{$stateParams.categoryName}}',
                parent: 'learnCenter.category'
            }
        })
        .state('gzzd', {
            url: "/:categoryCode",
            params: {categoryCode: 'gzzd'},
            templateUrl: "resources/app/learnCenter/list.html",
            ncyBreadcrumb: {
                label: '工作制度'
            }
        })
        .state('rwsm', {
            url: "/:categoryCode",
            params: {categoryCode: 'rwsm'},
            templateUrl: "resources/app/learnCenter/list.html",
            ncyBreadcrumb: {
                label: '任务说明'
            }
        })
        .state('ywjs', {
            url: "/:categoryCode",
            params: {categoryCode: 'ywjs'},
            templateUrl: "resources/app/learnCenter/list.html",
            ncyBreadcrumb: {
                label: '业务介绍'
            }
        })
        .state('kcjc', {
            url: "/:categoryCode",
            params: {categoryCode: 'kcjc'},
            templateUrl: "resources/app/learnCenter/list.html",
            ncyBreadcrumb: {
                label: '课程教材'
            }
        })
        .state('kcdg', {
            url: "/:categoryCode",
            params: {categoryCode: 'kcdg'},
            templateUrl: "resources/app/learnCenter/list.html",
            ncyBreadcrumb: {
                label: '课程大纲'
            }
        })
        .state('lszt', {
            url: "/:categoryCode",
            params: {categoryCode: 'lszt'},
            templateUrl: "resources/app/learnCenter/list.html",
            ncyBreadcrumb: {
                label: '历史真题'
            }
        })
        .state('sczx', {
            url: "/:categoryCode",
            params: {categoryCode: 'sczx'},
            templateUrl: "resources/app/learnCenter/list.html",
            ncyBreadcrumb: {
                label: '素材中心'
            }
        })
        .state('learnCenter.upload', {
            url: "/learnCenter/upload/:categoryCode",
            params: {categoryCode: null, categoryName: null},
            templateUrl: "resources/app/learnCenter/upload.html",
            ncyBreadcrumb: {
                label: '文件上传',
                parent: 'learnCenter.list'
            }
        })
        /** 业务管理员进行成绩分析 **/
        .state('scoreAnalysis', {
            controller: function ($scope, $stateParams) {
                window.open('scoreanalysis/login');
                location.reload();
            }
        }).state('paperAnalysisList', {
        url: "/paperAnalysisList",
        templateUrl: "resources/app/paperanalysis/paperAnalysis.html",
        ncyBreadcrumb: {
            label: '试卷分析'
        }
    })
    ;

});

