gaf-mobile
Version:
GAF mobile Web site
68 lines (61 loc) • 2.17 kB
JavaScript
module('gafMobileApp')
/**
* @ngdoc controller
* @name gafMobileApp.ProjectTemplatesCtrl
* @description
* Controller for the post project chessboard page
*/
.controller('ProjectTemplatesCtrl', function($q, $location, Budgets,
JobBundles, Categories, Preload, Projects, ProjectTemplates,
Experiments) {
var _this = this;
var preloads = [];
// TODO: Clean this up when ShowNewTemplates A/B test is done
_this.showNewTemplates = Experiments.activateTest('ShowNewTemplates');
/**
* @ngdoc property
* @name gafMobileApp.ProjectTemplatesCtrl#templatesPromise
* @propertyOf gafMobileApp.ProjectTemplatesCtrl
* @description
* Stores the promise for getting the project templates
*/
var templatesPromise = ProjectTemplates.get()
.then(function(templateList) {
return templateList;
});
// Preload the project templates at initialization
preloads.push(templatesPromise);
/**
* @ngdoc method
* @name gafMobileApp.ProjectTemplatesCtrl#startFromTemplate
* @methodOf gafMobileApp.ProjectTemplatesCtrl
* @description
* Starts a new project based on a chosen template
*/
_this.startFromTemplate = function(templateId, fallbackCategory, $event,
contest) {
// Reset previous project
Projects.getCurrent().reset();
// Stop href from firing
$event.preventDefault();
if(contest) {
Projects.getCurrent().set({ type: 'contest' });
}
_this.processing = {};
_this.processing[templateId] = true;
templatesPromise.then(function(templateList) {
var templateUrl = templateList.getById(templateId).getSeoUrl();
$location.url('post-project/' + templateUrl +
'?fallback-cat=' + fallbackCategory);
});
};
// Preload the budgets & currencies list and the project bundles as
// we are going to need them soon
$q.all(preloads).then(function() {
Preload.routes('post-project');
Categories.getListWithJobs();
Budgets.getWithCurrencies({ project_type: 'fixed' });
JobBundles.getCategoriesWithBundles();
});
});
;
angular.