Skip to content

Commit

Permalink
EditJobs: check color & set random default color
Browse files Browse the repository at this point in the history
+ set default = assigned
  • Loading branch information
lbayle committed May 1, 2016
1 parent 5be1fa4 commit 9a8a0ae
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
17 changes: 15 additions & 2 deletions admin/edit_jobs.php
Expand Up @@ -22,12 +22,14 @@

class EditJobsController extends Controller {

private static $logger;
/**
* Initialize complex static variables
* @static
*/
public static function staticInit() {
// Nothing special
self::$logger = Logger::getLogger(__CLASS__);
}

protected function display() {
Expand All @@ -37,6 +39,10 @@ protected function display() {
if ($session_user->isTeamMember(Config::getInstance()->getValue(Config::id_adminTeamId))) {
$this->smartyHelper->assign('jobType', Job::$typeNames);

// set random color
$rndJobColor = sprintf('%06X', mt_rand(0, 0xFFFFFF));
$this->smartyHelper->assign('rndJobColor', $rndJobColor);

$action = Tools::getSecurePOSTStringValue('action', 'none');

if ('addJob' == $action) {
Expand All @@ -46,8 +52,15 @@ protected function display() {

// TODO check if not already in table !

// save to DB
Jobs::create($job_name, $job_type, $job_color);
//Check for a hex color string without hash 'c1c2b4'
$job_color_trim = trim(str_replace("#", "", $job_color));
if(preg_match('/^[a-f0-9]{6}$/i', $job_color_trim)) {
// save to DB
Jobs::create($job_name, $job_type, $job_color_trim);
} else {
$this->smartyHelper->assign('error', T_("Invalid Color : '$job_color' ($job_color_trim)"));
}


} elseif ('addAssociationProject' == $action) {

Expand Down
2 changes: 1 addition & 1 deletion classes/jobs.class.php
Expand Up @@ -26,8 +26,8 @@ class Job extends Model implements Comparable {
const type_assignedJob = 1; // jobs specific to one or more projects are type 1

public static $typeNames = array(
self::type_assignedJob => "Assigned",
self::type_commonJob => "Common",
self::type_assignedJob => "Assigned"
);

private $id;
Expand Down
5 changes: 3 additions & 2 deletions tpl/edit_jobs.html
Expand Up @@ -9,6 +9,7 @@
{/if}

<div id="content">
<script type="text/javascript" src="js_min/datatable.min.js"></script>
{if isset($jobType)}
<div style="margin-top: 2em;padding: 0 1em 1em;"class="ui-widget-content">
<h2>{t}Jobs{/t}</h2>
Expand Down Expand Up @@ -50,7 +51,7 @@ <h2>{t}Jobs{/t}</h2>
{/foreach}
</select>
<label for="colorpicker">{t}Color{/t}:</label>
<input style="background-color: #FFFFFF" name="job_color" type="text" id="job_color" value="FFFFFF" title="format: FFFFFF" size="6" />
<input style="background-color: #FFFFFF" name="job_color" type="text" id="job_color" value="{$rndJobColor}" title="format: FFFFFF" size="6" />
<input type="button" id="addJob" name="btAddJob" value="{t}Add{/t}" />
&nbsp;&nbsp;&nbsp;<a href='http://www.colorschemer.com/online.html' target='_blank' title="{t}open a colorPicker in a new Tab{/t}">ColorPicker</a>
<input type="hidden" name="action" value="addJob" />
Expand Down Expand Up @@ -179,7 +180,7 @@ <h2 title="{t}Job Assignations{/t}">{t}Job Assignations{/t}</h2>
}
}
</script>
<table>
<table class="datatable_csv">
<!-- <caption>Assigned Jobs</caption> -->
<thead>
<tr>
Expand Down

0 comments on commit 9a8a0ae

Please sign in to comment.