Created
August 21, 2015 12:30
-
-
Save rodrigogalindez/1a620dc3de8d2c5052ca to your computer and use it in GitHub Desktop.
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
// when user clicks on button 'startJob', this is the function that it triggers: | |
$scope.startJob = function() { | |
if ($scope.areThereAvailableSegments(jobId)) { | |
console.log('there are available segments, so we show the text editor'); | |
} else { | |
console.log('sorry, no more segments available, capo!') | |
} | |
}; | |
// returns true or false if there are segments available | |
$scope.areThereAvailableSegments = function(jobId) { | |
var dump = []; | |
$scope.populateSegments(jobId, function whenDone() { | |
for (var i = 0; i < $scope.segments.length; i++) { | |
dump.push($scope.segments[i].status); // dumps status into a temp array | |
} | |
// in this moment, dump = ['available', 'translated'] | |
if (dump.indexOf('available') >= 0) { | |
return true; // if there's one 'available', returns true | |
} else { | |
return false; | |
} | |
}); | |
}; | |
// gets the segments from the API and populates $scope.segments | |
$scope.populateSegments = function(jobId, callback) { | |
SegmentsService.getSegments(jobId) | |
.then(function(segments) { | |
segments.sort(function(a,b) { | |
return a.sequence - b.sequence; | |
}); | |
$scope.segments = segments; | |
callback(); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment