parent
57faea4836
commit
78caeb5f1e
@ -0,0 +1,128 @@ |
||||
{% extends app.template_style ~ "/layout/layout_1_col.tpl" %} |
||||
{% block content %} |
||||
<script> |
||||
|
||||
function setSearchSelect(columnName) { |
||||
$("#questions").jqGrid('setColProp', columnName, { |
||||
|
||||
/*searchoptions:{ |
||||
dataInit:function(el){ |
||||
$("option[value='1']",el).attr("selected", "selected"); |
||||
setTimeout(function(){ |
||||
$(el).trigger('change'); |
||||
}, 1000); |
||||
} |
||||
}*/ |
||||
}); |
||||
} |
||||
|
||||
var added_cols = []; |
||||
var original_cols = []; |
||||
|
||||
function clean_cols(grid, added_cols) { |
||||
//Cleaning |
||||
for (key in added_cols) { |
||||
//console.log('hide: ' + key); |
||||
grid.hideCol(key); |
||||
}; |
||||
grid.showCol('name'); |
||||
grid.showCol('display_start_date'); |
||||
grid.showCol('display_end_date'); |
||||
grid.showCol('course_title'); |
||||
} |
||||
|
||||
function show_cols(grid, added_cols) { |
||||
grid.showCol('name').trigger('reloadGrid'); |
||||
for (key in added_cols) { |
||||
//console.log('show: ' + key); |
||||
grid.showCol(key); |
||||
}; |
||||
} |
||||
var second_filters = []; |
||||
|
||||
$(function () { |
||||
{{ js }} |
||||
|
||||
setSearchSelect("status"); |
||||
|
||||
var grid = $("#questions"), |
||||
prmSearch = { |
||||
multipleSearch : true, |
||||
overlay : false, |
||||
width: 'auto', |
||||
caption: '{{ 'Search' | get_lang }}', |
||||
formclass:'data_table', |
||||
onSearch : function() { |
||||
var postdata = grid.jqGrid('getGridParam', 'postData'); |
||||
|
||||
if (postdata && postdata.filters) { |
||||
filters = jQuery.parseJSON(postdata.filters); |
||||
clean_cols(grid, added_cols); |
||||
added_cols = []; |
||||
$.each(filters, function(key, value){ |
||||
//console.log('key: ' + key ); |
||||
|
||||
if (key == 'rules') { |
||||
$.each(value, function(subkey, subvalue) { |
||||
|
||||
if (subvalue.data == undefined) { |
||||
} |
||||
|
||||
//if (added_cols[value.field] == undefined) { |
||||
added_cols[subvalue.field] = subvalue.field; |
||||
//} |
||||
//grid.showCol(value.field); |
||||
}); |
||||
} |
||||
}); |
||||
show_cols(grid, added_cols); |
||||
} |
||||
}, |
||||
onReset: function() { |
||||
clean_cols(grid, added_cols); |
||||
} |
||||
}; |
||||
|
||||
original_cols = grid.jqGrid('getGridParam', 'colModel'); |
||||
|
||||
grid.jqGrid('navGrid','#questions_pager', |
||||
{edit:false,add:false,del:false}, |
||||
{height:280,reloadAfterSubmit:false}, // edit options |
||||
{height:280,reloadAfterSubmit:false}, // add options |
||||
{reloadAfterSubmit:false},// del options |
||||
prmSearch |
||||
); |
||||
|
||||
// create the searching dialog |
||||
grid.searchGrid(prmSearch); |
||||
|
||||
// Fixes search table. |
||||
var searchDialogAll = $("#fbox_"+grid[0].id); |
||||
searchDialogAll.addClass("table"); |
||||
var searchDialog = $("#searchmodfbox_"+grid[0].id); |
||||
searchDialog.addClass("ui-jqgrid ui-widget ui-widget-content ui-corner-all"); |
||||
searchDialog.css({position:"relative", "z-index":"auto", "float":"left"}) |
||||
var gbox = $("#gbox_"+grid[0].id); |
||||
gbox.before(searchDialog); |
||||
gbox.css({clear:"left"}); |
||||
|
||||
//Select first elements by default |
||||
$('.input-elm').each(function(){ |
||||
$(this).find('option:first').attr('selected', 'selected'); |
||||
}); |
||||
|
||||
$('.delete-rule').each(function(){ |
||||
$(this).click(function(){ |
||||
$('.input-elm').each(function(){ |
||||
$(this).find('option:first').attr('selected', 'selected'); |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
||||
</script> |
||||
|
||||
<div class="questions"> |
||||
{{ grid }} |
||||
</div> |
||||
|
||||
{% endblock %} |
||||
@ -0,0 +1,87 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace ChamiloLMS\Controller; |
||||
|
||||
use Silex\Application; |
||||
use Symfony\Component\HttpFoundation\Response; |
||||
use Symfony\Component\HttpFoundation\Request; |
||||
use Symfony\Component\HttpKernel\HttpKernelInterface; |
||||
|
||||
/** |
||||
* @package ChamiloLMS.Controller |
||||
* @author Julio Montoya <gugli100@gmail.com> |
||||
*/ |
||||
class ExerciseController |
||||
{ |
||||
/** |
||||
* @param Application $app |
||||
* @return Response |
||||
*/ |
||||
public function questionPoolAction(Application $app) |
||||
{ |
||||
|
||||
$extraJS = array(); |
||||
//@todo improve this JS includes should be added using twig |
||||
$extraJS[] = api_get_jqgrid_js(); |
||||
$app['extraJS'] = $extraJS; |
||||
//$questions = $category->getQuestions(); |
||||
|
||||
/*$questionFields = $em->getRepository('Entity\QuestionField')->findAll(); |
||||
$rules = array(); |
||||
foreach ($questionFields as $extraField) { |
||||
$extraField->getFieldVariable(); |
||||
$rules[] = ; |
||||
}*/ |
||||
|
||||
$questionColumns = \Question::getQuestionColumns(); |
||||
$columnModel = $questionColumns['column_model']; |
||||
$columns = $questionColumns['columns']; |
||||
$rules = $questionColumns['rules']; |
||||
|
||||
$grid = \Display::grid_html('questions'); |
||||
|
||||
//jqgrid will use this URL to do the selects |
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_questions'; |
||||
|
||||
$extraParams['postData'] = array( |
||||
'filters' => array( |
||||
"groupOp" => "AND", |
||||
"rules" => $rules |
||||
) |
||||
); |
||||
|
||||
// Autowidth. |
||||
$extraParams['autowidth'] = 'true'; |
||||
// Height auto. |
||||
$extraParams['height'] = 'auto'; |
||||
$token = null; |
||||
$editUrl = $app['url_generator']->generate('admin_questions'); |
||||
|
||||
$actionLinks = 'function action_formatter(cellvalue, options, rowObject) { |
||||
return \'<a href="'.$editUrl.'/\'+rowObject[0]+\'/edit">'.\Display::return_icon( |
||||
'edit.png', |
||||
get_lang('Edit'), |
||||
'', |
||||
ICON_SIZE_SMALL |
||||
).'</a>'.'\'; |
||||
}'; |
||||
|
||||
$js = \Display::grid_js( |
||||
'questions', |
||||
$url, |
||||
$columns, |
||||
$columnModel, |
||||
$extraParams, |
||||
array(), |
||||
$actionLinks, |
||||
true |
||||
); |
||||
$app['template']->assign('grid', $grid); |
||||
$app['template']->assign('js', $js); |
||||
|
||||
$response = $app['template']->render_template('exercise/question_pool.tpl'); |
||||
|
||||
return new Response($response, 200, array()); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue