Skip to content

Commit

Permalink
Merge pull request #1001 from civicrm/integration
Browse files Browse the repository at this point in the history
Sync master with integration
  • Loading branch information
Alessandro authored Jul 5, 2016
2 parents 9a4060c + 4370fd5 commit 79d617f
Show file tree
Hide file tree
Showing 110 changed files with 23,177 additions and 13,929 deletions.
11,468 changes: 5,794 additions & 5,674 deletions com.civicrm.hrjobroles/css/hrjobroles.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion com.civicrm.hrjobroles/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var fs = require('fs');
gulp.task('sass', function (done) {
// The app style relies on compass's gems, so we need to rely on it
// for the time being
exec('compass watch', function (_, stdout, stderr) {
exec('compass compile', function (_, stdout, stderr) {
console.log(stdout);
done();
});
Expand Down
9 changes: 7 additions & 2 deletions com.civicrm.hrjobroles/hrjobroles.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,19 @@ function hrjobroles_civicrm_navigationMenu( &$params ) {
* @param $tabs
* @param $contactID
* Create a custom tab for civicrm contact which will implement custom drupal callback function
* this tab should appear after job contracts tab directly
* and since contact summary tab weight is
* -190 we chose this to be -180
* to give some room for other extensions to place
* their tabs between these two.
*/
function hrjobroles_civicrm_tabs(&$tabs, $contactID) {

$url = CRM_Utils_System::url('civicrm/job-roles/' . $contactID);
$tabs[] = array( 'id' => 'hrjobroles',
'url' => $url,
'title' => 'Job Roles',
'weight' => 300 );
'weight' => -180 );
}

/**
Expand Down Expand Up @@ -269,4 +274,4 @@ function hrjobroles_civicrm_export( $exportTempTable, $headerRows, $sqlColumns,
CRM_Core_DAO::executeQuery($query);
}

}
}
3 changes: 1 addition & 2 deletions com.civicrm.hrjobroles/js/dist/job-roles.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ define([
$scope.format = HR_settings.DATE_FORMAT;

var me = this;
var formatDate = $filter('formatDate');
var roles_type = ['funders', 'cost_centers'];

$scope.present_job_roles = [];
Expand All @@ -39,22 +40,17 @@ define([
* Method responsible for updating new JobRole with dates from Contract
*/
$scope.onContractSelected = function () {
var contract = getContractData($scope.edit_data['new_role_id']['job_contract_id']);
var areDatesCustom = $scope.checkIfDatesAreCustom($scope.edit_data['new_role_id']['newStartDate'], $scope.edit_data['new_role_id']['newEndDate']);

if (!areDatesCustom) {
if (!!contract.start_date) {
$scope.edit_data['new_role_id']['newStartDate'] = contract.start_date;
} else {
$scope.edit_data['new_role_id']['newStartDate'] = null;
}
var contract = getContractData($scope.edit_data.new_role_id.job_contract_id);
var areDatesCustom = $scope.checkIfDatesAreCustom($scope.edit_data.new_role_id.newStartDate, $scope.edit_data.new_role_id.newEndDate);

if (!!contract.end_date) {
$scope.edit_data['new_role_id']['newEndDate'] = contract.end_date;
} else {
$scope.edit_data['new_role_id']['newEndDate'] = null;
}
}
formatRoleDates($scope.edit_data.new_role_id, {
start: areDatesCustom ? $scope.edit_data.new_role_id.newStartDate : contract.start_date,
end: areDatesCustom ? $scope.edit_data.new_role_id.newEndDate : contract.end_date
},
{
start: 'newStartDate',
end: 'newEndDate'
});
};

/**
Expand All @@ -73,8 +69,8 @@ define([


angular.forEach(me.contractsData, function (value) {
if ($filter('formatDate')(start) === $filter('formatDate')(value.start_date)
&& $filter('formatDate')(end) === $filter('formatDate')(value.end_date))
if (formatDate(start) === formatDate(value.start_date)
&& formatDate(end) === formatDate(value.end_date))
custom = false;
});

Expand All @@ -88,23 +84,19 @@ define([
*/
$scope.onContractEdited = function (jobContractId, role_id) {
var id = jobContractId || $scope.edit_data[role_id]['job_contract_id'];

var contract = getContractData(id);

var areDatesCustom = $scope.checkIfDatesAreCustom($scope.edit_data[role_id]['start_date'], $scope.edit_data[role_id]['end_date']);

if (!areDatesCustom) {
if (!!contract.start_date) {
$scope.edit_data[role_id]['start_date'] = contract.start_date;
} else {
$scope.edit_data[role_id]['start_date'] = null;
}

if (!!contract.end_date) {
$scope.edit_data[role_id]['end_date'] = contract.end_date;
} else {
$scope.edit_data[role_id]['end_date'] = null;
}
formatRoleDates($scope.edit_data[role_id], {
start: contract.start_date,
end: contract.end_date
});
} else {
formatRoleDates($scope.edit_data[role_id], {
start: $scope.edit_data[role_id].start_date,
end: $scope.edit_data[role_id].end_date
});
}
};

Expand Down Expand Up @@ -322,6 +314,11 @@ define([
$scope.$apply();
return $scope.updateRole(role_id);
});
} else {
formatRoleDates($scope.edit_data[role_id], {
start: $scope.edit_data[role_id].start_date,
end: $scope.edit_data[role_id].end_date
});
}
}
}
Expand All @@ -339,6 +336,21 @@ define([
}
};

/**
* Sets the values of the given role's start and end date properties
* to the Date objects representing the given start and end dates
*
* @param {Object} role - The job role
* @param {Object} dates - An object with `start` and `end ` dates
* @param {Object} keys - Custom names of the role's start and end date properties
*/
function formatRoleDates(role, dates, keys) {
var keys = keys ? keys : { start: 'start_date', end: 'end_date' };

role[keys.start] = !!dates.start ? formatDate(dates.start, Date) : null;
role[keys.end] = !!dates.end ? formatDate(dates.end, Date) : null;
}

/**
* Checks if JobRole dates are actual, if not checks if they exist in any of contract's revisions.
* @param role_id
Expand All @@ -351,17 +363,24 @@ define([

// search for revision containing these dates
var revision = contract.revisions.some(function (rev) {
return rev.period_start_date === $filter('formatDate')($scope.edit_data[role_id]['start_date'])
&& rev.period_end_date === $filter('formatDate')($scope.edit_data[role_id]['end_date']);
return rev.period_start_date === formatDate($scope.edit_data[role_id]['start_date'])
&& rev.period_end_date === formatDate($scope.edit_data[role_id]['end_date']);
});

// check if dates match with revision
if (revision) {
$scope.edit_data[role_id]['start_date'] = contract.start_date;
$scope.edit_data[role_id]['end_date'] = contract.end_date;
formatRoleDates($scope.edit_data[role_id], {
start: contract.start_date,
end: contract.end_date
});

$scope.updateRole(role_id);
}
} else {
formatRoleDates($scope.edit_data[role_id], {
start: $scope.edit_data[role_id].start_date,
end: $scope.edit_data[role_id].end_date
});
}
}

Expand Down Expand Up @@ -397,31 +416,12 @@ define([
|| $scope.edit_data['new_role_id']['job_contract_id'] === '');
};

/**
* Parse dates so they can be correctly read by server.
*
* @param {string|Date} date
* @returns {string|null}
*/
$scope.parseDate = function (date) {

if (date instanceof Date) {
date = date.getTime();
}

var formatted = moment(date, [
'DD/MM/YYYY',
'x',
'YYYY-MM-DD'
]);

return (formatted.isValid()) ? formatted.format('YYYY-MM-DD') : null;
};

/**
* Validates Dates and saves the new Job Role
*/
$scope.saveNewRole = function saveNewRole() {
var newRole;

$log.debug('Add New Role');

$scope.errors = {};
Expand All @@ -441,17 +441,18 @@ define([
});

if (validateResponse) {
newRole = angular.copy($scope.edit_data.new_role_id);

$scope.edit_data.new_role_id.newStartDate = $scope.parseDate($scope.edit_data.new_role_id.newStartDate);
newRole.newStartDate = convertDateToServerFormat(newRole.newStartDate);

if ($scope.edit_data.new_role_id.newEndDate) {
$scope.edit_data.new_role_id.newEndDate = $scope.parseDate($scope.edit_data.new_role_id.newEndDate);
if (newRole.newEndDate) {
newRole.newEndDate = convertDateToServerFormat(newRole.newEndDate);
} else {
delete $scope.edit_data.new_role_id.newEndDate;
delete newRole.newEndDate;
}

// Create the new job role
createJobRole($scope.edit_data.new_role_id).then(function () {
createJobRole(newRole).then(function () {
// Hide the add new form
$scope.add_new = false;

Expand Down Expand Up @@ -499,22 +500,25 @@ define([
* @param role_id
*/
$scope.updateRole = function (role_id, role_type) {
var updatedRole;

$log.debug('Update Role');

if (typeof role_type === 'string') {
filterEmptyData(role_id, role_type);
}

$scope.edit_data[role_id].start_date = $scope.parseDate($scope.edit_data[role_id].start_date);
updatedRole = angular.copy($scope.edit_data[role_id]);
updatedRole.start_date = convertDateToServerFormat(updatedRole.start_date);

if ($scope.edit_data[role_id].end_date) {
$scope.edit_data[role_id].end_date = $scope.parseDate($scope.edit_data[role_id].end_date);
if (updatedRole.end_date) {
updatedRole.end_date = convertDateToServerFormat(updatedRole.end_date);
} else {
delete $scope.edit_data[role_id].end_date;
delete updatedRole.end_date;
}

// Update the job role
updateJobRole(role_id, $scope.edit_data[role_id]).then(function () {
updateJobRole(role_id, updatedRole).then(function () {
return getJobRolesList($scope.$parent.contactId);
});
};
Expand Down Expand Up @@ -875,8 +879,8 @@ define([
revisions: data.values[i]['revisions']
};

var optionalEndDate = $filter('formatDate')(contract.end_date) || 'Unspecified';
contract.label = contract.title + ' (' + $filter('formatDate')(contract.start_date) + ' - ' + optionalEndDate + ')';
var optionalEndDate = formatDate(contract.end_date) || 'Unspecified';
contract.label = contract.title + ' (' + formatDate(contract.start_date) + ' - ' + optionalEndDate + ')';

contractsData[data.values[i]['id']] = contract;
}
Expand Down Expand Up @@ -995,10 +999,6 @@ define([

// Implements the "updateJobRole" service
function updateJobRole(role_id, job_roles_data) {

job_roles_data.end_date = $scope.parseDate(job_roles_data.end_date);
job_roles_data.start_date = $scope.parseDate(job_roles_data.start_date);

return HRJobRolesService.updateJobRole(role_id, job_roles_data).then(function (data) {

if (data.is_error === 1) {
Expand Down Expand Up @@ -1050,6 +1050,18 @@ define([
function getContractData(contractId) {
return me.contractsData[contractId];
}

/**
* Parse dates so they can be correctly read by server.
*
* @param {string|Date} date
* @returns {string|null}
*/
function convertDateToServerFormat(date) {
var dateString = formatDate(date, 'YYYY-MM-DD');

return dateString !== 'Unspecified' ? dateString : null;
}
}
]);
});
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ define([

checkIfValuesAreValid(start, ['start_date']);
checkIfStartIsLowerThanContractEnd(start, contractEnd);
checkIfStartIsLowerThanContractStart(start, contractStart);

if (end === 0 || end) {
end = formatDate(end, this.dateFormats);
Expand All @@ -127,7 +128,6 @@ define([
checkIfEndIsEqualOrLowerThanContractEnd(end, contractEnd);

checkIfStartDateIsLower(start, end);
checkIfStartIsLowerThanContractStart(start, contractStart);
}
}
};
Expand Down
Loading

0 comments on commit 79d617f

Please sign in to comment.