var initApp = function(){
    "use strict";
    var ref = [
        "xn.directive.common",
        "xn.filter.common",
        "xn.service.common",
        "xn.directive.navigation",
        "xn.service.interceptor",
        "xn.service.foundation",
        "ui.bootstrap",
        "xn.directive.form",
        "xn.directive.calendar",
        "xn.directive.location",
        "xn.my.list"
    ];
    var messageController = function ($scope, $modal, FoundationService) {
        //页面加载日志信息
        $scope.getMessageList = function () {
            FoundationService.getMessageList().success(function (data) {
                $scope.messages = [];
                $scope.messagesAll = data.result;
                if ($scope.messagesAll != undefined) {
                    if (data.result.length > 5) {
                        for (var i = 0; i < 5; i++) {
                            $scope.messages.push(data.result[i]);
                        }
                    } else {
                        $scope.messages = data.result;
                    }
                }
            });
        };
        $scope.getMessageList();

        $scope.showMoreMessage = function () {
            window.location = "/message/index.htm";
        };

        var cardFunction = function (templateUrl) {
            return function (id) {
                $scope.messageDetailId = id;
                $modal.open({
                    controller: messageDetailController,
                    scope: $scope,
                    templateUrl: templateUrl,
                    resolve: {
                        data: function () {
                            return {};
                        }
                    }
                });
            };
        };
        $scope.getMessageDetail = cardFunction("messageDetail.html");
    };

    /**
     *消息明细
     */
    var messageDetailController = function ($scope, FoundationService,$modalInstance) {
        var id = {id: $scope.messageDetailId};
        //页面加载消息详细信息
        $scope.getMessageDetail = function () {
            FoundationService.getMessageDetail(id).success(function (data) {
                $scope.messageDetail = data.message;
            });
        };
        $scope.getMessageDetail();

        $scope.doRead = function () {
            $scope.messageReadIds = [];
            $scope.messageReadIds.push($scope.messageDetailId);
            console.log($scope.messageReadIds);
            FoundationService.doRead($scope.messageReadIds).success(function () {
            });
        };
        $scope.doRead();

        $scope.cancel = function () {
            $scope.getMessageList();
            $modalInstance.dismiss("cancel");
        };
    };
      var app= angular.module("xn", ref);
        //拦截器
         app.config(["$httpProvider", function ($httpProvider) {
             $httpProvider.interceptors.push("httpInterceptor");
         }]);
        // 全局配置 form提交验证
        app.config(["xnValidatorProvider", function (xnValidatorProvider) {
            // 全局配置
            xnValidatorProvider.config({
                blurTrig   : false,
                showError  : false,
                removeError: false
            });
            xnValidatorProvider.setRules({

            });
        }]);

        app.controller("BodyController",["$scope","SystemService",function($scope){
                $scope.randomNumber=new Date().getTime();
                //日期转换函数
                Date.prototype.format = function(format){
                    var o = {
                        "M+" : this.getMonth()+1, //month
                        "d+" : this.getDate(),    //day
                        "h+" : this.getHours(),   //hour
                        "m+" : this.getMinutes(), //minute
                        "s+" : this.getSeconds(), //second
                        "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
                        "S" : this.getMilliseconds() //millisecond
                    };
                    if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
                        (this.getFullYear()+"").substr(4 - RegExp.$1.length));
                    for(var k in o)if(new RegExp("("+ k +")").test(format))
                        format = format.replace(RegExp.$1,
                            RegExp.$1.length==1 ? o[k] :
                                ("00"+ o[k]).substr((""+ o[k]).length));
                    return format;
                };


        }])

};
