function setModel(model) { model = JSON.parse(JSON.stringify(model)); $scope.editing = !!model.id; $scope.model = model; $scope.featuredSkills.forEach(fn.set('selected', false)); if (model.skills && model.skills.length) { $scope.featuredSkills.some(function(featured) { var index = $scope.model.skills.indexOf(featured.value); if (index === -1) return; featured.selected = true; $scope.model.skills.splice(index, 1); }); } if (model.start) { var start = Date.parse(model.start); $scope.startMonth = $scope.months[start.getMonth()]; $scope.startYear = start.getFullYear(); if (model.end) { var end = Date.parse(model.end); $scope.endMonth = $scope.months[end.getMonth()]; $scope.endYear = end.getFullYear(); } } $scope.current = model.start && !model.end; afterModelChange(); }
function bindDate(key) { var month = key + 'Month'; var year = key + 'Year'; var storedValue = $scope.model[key]; if (storedValue) { var date = Date.parse(storedValue); $scope[year] = date.getFullYear(); $scope[month] = $scope.months[date.getMonth()]; } $scope[key + 'DateUpdate'] = function() { var value = null; if ($scope[month] && $scope[year]) { var date = Date.get($scope[year], $scope.months.indexOf($scope[month])); value = date.getFullYear() + '-' + (date.getMonth() + 1) + '-01'; } $scope.model[key] = value; }; }