'use strict';

var angular = require('angular');
require('../modules');

var module = angular.module('initializeset.directives');

/**
* 省份选择控制器
*/
module.directive('sinoSetUrl', function($ionicModal) {
  return {
    restrict: 'A',
    replace: false,
    link: function(scope, element) {
      element.on('click', function() {
        if(!scope.settingModal) {
          $ionicModal.fromTemplateUrl('views/initializeset/setUrl.login.tpl.html', function(modal) {
            scope.settingModal = modal;
            scope.settingModal.show();
          }, {
            scope: scope,
            animation: 'slide-in-up'
          });
        } else {
          scope.settingModal.show();
        }
      });
      
      scope.closeSettingModal = function() {
        return scope.settingModal.remove().then(function() {
          scope.settingModal = null;
        });
      };
      
      scope.$on('$destroy', function() {
        if (scope.settingModal) {
          scope.settingModal.remove();
          scope.settingModal = null;
        }
      });
    }
  };
});
