'use strict';

app.directive('deviceBtnMove', function() {
  return {
    restrict: 'E',
    replace: true,
    scope: {
      ngModel: '=',
      selectedBtn: '=',
      exists: '='
    },
    template: '<a title="Move button to another page" ng-click="showModal()"><i class="fa fa-fw fa-lg fa-exchange action-icon"></i></a>',
    controller: function($scope, $element, $modal) {
      var moveModal = $modal({ scope: $scope, title: 'Move button to another page', placement: 'top', template:'views/modal-tpls/device-move-btn.html', show:false});
      
      function showModal() {
        $scope.popupDialog = {};
        moveModal.$promise.then(moveModal.show);
      }
      function hideModal() {
        moveModal.$promise.then(moveModal.hide);
      }

      $scope.showModal = showModal;

      $scope.swapButtons = function(source, dest) {
        var temp1 = _.omit(source, ['id', 'page_btn_idx', 'name', 'device_id', 'room_id']),
            temp2 = _.omit(dest, ['id', 'page_btn_idx', 'name', 'device_id', 'room_id']);

        console.log(temp1);
        console.log(temp2);

        for (var prop1 in temp1) {
          dest[prop1] = temp1[prop1];
        }

        for (var prop2 in temp2) {
          source[prop2] = temp2[prop2];
        }

        hideModal();
      };
      
    }
  };
});