var angular = require('angular');
require('../modules');
require('../services/InfoReleaseService');
'use strict';

var module = angular.module('info');
module.controller('InfoDetailCggsCtrl', function($scope, $state,
  $stateParams, $q, InfoReleaseService, $location) {

  var modelId = $stateParams.modelId,
    infoId = $stateParams.infoId,
    pageNo = parseInt($location.search().pageNo);
  $scope.title = '出国公示';
  $scope.recordId = infoId.split('new')[0];
  var model;

  /**
   * 初始化页面
   */
  $scope.$on('$ionicView.enter', function() {
    init(model);
  });

  function init(model) {
    return InfoReleaseService.getInfoByInfoId(modelId, infoId).then(function(data) {
      $scope.inf = data;
      $scope.waitError = false;
    }, function() {
      $scope.waitingText = '加载失败...';
      $scope.waitError = true;
    });
  }

  /**
   * 返回
   * @return 转到更多页面
   */
  $scope.goBack = function(){
    $state.go('infoRelease-infoReleaseMoreCggs', {
      modelId: modelId,
      pageNo: pageNo,
      enterSign: 'detail'
    });
  };

  /**
   * 刷新
   */
  $scope.onRefresh = function() {
    $scope.loaderror = false;
    init();
  };

  $scope.filterFn = function(affix) {
    return affix && affix.isPublic === true;
  };

});
