Created
November 18, 2013 22:20
-
-
Save selahlynch/7536421 to your computer and use it in GitHub Desktop.
Decision Directive Definition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('startup.directives.decision', []) | |
.directive('decisionMaker', ['simulatePushChannel', function (simulatePushChannel) { | |
return{ | |
restrict: 'E', | |
templateUrl: 'views/directives/decision.html', | |
scope: { | |
runId:"=", | |
roles:"=", | |
founderName:"=", | |
decisions:"=decisionsData", | |
decisionType:"@", | |
tweetsEnabled:"@" | |
}, | |
controller: ['$scope', '$attrs', 'Decisions', function ($scope, $attrs, Decisions){ | |
$scope.decisionType = $attrs.decisionType; | |
$scope.$watch('decisions', function(newVal, oldVal) { | |
//watch decisions, any time they change, update this | |
$scope.decisionEdits = _.map($scope.decisions, function(decision, i){return {editOn:false}}); | |
}, true); | |
var d = Decisions($scope.runId); | |
var addDecision, rmDecision, updDecision; | |
if($scope.decisionType === "hire"){ | |
addDecision = d.addHire; | |
rmDecision = d.rmHire; | |
updDecision = d.updHire; | |
} | |
else if($scope.decisionType === "investment"){ | |
addDecision = d.addInvestment; | |
rmDecision = d.rmInvestment; | |
updDecision = d.updInvestment; | |
} | |
else{ | |
throw new Error("Invalid decision type"); | |
} | |
$scope.editDecision = function(i){ | |
$scope.decisionEdits[i].editOn = true; | |
$scope.decisionEdits[i].shares = $scope.decisions[i].shares; | |
$scope.decisionEdits[i].capital = $scope.decisions[i].capital; | |
}; | |
$scope.cancelEdit = function(i){ | |
$scope.decisionEdits[i].editOn = false; | |
}; | |
$scope.saveDecision = function(i){ | |
updDecision($scope.founderName, $scope.decisions[i].role, Number($scope.decisionEdits[i].shares), Number($scope.decisionEdits[i].capital)).then(function(){ | |
$scope.$emit("DecisionsChanged"); | |
$scope.decisionEdits = _.map($scope.decisions, function(decision, i){return {editOn:false}}); | |
}); | |
}; | |
$scope.deleteDecision = function(i){ | |
$scope.indexForDecisionUpdate = -1; | |
rmDecision($scope.founderName, $scope.decisions[i].role). | |
then(function(){ | |
$scope.$emit("DecisionsChanged"); | |
}); | |
}; | |
$scope.addDecision = function(){ | |
addDecision($scope.founderName, $scope.newDecision.role, Number($scope.newDecision.shares), Number($scope.newDecision.capital)).then(function(){ | |
if($scope.tweetsEnabled == "true"){ | |
if ($scope.decisionType === 'hire'){ | |
simulatePushChannel.sendChatMessage($scope.founderName + " hired " + $scope.newDecision.role); | |
} | |
if ($scope.decisionType === 'investment'){ | |
simulatePushChannel.sendChatMessage($scope.newDecision.role + " invested in "+ $scope.founderName); | |
} | |
} | |
$scope.newDecision = {}; | |
$scope.$emit("DecisionsChanged"); | |
}); | |
}; | |
}] | |
}; | |
}]); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment