Commit b7b4e8fd authored by Jerome Mariette's avatar Jerome Mariette
Browse files

make the project table be reloaded with ajax

parent 243fe1b8
......@@ -605,6 +605,33 @@ class tx_nG6_eid {
$smarty->assign('is_at_least_admin_of_1_run', $is_at_least_admin_of_1_run);
$smarty->assign('login_user', $login_user);
print $smarty->fetch('run_table.tpl');
} elseif($type == 'projects_table') {
$smarty = new Smarty();
$smarty->setTemplateDir(t3lib_extMgm::extPath('nG6').'/pi1');
$smarty->setCompileDir(t3lib_extMgm::extPath('nG6').'/res/smarty/templates_c');
$smarty->setCacheDir(t3lib_extMgm::extPath('nG6').'/res/smarty/cache');
$smarty->setConfigDir(t3lib_extMgm::extPath('nG6').'/res/smarty/configs');
$smarty->security = true;
$smarty->security_settings['MODIFIER_FUNCS'] = array('count');
$user_id = trim(t3lib_div::_GP('user_id'));
$login_user = intVal(trim(t3lib_div::_GP('login_user')));
$page_id = intVal(trim(t3lib_div::_GP('page_id')));
$projects = tx_nG6_db::select_all_user_projects($user_id, 'tx_nG6_project.name');
$is_at_least_admin_of_1_project = false;
foreach($projects as $project_id => $project_values) {
$is_admin = tx_nG6_db::is_project_administrator($user_id, $project_values['id']);
if ($is_admin) { $is_at_least_admin_of_1_project = true; }
$projects[$project_id]['is_admin'] = $is_admin;
$projects[$project_id]['is_manager'] = tx_nG6_db::is_project_manager($user_id, $project_values['id']);
$projects[$project_id]['is_member'] = tx_nG6_db::is_project_member($user_id, $project_values['id']);
$href = '<a href="index.php?id='.$page_id.'&tx_nG6_pi1[project_id]='.$project_values['id'].'">'.$project_values['name'].'</a>';
$projects[$project_id]['href'] = $href;
}
$smarty->assign('projects', $projects);
$smarty->assign('is_at_least_admin_of_1_project', $is_at_least_admin_of_1_project);
$smarty->assign('login_user', $login_user);
print $smarty->fetch('project_table.tpl');
}
}
......
......@@ -563,7 +563,7 @@ class tx_nG6_db {
foreach($project_analysis as $analysis_id => $analysis_values) {
tx_nG6_db::hide_analysis($analysis_values['id']);
}
tx_nG6_db::unpublish_project($p_id);
// Finaly change the project itself
$GLOBALS['TYPO3_DB']-> exec_UPDATEquery ('tx_nG6_project', 'uid='.$p_id, array('hidden' => '1'));
}
......
{*
Copyright (C) 2009 INRA
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*}
<table class="table table-striped table-bordered dataTable" id="project_data_table">
<thead>
<tr>
{if $is_at_least_admin_of_1_project && $login_user}
<th><center><input type="checkbox" id="chk_all_project"></center></th>
{/if}
<th>Project Name</th>
<th>Date</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{foreach from=$projects key=project_id item=project_values}
{assign var="classes" value=""}
{if $login_user && $project_values.public == 0 && $project_values.is_admin}
{$classes = $classes|cat:"<span class='label label-warning'>Public</span> "}
{/if}
{if $project_values.hidden == 1}
{$classes = $classes|cat:" <span class='label label-info'>Hidden</span> "}
{/if}
{if ($project_values.hidden == 1 && $project_values.is_admin) || $project_values.hidden == 0}
<tr id="tr_project_{$project_values.id}">
{if $project_values.is_admin}
<td><center><input type="checkbox" id="chk_project_{$project_values.id}" value="project_{$project_values.id}"></center></td>
{elseif $is_at_least_admin_of_1_project}
<td></td>
{/if}
{if $project_values.is_admin}
<td class="editable">
{$classes} <span class="editable" data-type="text" data-pk="{$project_values.id}" data-url="index.php?eID=tx_nG6&type=update_db_field&table=tx_nG6_project&field=name" data-original-title="Enter project name">{$project_values.href}</span>
</td>
{else}
<td>
{$project_values.href}
</td>
{/if}
{if $project_values.is_admin}
<td class="editable">
<span class="editable-date" data-type="date" data-pk="{$project_values.id}" data-url="index.php?eID=tx_nG6&type=update_db_field&table=tx_nG6_project&field=crdate" data-original-title="Select date">{$project_values.date|date_format:"%d/%m/%Y"}</span>
</td>
{else}
<td>
{$project_values.date|date_format:"%d/%m/%Y"}
</td>
{/if}
{if $project_values.is_admin}
<td class="editable">
<span class="editable" data-type="textarea" data-pk="{$project_values.id}" data-url="index.php?eID=tx_nG6&type=update_db_field&table=tx_nG6_project&field=description" data-original-title="Enter description"> {$project_values.description}</span>
</td>
{else}
<td>
{$project_values.description}
</td>
{/if}
</tr>
{/if}
{/foreach}
</tbody>
{if $is_at_least_admin_of_1_project && $login_user}
<tfoot>
<tr>
<th align="left" colspan="4">
With selection :
<div class="btn-group">
<button id="hide_project" type="button" class="btn btn-small"><i class=" icon-eye-close"></i> hide</button>
<button id="unhide_project" type="button" class="btn btn-small"><i class="icon-eye-open"></i> unhide</button>
</div>
<div class="btn-group">
<button id="add_project" type="button" class="btn btn-small"><i class="icon-plus"></i> add</button>
<button id="delete_project" type="button" class="btn btn-small"><i class="icon-minus"></i> delete</button>
</div>
<div class="btn-group">
<button id="publish_project" type="button" class="btn btn-small"><i class="icon-thumbs-up"></i> publish</button>
<button id="unpublish_project" type="button" class="btn btn-small"><i class="icon-thumbs-down"></i> unpublish</button>
</div>
</th>
</tr>
</tfoot>
{/if}
</table>
\ No newline at end of file
......@@ -271,88 +271,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</div>
<div style="clear:both"></div>
</div>
<div class="sub-content sc-bottom">
<table class="table table-striped table-bordered dataTable" id="project_data_table">
<thead>
<tr>
{if $is_at_least_admin_of_1_project && $login_user}
<th><center><input type="checkbox" id="chk_all_project"></center></th>
{/if}
<th>Project Name</th>
<th>Date</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{foreach from=$projects key=project_id item=project_values}
{assign var="classes" value=""}
{if $login_user && $project_values.public == 0 && $project_values.is_admin}
{$classes = $classes|cat:"<span class='label label-warning'>Public</span> "}
{/if}
{if $project_values.hidden == 1}
{$classes = $classes|cat:" <span class='label label-info'>Hidden</span> "}
{/if}
{if ($project_values.hidden == 1 && $project_values.is_admin) || $project_values.hidden == 0}
<tr id="tr_project_{$project_values.id}">
{if $project_values.is_admin}
<td><center><input type="checkbox" id="chk_project_{$project_values.id}" value="project_{$project_values.id}"></center></td>
{elseif $is_at_least_admin_of_1_project}
<td></td>
{/if}
{if $project_values.is_admin}
<td class="editable">
{$classes} <span class="editable" data-type="text" data-pk="{$project_values.id}" data-url="index.php?eID=tx_nG6&type=update_db_field&table=tx_nG6_project&field=name" data-original-title="Enter project name">{$project_values.href}</span>
</td>
{else}
<td>
{$project_values.href}
</td>
{/if}
{if $project_values.is_admin}
<td class="editable">
<span class="editable-date" data-type="date" data-pk="{$project_values.id}" data-url="index.php?eID=tx_nG6&type=update_db_field&table=tx_nG6_project&field=crdate" data-original-title="Select date">{$project_values.date|date_format:"%d/%m/%Y"}</span>
</td>
{else}
<td>
{$project_values.date|date_format:"%d/%m/%Y"}
</td>
{/if}
{if $project_values.is_admin}
<td class="editable">
<span class="editable" data-type="textarea" data-pk="{$project_values.id}" data-url="index.php?eID=tx_nG6&type=update_db_field&table=tx_nG6_project&field=description" data-original-title="Enter description"> {$project_values.description}</span>
</td>
{else}
<td>
{$project_values.description}
</td>
{/if}
</tr>
{/if}
{/foreach}
</tbody>
{if $is_at_least_admin_of_1_project && $login_user}
<tfoot>
<tr>
<th align="left" colspan="4">
With selection :
<div class="btn-group">
<button id="hide_project" type="button" class="btn btn-small"><i class=" icon-eye-close"></i> hide</button>
<button id="unhide_project" type="button" class="btn btn-small"><i class="icon-eye-open"></i> unhide</button>
</div>
<div class="btn-group">
<button id="add_project" type="button" class="btn btn-small"><i class="icon-plus"></i> add</button>
<button id="delete_project" type="button" class="btn btn-small"><i class="icon-minus"></i> delete</button>
</div>
<div class="btn-group">
<button id="publish_project" type="button" class="btn btn-small"><i class="icon-thumbs-up"></i> publish</button>
<button id="unpublish_project" type="button" class="btn btn-small"><i class="icon-thumbs-down"></i> unpublish</button>
</div>
</th>
</tr>
</tfoot>
{/if}
</table>
<div id="projects" class="sub-content sc-bottom">
{include file='project_table.tpl'}
</div>
{/if}
......
......@@ -64,6 +64,9 @@
$(function () {
initEditableFields();
initCheckboxes();
// Init tables
var projectTable = initProjectTable(),
runTable = initRunTable(),
......@@ -72,8 +75,9 @@ $(function () {
// Grab relevant info from URL fragment
var params = simpleQueryParams(location.href),
active_tab = params["active_tab"];
active_tab = params["active_tab"],
page_id = params["id"];
if (active_tab == "users") {
$('#myTab a[href="#users"]').tab('show');
} else {
......@@ -115,112 +119,16 @@ $(function () {
}
});
initEditableFields();
/* Delete toolbar option */
$('[id^="delete_"]').on('click', deletePRAHandler);
/* Hide toolbar option */
$("[id^=hide_]").on('click', hideHandler);
/* Unhide toolbar option */
$("[id^=unhide_]").on('click', unhideHandler);
/* Checked or unchecked all checkboxes (master checkbox) */
$(":checkbox[id^=chk_all]").click( function() {
if ($(this).attr('checked')) {
$("input[type='checkbox'][id^=chk_"+$(this).attr("id").split("_")[2]+"]").attr('checked', true);
} else {
$("input[type='checkbox'][id^=chk_"+$(this).attr("id").split("_")[2]+"]").attr('checked', false);
}
});
/* Check main checkbox status */
$(':checkbox').click(function () {
if ($(':checkbox[id^=chk_'+ $(this).attr("id").split("_")[1] +']').size() == $(':checked[id^=chk_'+ $(this).attr("id").split("_")[1] +']').size()) {
$(":checkbox[id=chk_all_"+ $(this).attr("id").split("_")[1] +"]").attr('checked',true);
} else {
$(":checkbox[id=chk_all_"+ $(this).attr("id").split("_")[1] +"]").attr('checked',false);
}
});
/* Publish toolbar option */
$("[id=publish_project]").click(function() {
if ($(':checked[id^=chk_project_]').size() != 0) {
// First confirm with the user
$("#modal-label-tmpl").html("Publish");
$("#modal-body-tmpl").html("Are you sure you want to publish the selected project(s) ?<br/><br/> When done analysis and data related to the project(s) will be visible by all users.");
$("#modal-foot-tmpl").html('<button class="btn" data-dismiss="modal" aria-hidden="true">No</button>' +
'<button id="modal-btn-yes" class="btn btn-primary">Yes</button>');
$("#ng6modal").modal();
// Define yes button actions
$("#modal-btn-yes").click( function() {
// Built the url
var val_url = "index.php?eID=tx_nG6&type=publish";
val_url += "&user_id="+$("#user_id").val();
val_url += "&ids=";
$(':checked[id^=chk_project_]').each(function(i){
val_url += $(this).val().split("_",2)[1]+";";
});
$.ajax({
url: val_url,
success: function(val, status, xhr) {
$(':checked[id^=chk_project_]').each(function(i){
if ($(this).parent().parent().parent().children("td:nth-child(2)").children("span.label-warning").length == 0) {
$(this).parent().parent().parent().children("td:nth-child(2)").prepend(" <span class='label label-warning'>Public</span> ");
}
});
// Uncheck all checkboxes
$(':checked').each(function(i){
$(this).attr('checked',false);
});
$("#ng6modal").modal('hide');
}
});
});
} else {
$("#ng6modal-DTnoraw").modal();
}
});
/* Unpublish toolbar option */
$("[id=unpublish_project]").click(function() {
if ($(':checked[id^=chk_project_]').size() != 0) {
// First confirm with the user
$("#modal-label-tmpl").html("Unpublish");
$("#modal-body-tmpl").html("Are you sure you want to unpublish the selected project(s) ?<br/><br/>When done analysis and data related to the project(s) will be no longer visible by all users.");
$("#modal-foot-tmpl").html('<button class="btn" data-dismiss="modal" aria-hidden="true">No</button>' +
'<button id="modal-btn-yes" class="btn btn-primary">Yes</button>');
$("#ng6modal").modal();
// Define yes button actions
$("#modal-btn-yes").click( function() {
// Built the url
var val_url = "index.php?eID=tx_nG6&type=unpublish";
val_url += "&user_id="+$("#user_id").val();
val_url += "&ids=";
$(':checked[id^=chk_project_]').each(function(i){
val_url += $(this).val().split("_",2)[1]+";";
});
$.ajax({
url: val_url,
success: function(val, status, xhr) {
$(':checked[id^=chk_project_]').each(function(i){
$(this).parent().parent().parent().children("td:nth-child(2)").children("span.label-warning").remove();
});
// Uncheck all checkboxes
$(':checked').each(function(i){
$(this).attr('checked',false);
});
$("#ng6modal").modal('hide');
}
});
});
} else {
$("#ng6modal-DTnoraw").modal();
}
});
$("[id=unpublish_project]").on('click', unpublishHandler);
/* Publish toolbar option */
$("[id=publish_project]").on('click', publishHandler);
/* change user right on project option */
function change_right(select){
......@@ -251,50 +159,10 @@ $(function () {
$("table#users_data_table > tbody > tr > td > select").change(function(){
change_right(this);
});
/* add a brand new project option */
$(":button[id=add_project]").click(function(){
$.ajax({
url: 'http://localhost:8080/get_available_workflows?callback=?',
dataType: "json",
timeout: 2000,
error: function (xhr, ajaxOptions, thrownError) {
$('#setAndRunModalLabel').html("Error");
$('#setAndRunModalBody').html('<div class="tx-nG6-pi1-error">An error occured when trying to connect to the jflow server!</div>');
$("#reset_workflow").hide();
$("#run_workflow").hide();
$('#setAndRunModal').modal();
},
success: function(data) {
var workflow = {};
for (var i in data) {
if (data[i]["class"] == "AddProject") {
workflow = data[i];
}
}
$('#setAndRunModalLabel').html(workflow["name"] + " <small>" + workflow["help"] + "</small>");
$('#setAndRunModalBody').wfform({
workflowClass: workflow["class"],
displayRunButton: false,
displayResetButton: false,
parameters: {"admin_login": $("#user_login").val()}
});
$('#setAndRunModalBody').on('run', function(event, running_wf) {
location.assign(location.href);
});
$("#reset_workflow").show();
$("#run_workflow").show();
$('#setAndRunModal').modal();
}
});
$("#refresh_workflow").click(function(){ $('#statusModalBody').wfstatus('reload'); });
$("#reset_workflow").click(function(){ $('#setAndRunModalBody').wfform('reset'); });
$("#run_workflow").click(function(){ $('#setAndRunModalBody').wfform('run'); });
});
$(":button[id=add_project]").on('click', addProjectHandler);
/* add a brand new run option */
$(":button[id=add_run]").on('click', addRunHandler);
......@@ -640,8 +508,6 @@ $(function () {
});
/* Run table init */
function initRunTable() {
var runTable = null ;
......@@ -770,6 +636,26 @@ function initUsersTable() {
return usersTable;
}
function initCheckboxes() {
/* Checked or unchecked all checkboxes (master checkbox) */
$(":checkbox[id^=chk_all]").click( function() {
if ($(this).attr('checked')) {
$("input[type='checkbox'][id^=chk_"+$(this).attr("id").split("_")[2]+"]").attr('checked', true);
} else {
$("input[type='checkbox'][id^=chk_"+$(this).attr("id").split("_")[2]+"]").attr('checked', false);
}
});
/* Check main checkbox status */
$(':checkbox').click(function () {
if ($(':checkbox[id^=chk_'+ $(this).attr("id").split("_")[1] +']').size() == $(':checked[id^=chk_'+ $(this).attr("id").split("_")[1] +']').size()) {
$(":checkbox[id=chk_all_"+ $(this).attr("id").split("_")[1] +"]").attr('checked',true);
} else {
$(":checkbox[id=chk_all_"+ $(this).attr("id").split("_")[1] +"]").attr('checked',false);
}
});
}
function showEditableFromTD(e) {
e.stopPropagation();
$(this).children('span.editable').editable('show');
......@@ -902,6 +788,9 @@ function hideHandler() {
if ($(this).parent().parent().parent().children("td:nth-child(2)").children("span.label-info").length == 0) {
$(this).parent().parent().parent().children("td:nth-child(2)").prepend(" <span class='label label-info'>Hidden</span> ");
}
if ($(this).parent().parent().parent().children("td:nth-child(2)").children("span.label-warning").length > 0) {
$(this).parent().parent().parent().children("td:nth-child(2)").children("span.label-warning").remove();
}
});
// Uncheck all checkboxes
$(':checked').each(function(i){
......@@ -956,6 +845,87 @@ function unhideHandler() {
}
}
function unpublishHandler() {
if ($(':checked[id^=chk_project_]').size() != 0) {
// First confirm with the user
$("#modal-label-tmpl").html("Unpublish");
$("#modal-body-tmpl").html("Are you sure you want to unpublish the selected project(s) ?<br/><br/>When done analysis and data related to the project(s) will be no longer visible by all users.");
$("#modal-foot-tmpl").html('<button class="btn" data-dismiss="modal" aria-hidden="true">No</button>' +
'<button id="modal-btn-yes" class="btn btn-primary">Yes</button>');
$("#ng6modal").modal();
// Define yes button actions
$("#modal-btn-yes").click( function() {
// Built the url
var val_url = "index.php?eID=tx_nG6&type=unpublish";
val_url += "&user_id="+$("#user_id").val();
val_url += "&ids=";
$(':checked[id^=chk_project_]').each(function(i){
val_url += $(this).val().split("_",2)[1]+";";
});
$.ajax({
url: val_url,
success: function(val, status, xhr) {
$(':checked[id^=chk_project_]').each(function(i){
$(this).parent().parent().parent().children("td:nth-child(2)").children("span.label-warning").remove();
});
// Uncheck all checkboxes
$(':checked').each(function(i){
$(this).attr('checked',false);
});
$("#ng6modal").modal('hide');
}
});
});
} else {
$("#ng6modal-DTnoraw").modal();
}
}
function publishHandler () {
if ($(':checked[id^=chk_project_]').size() != 0) {
// First confirm with the user
$("#modal-label-tmpl").html("Publish");
$("#modal-body-tmpl").html("Are you sure you want to publish the selected project(s) ?<br/><br/> When done analysis and data related to the project(s) will be visible by all users.");
$("#modal-foot-tmpl").html('<button class="btn" data-dismiss="modal" aria-hidden="true">No</button>' +
'<button id="modal-btn-yes" class="btn btn-primary">Yes</button>');
$("#ng6modal").modal();
// Define yes button actions
$("#modal-btn-yes").click( function() {
// Built the url
var val_url = "index.php?eID=tx_nG6&type=publish";
val_url += "&user_id="+$("#user_id").val();
val_url += "&ids=";
$(':checked[id^=chk_project_]').each(function(i){
val_url += $(this).val().split("_",2)[1]+";";
});
$.ajax({
url: val_url,
success: function(val, status, xhr) {
$(':checked[id^=chk_project_]').each(function(i){
if ($(this).parent().parent().parent().children("td:nth-child(2)").children("span.label-warning").length == 0) {
$(this).parent().parent().parent().children("td:nth-child(2)").prepend(" <span class='label label-warning'>Public</span> ");
}
if ($(this).parent().parent().parent().children("td:nth-child(2)").children("span.label-info").length > 0) {
$(this).parent().parent().parent().children("td:nth-child(2)").children("span.label-info").remove();
}
});
// Uncheck all checkboxes
$(':checked').each(function(i){
$(this).attr('checked',false);
});
$("#ng6modal").modal('hide');
}
});
});
} else {
$("#ng6modal-DTnoraw").modal();
}
}
function addRunHandler() {
$('#setAndRunModalLabel').html("Add a run <small> from a workflow execution</small>");
var carousel = '<div id="myCarousel" class="carousel slide">';
......@@ -1017,7 +987,7 @@ function addRunHandler() {
forceUsingWorkflow: running_wf
});
$.ajax({
url: 'index.php?eID=tx_nG6&type=runs_table&project_id='+$("#current_project_id").val()+'&user_id='+$("#user_id").val()+'&login_user='+$("#login_user").val()+'&page_id='+$("#ids").val(),
url: 'index.php?eID=tx_nG6&type=runs_table&project_id='+$("#current_project_id").val()+'&user_id='+$("#user_id").val()+'&login_user='+$("#login_user").val()+'&page_id='+page_id,
dataType: "html",
error: function (xhr, ajaxOptions, thrownError) {
var html = '<div class="alert alert-error"><strong>Error!</strong> An error occured when attempting to reload the runs table.</div>';
......@@ -1026,12 +996,13 @@ function addRunHandler() {
success: function(data) {
if (data) {
$("#runs").html(data);
initEditableFields();
initCheckboxes();
var runTable = initRunTable();
$('#delete_run').on('click', deletePRAHandler);
$("#hide_run").on('click', hideHandler);
$("#unhide_run").on('click', unhideHandler);
$("#add_run").on('click', addRunHandler);
initEditableFields();
} else {
var html = '<div class="alert alert-error"><strong>Error!</strong> An error occured when attempting to reload the runs table.</div>';
$("#runs").html(html);
......@@ -1044,3 +1015,70 @@ function addRunHandler() {
$("#run_workflow").click(function(){ $('#selectedWfForm').wfform('run'); });
$("#refresh_workflow_status").click(function(){ $('#monitoringWorkflow').wfstatus('reload'); });
}
function addProjectHandler(){