UNPKG

gaf-mobile

Version:

GAF mobile Web site

62 lines (56 loc) 1.9 kB
'use strict'; angular.module('gafMobileApp') .controller('HirePageCtrl', function($scope, $route, $location, $http, Projects) { if ($route.current.locals.job) { // A valid job has been specified, i.e. /hire/Graphic-Design $scope.job = $route.current.locals.job; } else if ($route.current.locals.h1) { // A job title has been specified, with either an h1 search param or // through a /hire/Something-not-a-valid-job path $scope.h1 = $route.current.locals.h1; } else { $scope.job = ''; $scope.h1 = ''; } $scope.startProjectFromJob = function(job) { Projects.getCurrent().set({ jobs: [job] }); $location.path('/post-project'); }; // TODO: duplicate of home page -> create a component // [TEMP] Skill select service code. To be rewritten when the skill select // service leaves the prototype stage $scope.startWithQuery = function(query) { // Reset previous project Projects.getCurrent().reset(); var skills; var templateId; $http.get('https://m.freelancer.com/suggest-skill', { params: { q: query } }).then(function(response) { if (response.data) { skills = response.data.skills; templateId = response.data.template; } }).finally(function() { // Fail safe (prototype!). We always move to the next step whatever // happens var params = 'title=' + encodeURIComponent(query.charAt(0).toUpperCase() + query.slice(1)); if (templateId === 0) { // Hardcoded for now but could be exdented when we have a template API $location.url('post-project/Web-development/?' + params); } else if (skills && skills.length) { params += '&jobs=' + skills.join(); $location.url('post-project/mobile/?' + params); } else { $location.url('post-project/?' + params); } }); }; });