Skip to content

Instantly share code, notes, and snippets.

@rodrigogalindez
Created August 21, 2015 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodrigogalindez/1a620dc3de8d2c5052ca to your computer and use it in GitHub Desktop.
Save rodrigogalindez/1a620dc3de8d2c5052ca to your computer and use it in GitHub Desktop.
// 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