Commit 1a030534 authored by Jerome Mariette's avatar Jerome Mariette

modify database so user have organism and location information + gui handling this feature

parent f144c949
......@@ -275,6 +275,8 @@ CREATE TABLE IF NOT EXISTS `fe_groups` (
`crdate` int(11) unsigned NOT NULL DEFAULT '0',
`cruser_id` int(11) unsigned NOT NULL DEFAULT '0',
`title` varchar(50) NOT NULL DEFAULT '',
`organism` varchar(50) NOT NULL DEFAULT '',
`location` varchar(50) NOT NULL DEFAULT '',
`hidden` tinyint(3) unsigned NOT NULL DEFAULT '0',
`lockToDomain` varchar(50) NOT NULL DEFAULT '',
`deleted` tinyint(3) unsigned NOT NULL DEFAULT '0',
......
......@@ -441,13 +441,11 @@ class tx_nG6_eid {
$col = trim(t3lib_div::_GP('gender'));
$project_id = trim(t3lib_div::_GP('project_id'));
$name_start = trim(t3lib_div::_GP('name_start'));
// user search
if($col != 'group'){
$name_start = trim(t3lib_div::_GP('name_start'));
if($col != 'title' && $col != 'location' && $col != 'organism'){
$res = tx_nG6_db::get_all_names_starting_with($name_start, $col);
foreach($res as $res_id => $res_val){
// find right on project
$res[$res_id]['right_id'] = tx_nG6_db::get_user_right_on_project($res_val['uid'], $project_id);
......@@ -459,10 +457,8 @@ class tx_nG6_eid {
// group search
}else{
$group_name_start = trim(t3lib_div::_GP('group_name'));
$res = tx_nG6_db::get_all_group_starting_with($group_name_start);
$res = tx_nG6_db::get_all_starts_with_in_group($name_start, $col);
}
$json_res = json_encode($res);
print $json_res;
......@@ -473,7 +469,9 @@ class tx_nG6_eid {
$user_name = trim(t3lib_div::_GP('username'));
$project_id = trim(t3lib_div::_GP('project_id'));
$right_id = trim(t3lib_div::_GP('right'));
$group_name = trim(t3lib_div::_GP('group'));
$group_name = trim(t3lib_div::_GP('title'));
$location = trim(t3lib_div::_GP('location'));
$organism = trim(t3lib_div::_GP('organism'));
$email = trim(t3lib_div::_GP('email'));
$first_name = trim(t3lib_div::_GP('first_name'));
$last_name = trim(t3lib_div::_GP('last_name'));
......@@ -490,7 +488,7 @@ class tx_nG6_eid {
if( !isset($group_id) ){
$cruser_id = trim(t3lib_div::_GP('creator'));
tx_nG6_db::create_new_group($cruser_id, $group_name);
tx_nG6_db::create_new_group($cruser_id, $group_name, $organism, $location);
$group_id = tx_nG6_db::get_group_id($group_name);
}
......
......@@ -1730,7 +1730,7 @@ class tx_nG6_db {
*/
function get_all_names_starting_with($name_start, $user_col) {
$queryParts = Array(
'SELECT' => 'fe_users.uid, fe_users.username, fe_users.last_name, fe_users.first_name, fe_users.password, fe_users.email, fe_users.cruser_id, fe_groups.title',
'SELECT' => 'fe_users.uid, fe_users.username, fe_users.last_name, fe_users.first_name, fe_users.password, fe_users.email, fe_users.cruser_id, fe_groups.title, fe_groups.organism, fe_groups.location',
'FROM' => 'fe_users INNER JOIN fe_groups ON fe_users.usergroup=fe_groups.uid',
'WHERE' => 'fe_users.'.$user_col.' LIKE "'.$name_start.'%"',
'GROUPBY' => '',
......@@ -1747,8 +1747,11 @@ class tx_nG6_db {
'last_name' => $res_row['last_name'],
'password' => $res_row['password'],
'email' => $res_row['email'],
'group' => $res_row['title'],
'cruser_id' => $res_row['cruser_id']
'title' => $res_row['title'],
'cruser_id' => $res_row['cruser_id'],
'organism' => $res_row['organism'],
'location' => $res_row['location']
);
}
return $res_tab;
......@@ -1758,25 +1761,39 @@ class tx_nG6_db {
/**
* Get all groupnames starting with a string.
*
* @param string $group_name_start the string part
* @param string $starts_with the string part
* @param string $col the colone name to seek in
* @return array
*/
function get_all_group_starting_with($group_name_start) {
function get_all_starts_with_in_group($starts_with, $col) {
$queryParts = Array(
'SELECT' => 'fe_groups.uid, fe_groups.title',
'SELECT' => '*',
'FROM' => 'fe_groups',
'WHERE' => 'fe_groups.title LIKE "'.$group_name_start.'%"',
'WHERE' => 'fe_groups.'.$col.' LIKE "'.$starts_with.'%"',
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => '',
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$res_tab = array();
$distinct = array();
while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$res_tab[] = array(
'uid' => $res_row['uid'],
'title' => $res_row['title']
);
if( $col == 'title') {
$res_tab[] = array(
'uid' => $res_row['uid'],
'title' => $res_row['title'],
'organism' => $res_row['organism'],
'location' => $res_row['location']
);
} else {
if( !isset($distinct[$res_row[$col]]) ) {
$res_tab[] = array(
'uid' => $res_row['uid'],
$col => $res_row[$col]
);
$distinct[$res_row[$col]] = True ;
}
}
}
return $res_tab;
}
......@@ -2062,12 +2079,14 @@ class tx_nG6_db {
*
* @param array $group_datas the group array
*/
function create_new_group($cruser_id, $group_name) {
function create_new_group($cruser_id, $group_name, $organism, $location) {
// Create new user
$group_datas = array(
'cruser_id' => $cruser_id,
'title' => $group_name,
'organism' => $organism,
'location' => $location,
'hidden' => 0,
'deleted' => 0,
'description' => '',
......
......@@ -422,10 +422,24 @@ $(function () {
add_user_html += ' <div class="control-group">';
add_user_html += ' <label class="control-label">Laboratory</label>';
add_user_html += ' <div class="controls">';
add_user_html += ' <input type="text" id="user_group_val" name="user_group_val" placeholder="Laboratory"/>';
add_user_html += ' <input type="text" id="title_val" class="group_typeahead" name="title_val" placeholder="Laboratory"/>';
add_user_html += ' </div>';
add_user_html += ' </div>';
add_user_html += ' <div class="control-group">';
add_user_html += ' <label class="control-label">Organism</label>';
add_user_html += ' <div class="controls">';
add_user_html += ' <input type="text" id="organism_val" class="group_typeahead" name="organism_val" placeholder="Organism"/>';
add_user_html += ' </div>';
add_user_html += ' </div>';
add_user_html += ' <div class="control-group">';
add_user_html += ' <label class="control-label">Location</label>';
add_user_html += ' <div class="controls">';
add_user_html += ' <input type="text" id="location_val" class="group_typeahead" name="location_val" placeholder="Location"/>';
add_user_html += ' </div>';
add_user_html += ' </div>';
add_user_html += ' <div class="control-group">';
add_user_html += ' <label class="control-label">Right</label>';
add_user_html += ' <div class="controls">';
......@@ -467,7 +481,9 @@ $(function () {
$("#username_val").val(item.username);
$("#user_password_pwd_val").val(item.password);
$("#email_val").val(item.email);
$("#user_group_val").val(item.group);
$("#title_val").val(item.title);
$("#organism_val").val(item.organism);
$("#location_val").val(item.location);
$('select#cbb_user_right option[value='+item.right_id+']').attr("selected","selected");
lock_fields(1);
},
......@@ -488,16 +504,31 @@ $(function () {
}
});
$('#user_group_val').typeahead({
$('.group_typeahead').typeahead({
minLength: 2,
onselect: function(item) {
console.log(item)
if( item.hasOwnProperty('title') ) {
$("#title_val").val(item.title);
$("#organism_val").val(item.organism);
$("#location_val").val(item.location);
lock_group_fields(1);
} else if( item.hasOwnProperty('organism') ) {
$("#organism_val").val(item.organism);
} else if( item.hasOwnProperty('location') ) {
$("#location_val").val(item.location);
}
},
source: function (typeahead, query) {
var gender = $(typeahead["$element"][0]).attr("id").split("_val")[0];
$.ajax({
url: "index.php?eID=tx_nG6&type=autocomplete&gender=group&project_id=" + $("#current_project_id").val() + "&name_start=" + query,
url: "index.php?eID=tx_nG6&type=autocomplete&gender="+gender+"&project_id=" + $("#current_project_id").val() + "&name_start=" + query,
dataType: 'json',
success: function (groups) {
success: function (users) {
var data = new Array();
for (index in groups) {
data.push({'value': groups[index]["title"]});
for (index in users) {
users[index]['value'] = users[index][gender];
data.push(users[index]);
}
typeahead.process(data);
}
......@@ -520,9 +551,12 @@ $(function () {
$("#username_val").val("");
$("#user_password_pwd_val").val("");
$("#email_val").val("");
$("#user_group_val").val("");
$("#title_val").val("");
$("#organism_val").val("");
$("#location_val").val("");
$('select#cbb_user_right option[value=0]').attr("selected","selected");
lock_fields(0); // unlock fields
lock_group_fields(0); // unlock fields
$("#new_member div.control-group").removeClass("error");
$(".btn-danger").removeClass("btn-danger");
$(".icon-wrench").removeClass("icon-white");
......@@ -538,7 +572,9 @@ $(function () {
$("#first_name_val").attr('disabled', 'disabled');
$("#email_val").attr('disabled', 'disabled');
$("#key_gen_btn").addClass('disabled');
$("#user_group_val").attr('disabled', 'disabled');
$("#title_val").attr('disabled', 'disabled');
$("#organism_val").attr('disabled', 'disabled');
$("#location_val").attr('disabled', 'disabled');
$("#user_password_pwd_val").attr('disabled', 'disabled');
// unlock fields
} else if(order == 0){
......@@ -547,10 +583,27 @@ $(function () {
$("#first_name_val").removeAttr('disabled');
$("#email_val").removeAttr('disabled');
$("#key_gen_btn").removeClass('disabled');
$("#user_group_val").removeAttr('disabled');
$("#title_val").removeAttr('disabled');
$("#organism_val").removeAttr('disabled');
$("#location_val").removeAttr('disabled');
$("#user_password_pwd_val").removeAttr('disabled');
}
}
// lock/unlock fields when autocomplete
function lock_group_fields(order){
// lock fields
if(order == 1){
$("#title_val").attr('disabled', 'disabled');
$("#organism_val").attr('disabled', 'disabled');
$("#location_val").attr('disabled', 'disabled');
// unlock fields
} else if(order == 0){
$("#title_val").removeAttr('disabled');
$("#organism_val").removeAttr('disabled');
$("#location_val").removeAttr('disabled');
}
}
if($("#username_val").attr('disabled') != 'disabled'){
$("#new_member").validate({
......@@ -559,7 +612,9 @@ $(function () {
email_val: { required: true, email: true },
last_name_val: { required: true },
username_val: { required: true },
user_group_val: { required: true },
title_val: { required: true },
organism_val: { required: true },
location_val: { required: true },
user_password_pwd_val: { required: true }
},
messages: {
......@@ -567,7 +622,9 @@ $(function () {
email_val: null,
last_name_val: null,
username_val: null,
user_group_val: null,
title_val: null,
organism_val: null,
location_val: null,
user_password_pwd_val: null
},
submitHandler: function(form) {
......@@ -580,7 +637,9 @@ $(function () {
val_url += "&clearpassword=" + $("#user_password_pwd_val").val();
val_url += "&email=" + $("#email_val").val();
val_url += "&creator=" + $("#user_id").val();
val_url += "&group=" + $("#user_group_val").val();
val_url += "&title=" + $("#title_val").val();
val_url += "&organism=" + $("#organism_val").val();
val_url += "&location=" + $("#location_val").val();
val_url += "&project_id=" + $("#current_project_id").val();
val_url += "&right=" + $("#cbb_user_right").val();
val_url += "&pid=" + $("#pid").val();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment