'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',
    'qrzk.service'])
    .constant('appConst', {
        context: 'qrzk_jk',
        formHeaders: {'Content-Type': 'application/x-www-form-urlencoded'},
        sysType: 'GK',//'SK'、'GK'
        sysTitle: {'GK': '国考卷库管理', 'SK': '省考卷库管理'},
        batchTypes: {
            'GK': [{name: 'ENTER', value: '入库'}, {name: 'REVIEW', value: '复审'}, {name: 'SUPPLY', value: '供卷'}],
            'SK': [{name: 'ENTER', value: '入库'}, {name: 'REVIEW', value: '清样库建设'}, {name: 'USE', value: '启用'}]
        }
    })
    //集成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('province', {
            url: "/province",
            templateUrl: "resources/app/province.html",
            ncyBreadcrumb: {
                label: '供卷省份信息设置'
            }
        })//机要文件管理
        .state('confidential', {
            url: "/confidential",
            templateUrl: "resources/app/confidential.html",
            ncyBreadcrumb: {
                label: '机要文件管理'
            }
        })//试卷分析
        .state('paperAnalysisList', {
            url: "/paperAnalysisList",
            templateUrl: "resources/app/paperAnalysis.html",
            ncyBreadcrumb: {
                label: '试卷分析'
            }
        })
        //批次管理
        .state('batch', {
            abstract: true,
            url: "/batch",
            templateUrl: "resources/app/batch/main.html"
        })
        .state('batch.top', {
            url: "/top",
            templateUrl: "resources/app/batch/main.top.html",
            ncyBreadcrumb: {
                label: '批次管理'
            }
        })
        .state('batch.add', {
            url: "/add",
            templateUrl: "resources/app/batch/main.add.html",
            ncyBreadcrumb: {
                label: '新增批次',
                parent: 'batch.top'
            }
        })
        .state('batch.import', {
            url: "/batchImport",
            templateUrl: "resources/app/batch/batch.import.html",
            ncyBreadcrumb: {
                label: '导入批次',
                parent: 'batch.top'
            }
        })
        .state('batch.info', {
            abstract: true,
            url: "/info/:id",
            params: {id: null},
            templateUrl: "resources/app/batch/info.html",
            ncyBreadcrumb: {
                label: '供卷',
                parent: 'batch.top'
            }
        })
        .state('batch.info.paper', {
            url: "/paper",
            templateUrl: "resources/app/batch/info.paper.html"
        })
        .state('batch.info.book', {
            url: "/book",
            templateUrl: "resources/app/batch/info.book.html"
        })
        /** 供卷 **/
        .state('batch.info.supply', {
            url: "/supply",
            templateUrl: "resources/app/batch/info.supply.html",
            ncyBreadcrumb: {
                label: '{{batch.title}}',
                parent: 'batch.info'
            }
        })
        .state('batch.info.supplymgt', {
            url: "/supplymgt",
            templateUrl: "resources/app/batch/info.supply.mgt.html",
            ncyBreadcrumb: {
                label: '供卷课程管理',
                parent: 'batch.info.supply'
            }
        })
        .state('batch.info.printLog', {
            url: "/supplyPrintLog",
            templateUrl: "resources/app/batch/info.supply.printLog.html",
            ncyBreadcrumb: {
                label: '查看打印日志',
                parent: 'batch.info.supply'
            }
        })
        .state('batch.info.supplyform', {
            url: "/supplyform/:op",
            params: {op: null, supplyCourseId: null},
            templateUrl: "resources/app/batch/info.supply.form.html",
            ncyBreadcrumb: {
                label: '编辑供卷省份',
                parent: 'batch.info.supplymgt'
            }
        })
        .state('batch.info.supplypaper', {
            url: "/supplypaper/form",
            params: {op: null, id: null},
            templateUrl: "resources/app/batch/info.supply.paper.html",
            ncyBreadcrumb: {
                label: '启用试卷',
                parent: 'batch.info.supplymgt'
            }
        })
        .state('batch.info.supplyconfig', {
            url: "/supplyconfig",
            templateUrl: "resources/app/batch/info.supply.config.html",
            ncyBreadcrumb: {
                label: '供卷设置',
                parent: 'batch.info.supplymgt'
            }
        })
        .state('batch.info.supplyprint', {
            url: "/supplyprint",
            templateUrl: "resources/app/batch/info.supply.print.html",
            ncyBreadcrumb: {
                label: '供卷打印',
                parent: 'batch.info.supplymgt'
            }
        })
        .state('batch.info.supplyprinttask', {
            url: "/supply/printtask",
            params: {op: null, id: null},
            templateUrl: "resources/app/batch/info.supply.printtask.html",
            ncyBreadcrumb: {
                label: '分配打印任务',
                parent: 'batch.info.supplymgt'
            }
        })
        .state('batch.info.supplyscantask', {
            url: "/supply/scantask",
            params: {op: null, id: null},
            templateUrl: "resources/app/batch/info.supply.scantask.html",
            ncyBreadcrumb: {
                label: '分配封装任务',
                parent: 'batch.info.supplymgt'
            }
        })
        .state('batch.info.ruku', {
            url: "/ruku",
            templateUrl: "resources/app/batch/rukuBatch.html",
            ncyBreadcrumb: {
                label: '{{batch.title}}',
                parent: 'batch.info'
            }
        })
        .state('batch.info.addRukuPaper', {
            url: "/addRukuPaper",
            templateUrl: "resources/app/batch/addRukuPaper.html",
            ncyBreadcrumb: {
                label: '新增试卷',
                parent: 'batch.info.ruku'
            }
        })
        .state('batch.info.importRukuPaperDBF', {
            url: "/importRukuPaperDBF",
            templateUrl: "resources/app/batch/importRukuPaperDBF.html",
            ncyBreadcrumb: {
                label: '导入DBF',
                parent: 'batch.info.ruku'
            }
        })
        .state('batch.info.uploadRukuPaperFiles', {
            url: "/uploadRukuPaperFiles",
            templateUrl: "resources/app/batch/uploadRukuPaperFiles.html",
            ncyBreadcrumb: {
                label: '上传电子文档',
                parent: 'batch.info.ruku'
            }
        })
        .state('batch.info.instorageScan', {
            url: "/instorageScan",
            templateUrl: "resources/app/batch/instorageScan.html",
            ncyBreadcrumb: {
                label: '入库扫描',
                parent: 'batch.info.ruku'
            }
        })

        .state('batch.info.review', {
            url: "/review",
            templateUrl: "resources/app/batch/info.review.html",
            ncyBreadcrumb: {
                label: '{{batch.title}}',
                parent: 'batch.info'
            }
        })
        .state('batch.info.addReviewPaper', {
            url: "/review/addReviewPaper",
            templateUrl: "resources/app/batch/info.review.addPaper.html",
            controller: "ReviewBatchAddPaperCtrl",
            ncyBreadcrumb: {
                label: '关联试卷',
                parent: 'batch.info.review'
            }
        })
        .state('batch.info.reviewOut', {
            url: "/review/out",
            templateUrl: "resources/app/batch/info.review.out.html",
            ncyBreadcrumb: {
                label: '{{batch.title}}',
                parent: 'batch.info'
            }
        })
        .state('batch.info.reviewIn', {
            url: "/review/in",
            templateUrl: "resources/app/batch/info.review.in.html",
            ncyBreadcrumb: {
                label: '{{batch.title}}',
                parent: 'batch.info'
            }
        })
        .state('batch.info.reviewOutScan', {
            url: "/review/outScan",
            templateUrl: "resources/app/batch/info.review.outScan.html",
            ncyBreadcrumb: {
                label: '出库扫描',
                parent: 'batch.info.reviewOut'
            }
        })
        .state('batch.info.reviewUploadPapers', {
            url: "/review/uploadPapers",
            templateUrl: "resources/app/batch/info.review.uploadPapers.html",
            ncyBreadcrumb: {
                label: '上传清样电子试卷',
                parent: 'batch.info.reviewIn'
            }
        })
        .state('batch.info.reviewInScan', {
            url: "/review/inScan",
            templateUrl: "resources/app/batch/info.review.inScan.html",
            ncyBreadcrumb: {
                label: '回库扫描',
                parent: 'batch.info.reviewIn'
            }
        })
        //主菜单
        .state('home', {
            url: "/home",
            templateUrl: "resources/app/home.html",
            controller: function ($scope, UserMark) {
                $scope.userMarks = UserMark.query();

                $scope.removeMark = function (m) {
                    UserMark.remove({id: m.id}, function (data) {
                        if (data.result) {
                            $scope.userMarks = UserMark.query();
                        }
                    })
                }
            },
            ncyBreadcrumb: {
                label: '菜单和书签'
            }
        })
        .state('stock', {
            url: "/stock",
            templateUrl: "resources/app/batch/stock.html",
            ncyBreadcrumb: {
                label: '库存统计'
            }
        })

        .state('pswSetting', {
            url: "/pswSetting",
            templateUrl: "resources/app/pswSetting.html",
            ncyBreadcrumb: {
                label: '密码本管理'
            }
        })

        .state('pswSettingAdd', {
            url: "/pswSettingAdd",
            templateUrl: "resources/app/pswSetting.add.html",
            ncyBreadcrumb: {
                label: '生成密码本',
                parent: 'pswSetting'
            }
        })

        .state('backupAndRestore', {
            url: "/backupAndRestore",
            templateUrl: "resources/app/backupAndRestore.html",
            ncyBreadcrumb: {
                label: '数据备份还原'
            }
        })

        .state('userList', {
            url: "/userList",
            templateUrl: "resources/app/user/list.html",
            ncyBreadcrumb: {
                label: '用户管理'
            }
        })

        .state('userAdd', {
            url: "/userAdd",
            templateUrl: "resources/app/user/add.html",
            ncyBreadcrumb: {
                label: '新增用户',
                parent: 'userList'
            }
        })
        .state('userEdit', {
            url: "/userEdit/:id",
            params: {id: null},
            templateUrl: "resources/app/user/edit.html",
            ncyBreadcrumb: {
                label: '编辑用户',
                parent: 'userList'
            }
        })
        .state('paperSearch', {
            url: "/paperSearch",
            templateUrl: "resources/app/paperSearch.html",
            ncyBreadcrumb: {
                label: '试卷检索'
            }
        })
        .state('supplyScanPaper', {
            url: "/supplyScanTask/paper",
            params: {scanType: 'paper'},
            templateUrl: "resources/app/batch/supplyScanTask.html",
            ncyBreadcrumb: {
                label: '扫描试卷'
            }
        })
        .state('supplyScanAnswer', {
            url: "/supplyScanTask/answer",
            params: {scanType: 'answer'},
            templateUrl: "resources/app/batch/supplyScanTask.html",
            ncyBreadcrumb: {
                label: '扫描答案'
            }
        });
});

