Gitlab CSE Unil

Commit f45584a8 authored by M. Chardon's avatar M. Chardon
Browse files

gestion des axes adjout/modif/suppression

parent 880053c8
define(["jquery","core/notification","core/templates","core/fragment"],function(a,b,c,d){var e=null,f=function(a){this.init(),e=a};return f.prototype.selectTool=null,f.prototype.init=function(){var b=a("#editpdlplus_axes").val();a("#editpdlplus_toolbar_"+b).show(),a("#editpdlplus_axes").on("change",function(){a(".toolbar").hide();var b=a("#editpdlplus_axes").val();a("#editpdlplus_toolbar_"+b).show()}),a(".editpdlplus_tool").on("click",function(){var b=a(this).val();a(".editpdlplus_tool").each(function(){a(this).removeClass("btn-primary"),a(this).removeClass("btn-default");var c=a(this).data("enable");1===c&&a(this).val()!==b&&a(this).addClass("btn-default")}),a(this).addClass("btn-primary")}),this.selectTool=a(".editpdlplus_tool").first(),this.initTool(),a("#assignfeedback_editpdfplus_widget_admin_button_addaxis").on("click",this.openDivAddAxis),a("#assignfeedback_editpdfplus_widget_admin_button_editaxis").on("click",this.openDivEditAxis)},f.prototype.initTool=function(){a(this.selectTool).removeClass("btn-default"),a(this.selectTool).addClass("btn-primary")},f.prototype.openDivAddAxis=function(){a("#axistool").hide(),a("#assignfeedback_editpdfplus_widget_admin_div_addaxis").show(),a("#assignfeedback_editpdfplus_widget_admin_div_addaxis > .panel-body").html("");var f={};d.loadFragment("assignfeedback_editpdfplus","axisadd",e,f).done(function(a,b){c.appendNodeContents("#assignfeedback_editpdfplus_widget_admin_div_addaxis > .panel-body",a,b)}.bind(this)).fail(b.exception)},f.prototype.openDivEditAxis=function(){a("#axistool").hide(),a("#assignfeedback_editpdfplus_widget_admin_div_editaxis").show(),a("#assignfeedback_editpdfplus_widget_admin_div_editaxis > .panel-body").html("");var f=a("#editpdlplus_axes option:selected").val(),g={axeid:f};d.loadFragment("assignfeedback_editpdfplus","axisedit",e,g).done(function(a,b){c.appendNodeContents("#assignfeedback_editpdfplus_widget_admin_div_editaxis > .panel-body",a,b)}.bind(this)).fail(b.exception)},f});
\ No newline at end of file
define(["jquery","core/notification","core/templates","core/fragment"],function(a,b,c,d){var e=null,f=function(a){this.init(),e=a};return f.prototype.selectTool=null,f.prototype.init=function(){a("#editpdlplus_axes").on("change",function(){a(".toolbar").hide();var b=a("#editpdlplus_axes").val();a("#editpdlplus_toolbar_"+b).show();var c=a("#editpdlplus_axes option:selected").data("delete");c&&parseInt(c)>0?a("#assignfeedback_editpdfplus_widget_admin_button_delaxis").addClass("disabled"):a("#assignfeedback_editpdfplus_widget_admin_button_delaxis").removeClass("disabled")}),a("#editpdlplus_axes").change(),a(".editpdlplus_tool").on("click",function(){var b=a(this).val();a(".editpdlplus_tool").each(function(){a(this).removeClass("btn-primary"),a(this).removeClass("btn-default");var c=a(this).data("enable");1===c&&a(this).val()!==b&&a(this).addClass("btn-default")}),a(this).addClass("btn-primary")}),this.selectTool=a(".editpdlplus_tool").first(),this.initTool(),a("#assignfeedback_editpdfplus_widget_admin_button_addaxis").on("click",this.openDivAddAxis),a("#assignfeedback_editpdfplus_widget_admin_button_editaxis").on("click",this.openDivEditAxis),a("#assignfeedback_editpdfplus_widget_admin_button_delaxis").on("click",this.openDivDelAxis)},f.prototype.initTool=function(){a(this.selectTool).removeClass("btn-default"),a(this.selectTool).addClass("btn-primary")},f.prototype.openDivAddAxis=function(){a("#axistool").hide(),a("#assignfeedback_editpdfplus_widget_admin_div_addaxis").show(),a("#assignfeedback_editpdfplus_widget_admin_div_addaxis > .panel-body").html("");var f={};d.loadFragment("assignfeedback_editpdfplus","axisadd",e,f).done(function(a,b){c.appendNodeContents("#assignfeedback_editpdfplus_widget_admin_div_addaxis > .panel-body",a,b)}.bind(this)).fail(b.exception)},f.prototype.openDivEditAxis=function(){a("#axistool").hide(),a("#assignfeedback_editpdfplus_widget_admin_div_editaxis").show(),a("#assignfeedback_editpdfplus_widget_admin_div_editaxis > .panel-body").html("");var f=a("#editpdlplus_axes option:selected").val(),g={axeid:f};d.loadFragment("assignfeedback_editpdfplus","axisedit",e,g).done(function(a,b){c.appendNodeContents("#assignfeedback_editpdfplus_widget_admin_div_editaxis > .panel-body",a,b)}.bind(this)).fail(b.exception)},f.prototype.openDivDelAxis=function(){a("#axistool").hide(),a("#assignfeedback_editpdfplus_widget_admin_div_delaxis").show(),a("#assignfeedback_editpdfplus_widget_admin_div_delaxis > .panel-body").html("");var f=a("#editpdlplus_axes option:selected").val(),g={axeid:f};d.loadFragment("assignfeedback_editpdfplus","axisdel",e,g).done(function(a,b){c.appendNodeContents("#assignfeedback_editpdfplus_widget_admin_div_delaxis > .panel-body",a,b)}.bind(this)).fail(b.exception)},f});
\ No newline at end of file
......@@ -42,14 +42,18 @@ define(['jquery'/*, 'core/yui'*/, 'core/notification', 'core/templates', 'core/f
AdminPanel.prototype.selectTool = null;
//
AdminPanel.prototype.init = function () {
var selectAxis = $("#editpdlplus_axes").val();
$("#editpdlplus_toolbar_" + selectAxis).show();
$("#editpdlplus_axes").on("change", function () {
$(".toolbar").hide();
var selectAxis = $("#editpdlplus_axes").val();
$("#editpdlplus_toolbar_" + selectAxis).show();
var canBeDelete = $("#editpdlplus_axes option:selected").data('delete');
if (canBeDelete && parseInt(canBeDelete) > 0) {
$("#assignfeedback_editpdfplus_widget_admin_button_delaxis").addClass("disabled");
} else {
$("#assignfeedback_editpdfplus_widget_admin_button_delaxis").removeClass("disabled");
}
});
$("#editpdlplus_axes").change();
//
$(".editpdlplus_tool").on("click", function () {
var selectid = $(this).val();
......@@ -67,6 +71,7 @@ define(['jquery'/*, 'core/yui'*/, 'core/notification', 'core/templates', 'core/f
this.initTool();
$("#assignfeedback_editpdfplus_widget_admin_button_addaxis").on("click", this.openDivAddAxis);
$("#assignfeedback_editpdfplus_widget_admin_button_editaxis").on("click", this.openDivEditAxis);
$("#assignfeedback_editpdfplus_widget_admin_button_delaxis").on("click", this.openDivDelAxis);
};
//
AdminPanel.prototype.initTool = function () {
......@@ -107,6 +112,19 @@ define(['jquery'/*, 'core/yui'*/, 'core/notification', 'core/templates', 'core/f
html, js);
}.bind(this)).fail(notification.exception);
};
//
AdminPanel.prototype.openDivDelAxis = function () {
$("#axistool").hide();
$('#assignfeedback_editpdfplus_widget_admin_div_delaxis').show();
$('#assignfeedback_editpdfplus_widget_admin_div_delaxis > .panel-body').html("");
var axeid = $("#editpdlplus_axes option:selected").val();
var params = {axeid: axeid};
fragment.loadFragment('assignfeedback_editpdfplus', 'axisdel', contextid, params)
.done(function (html, js) {
templates.appendNodeContents('#assignfeedback_editpdfplus_widget_admin_div_delaxis > .panel-body',
html, js);
}.bind(this)).fail(notification.exception);
};
return AdminPanel;
});
\ No newline at end of file
......@@ -77,4 +77,15 @@ class admin_editor {
return $DB->update_record('assignfeedback_editpp_axis', $axis);
}
/**
*
* @global type $DB
* @param type $axisid
* @return type
*/
public static function del_axis($axeid) {
global $DB;
return $DB->delete_records('assignfeedback_editpp_axis', array('id' => $axeid));
}
}
<?php
/**
*
*
* @package assignfeedback_editpdfplus
* @copyright 2017 Université de Lausanne
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignfeedback_editpdfplus\form;
require_once("$CFG->libdir/formslib.php");
use moodleform;
/**
* Description of formslib
*
* @author kury
*/
class axis_del_form extends moodleform {
protected function definition() {
$mform = $this->_form;
$mform->addElement('hidden', 'label', ''); // Add elements to your form
$mform->setType('hidden', PARAM_TEXT); //Set type of element
$mform->addElement('hidden', 'axeid', ''); // Add elements to your form
$mform->setType('hidden', PARAM_INT); //Set type of element
/*$buttonarray[] = &$mform->createElement('submit', 'submitbutton', 'Enregistrer');
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$mform->closeHeaderBefore('buttonar');*/
//$this->add_action_buttons();
}
//Custom validation should be added here
function validation($data, $files) {
return array();
}
}
......@@ -387,5 +387,9 @@ class assignfeedback_editpdfplus_renderer extends plugin_renderer_base {
public function render_assignfeedback_editpdfplus_widget_admin_axisform(moodleform $form){
return $this->render_from_template('assignfeedback_editpdfplus/axis_form', $form);
}
public function render_assignfeedback_editpdfplus_widget_admin_axisdelform(moodleform $form){
return $this->render_from_template('assignfeedback_editpdfplus/axis_del_form', $form);
}
}
......@@ -44,5 +44,16 @@ $functions = array(
'requiredcapability' => 'mod/assignfeedback_editpdfplus:use',
'enabled'=>1,
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
),
'assignfeedback_editpdfplus_submit_axis_del_form' => array(
'classname' => 'assignfeedback_editpdfplus_external',
'methodname' => 'submit_axis_del_form',
'classpath' => 'mod/assign/feedback/editpdfplus/externallib.php',
'description' => 'Remove an axis',
'type' => 'write',
'ajax' => true,
'requiredcapability' => 'mod/assignfeedback_editpdfplus:use',
'enabled'=>1,
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
)
);
......@@ -31,6 +31,7 @@ require_once("locallib.php");
require_once("locallib_admin.php");
use \assignfeedback_editpdfplus\form\axis_form;
use \assignfeedback_editpdfplus\form\axis_del_form;
use \assignfeedback_editpdfplus\admin_editor;
class assignfeedback_editpdfplus_external extends external_api {
......@@ -81,19 +82,10 @@ class assignfeedback_editpdfplus_external extends external_api {
if ($validateddata) {
if ($validateddata->axeid) {
admin_editor::edit_axis($validateddata->axeid, $validateddata->label);
/* $axisTot = admin_editor::get_axis($context->id);
$res = array();
$res[]=array('axeid' => $validateddata->axeid, 'axelabel' => $validateddata->label);
foreach ($axisTot as $axetmp) {
$res[]=array('axeid' => $axetmp->id, 'axelabel' => $axetmp->label);
}
return $res; */
$axeid = $validateddata->axeid;
return array(array('axeid' => $axeid, 'axelabel' => $validateddata->label));
} else {
$axeid = admin_editor::add_axis($validateddata->label, $context->id);
//return array(array('itemid' => $axeid),array('item' => $validateddata->label));
//return array('axe' => array('axeid' => $axeid, 'axelabel' => $validateddata->label));
return array(array('axeid' => $axeid, 'axelabel' => $validateddata->label));
}
} else {
......@@ -120,4 +112,72 @@ class assignfeedback_editpdfplus_external extends external_api {
);
}
/**
* Returns description of method parameters
* @return external_function_parameters
*/
public static function submit_axis_del_form_parameters() {
return new external_function_parameters(
array(
'jsonformdata' => new external_value(PARAM_RAW, 'The data from the grading form, encoded as a json array')
)
);
}
public static function submit_axis_del_form($jsonformdata) {
global $USER, $PAGE, $DB;
$params = self::validate_parameters(self::submit_axis_form_parameters(), array(
'jsonformdata' => $jsonformdata
));
$serialiseddata = json_decode($params['jsonformdata']);
$data = array();
parse_str($serialiseddata, $data);
$warnings = array();
if (WS_SERVER) {
// Assume form submission if coming from WS.
$USER->ignoresesskey = true;
}
$course = $DB->get_record('course', array('id' => $data['courseid']), '*', MUST_EXIST);
$context = context_course::instance($course->id, MUST_EXIST);
$PAGE->set_context($context);
$customdata = (object) $data;
$formparams = array($customdata);
// Data is injected into the form by the last param for the constructor.
$mform = new axis_del_form(null, $formparams, 'post', '', null, true, $data);
$validateddata = $mform->get_data();
if ($validateddata) {
if ($validateddata->axeid && admin_editor::del_axis($validateddata->axeid)) {
$message = "1";
return array(array('message' => $message));
}
} else {
$message = "erreur à la suppression";
$warnings[] = array('message' => $message);
}
return $warnings;
}
/* public static function submit_axis_form_returns() {
return new external_warnings();
} */
public static function submit_axis_del_form_returns() {
return new external_multiple_structure(
new external_single_structure(
array(
'message' => new external_value(PARAM_TEXT, 'message', VALUE_OPTIONAL)
)
)
);
}
}
......@@ -129,3 +129,23 @@ function assignfeedback_editpdfplus_output_fragment_axisedit($args) {
return null;
}
function assignfeedback_editpdfplus_output_fragment_axisdel($args) {
global $DB;
$context = $args['context'];
$axisid = $args['axeid'];
if ($context->contextlevel != CONTEXT_COURSE) {
return null;
}
require_once('locallib_admin.php');
if (has_capability('mod/assignfeedback_editpdfplus:use', $context, null, false)) {
$course=$DB->get_record('course', array('id' => $context->instanceid), '*', MUST_EXIST);
$editpdfplus = new assign_feedback_editpdfplus_admin($context, $course);
return $editpdfplus->getAxisDelForm($axisid);
}
return null;
}
......@@ -27,6 +27,7 @@ defined('MOODLE_INTERNAL') || die();
use \assignfeedback_editpdfplus\page_editor;
use \assignfeedback_editpdfplus\widget_admin;
use \assignfeedback_editpdfplus\form\axis_form;
use \assignfeedback_editpdfplus\form\axis_del_form;
use \assignfeedback_editpdfplus\admin_editor;
class assign_feedback_editpdfplus_admin {
......@@ -52,21 +53,21 @@ class assign_feedback_editpdfplus_admin {
$html = '';
//$toform = null;
$renderer = $PAGE->get_renderer('assignfeedback_editpdfplus');
/*$formAddAxis = new axis_form(new moodle_url('/mod/assign/feedback/editpdfplus/view_admin.php?id=' . $this->course->id, array('id' => $this->course->id))); //Form processing and displaying is done here
if ($formAddAxis->is_cancelled()) {
//Handle form cancel operation, if cancel button is present on form
} else if ($fromform = $formAddAxis->get_data()) {
//In this case you process validated data. $mform->get_data() returns data posted in form.
$label = $fromform->label;
$axe = $this->addAxis($label);
$formAddAxis->set_data($toform);
return $axe; //"<option>tutu</option>";
} else {
// this branch is executed if the form is submitted but the data doesn't validate and the form should be redisplayed
// or on the first display of the form.
//Set default data (if any)
$formAddAxis->set_data($toform);
}*/
/* $formAddAxis = new axis_form(new moodle_url('/mod/assign/feedback/editpdfplus/view_admin.php?id=' . $this->course->id, array('id' => $this->course->id))); //Form processing and displaying is done here
if ($formAddAxis->is_cancelled()) {
//Handle form cancel operation, if cancel button is present on form
} else if ($fromform = $formAddAxis->get_data()) {
//In this case you process validated data. $mform->get_data() returns data posted in form.
$label = $fromform->label;
$axe = $this->addAxis($label);
$formAddAxis->set_data($toform);
return $axe; //"<option>tutu</option>";
} else {
// this branch is executed if the form is submitted but the data doesn't validate and the form should be redisplayed
// or on the first display of the form.
//Set default data (if any)
$formAddAxis->set_data($toform);
} */
$widget = $this->get_widget();
//$widget->axisaddform = $formAddAxis;
$html .= $renderer->render_assignfeedback_editpdfplus_widget_admin($widget);
......@@ -85,16 +86,16 @@ class assign_feedback_editpdfplus_admin {
}
if ($axis != null) {
$formAxis = new axis_form(null, array('id' => $this->course->id), null, null, array('id' => "assignfeedback_editpdfplus_edit_axis")); //Form processing and displaying is done here
$formAxis->set_data(array('axeid' => $axeid,'label' => $axis->label));
$formAxis->set_data(array('axeid' => $axeid, 'label' => $axis->label));
$formAxis->id = "assignfeedback_editpdfplus_edit_axis";
$formAxis->title="Renommer l'axe";
$formAxis->action="edit";
$formAxis->title = "Renommer l'axe";
$formAxis->action = "edit";
} else {
$formAxis = new axis_form(null, array('id' => $this->course->id), null, null, array('id' => "assignfeedback_editpdfplus_add_axis")); //Form processing and displaying is done here
$formAxis->set_data($toform);
$formAxis->id = "assignfeedback_editpdfplus_add_axis";
$formAxis->title="Ajouter un nouvel axe";
$formAxis->action="add";
$formAxis->title = "Ajouter un nouvel axe";
$formAxis->action = "add";
}
$renderer = $PAGE->get_renderer('assignfeedback_editpdfplus');
$formAxis->courseid = $this->course->id;
......@@ -102,6 +103,28 @@ class assign_feedback_editpdfplus_admin {
return $html;
}
public function getAxisDelForm($axeid) {
global $PAGE, $DB;
$html = '';
$formAxis = null;
$axis = null;
if ($axeid != null) {
$axis = $DB->get_record('assignfeedback_editpp_axis', array('id' => $axeid), '*', MUST_EXIST);
}
if ($axis != null) {
$formAxis = new axis_del_form(null, array('id' => $this->course->id), null, null, array('id' => "assignfeedback_editpdfplus_del_axis")); //Form processing and displaying is done here
$formAxis->set_data(array('axeid' => $axeid, 'label' => $axis->label));
}
$formAxis->id = "assignfeedback_editpdfplus_del_axis";
$formAxis->title = "Supprimer l'axe";
$formAxis->action = "del";
$renderer = $PAGE->get_renderer('assignfeedback_editpdfplus');
$formAxis->courseid = $this->course->id;
$html .= $renderer->render_assignfeedback_editpdfplus_widget_admin_axisdelform($formAxis);
return $html;
}
private function get_widget() {
global $USER;
......@@ -112,6 +135,7 @@ class assign_feedback_editpdfplus_admin {
$tools = page_editor::get_tools($coursecontexts);
$axis = page_editor::get_axis(array($this->context->id));
foreach ($axis as $ax) {
$ax->children = 0;
$toolbar = new stdClass();
$toolbar->axis = $ax;
$toolbar->tools = array();
......@@ -132,6 +156,7 @@ class assign_feedback_editpdfplus_admin {
$tool->style = "text-decoration: underline;";
}
$toolbar->tools[] = $tool;
$ax->children++;
}
}
$toolbars[] = $toolbar;
......
......@@ -27,7 +27,7 @@
<div class='col-sm-2'>
<select id='editpdlplus_axes' class='form-control'>
{{# axis }}
<option value="{{id}}">{{label}}</option>
<option value="{{id}}" data-delete="{{children}}">{{label}}</option>
{{/ axis }}
</select>
<div class="panel panel-default" id="axistool">
......@@ -35,7 +35,9 @@
<button type="button" class="btn btn-default" id="assignfeedback_editpdfplus_widget_admin_button_editaxis">
<i class="fa fa-pencil" aria-hidden="true"></i>
</button>
<button type="button" class="btn btn-default"><i class="fa fa-remove" aria-hidden="true"></i></button>
<button type="button" class="btn btn-default" id="assignfeedback_editpdfplus_widget_admin_button_delaxis">
<i class="fa fa-remove" aria-hidden="true"></i>
</button>
</div>
</div>
<div id="assignfeedback_editpdfplus_widget_admin_div_addaxis">
......@@ -44,6 +46,9 @@
<div id="assignfeedback_editpdfplus_widget_admin_div_editaxis">
<div class="panel-body"></div>
</div>
<div id="assignfeedback_editpdfplus_widget_admin_div_delaxis">
<div class="panel-body"></div>
</div>
</div>
<div class='col-sm-10'>
{{# toolbars }}
......
{{!
@template assignfeedback_editpdfplus/axis_form
}}
<div class="panel panel-default">
<div class="panel-heading">
{{title}}
</div>
<div class="panel-body" style="text-align: center;">
<p>Êtes-vous sûr de supprimer l'axe sélectionné ?</p>
{{{render}}}
<button type="button" class="btn btn-primary" id="axisDelSubmit">Oui</button>
<button type="button" class="btn btn-default" id="axisDelCancel">Non</button>
</div>
</div>
{{# js }}
require(['jquery','core/ajax','core/notification'], function($,ajax,notification) {
var formid='{{id}}';
$("#axisDelSubmit").on("click", function () {
var form = $('#'+formid);
var data = form.serialize()+"&courseid="+{{courseid}};
ajax.call([
{
methodname: 'assignfeedback_editpdfplus_submit_axis_del_form',
args: {jsonformdata: JSON.stringify(data)}
}
])[0].done(function(message) {
if (message[0].message === "1"){
$('#assignfeedback_editpdfplus_widget_admin_div_delaxis > .panel-body').html("");
$("#editpdlplus_axes option:selected").remove();
$("#editpdlplus_axes").change();
$("#axistool").show();
}else{
$('#assignfeedback_editpdfplus_widget_admin_div_delaxis > .panel-body > .panel > .panel-body').append("<div class='alert alert-danger' style='margin-top: 5px;'>"+message[0].message+"</div>");
}
}).fail(notification.exception);
});
$("#axisDelCancel").on("click", function () {
$('#assignfeedback_editpdfplus_widget_admin_div_delaxis > .panel-body').html("");
$("#axistool").show();
});
});
{{/ js }}
\ No newline at end of file
......@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017062000;
$plugin->version = 2017062100;
$plugin->requires = 2017050500; // Requires this Moodle version.
$plugin->dependencies = array(
'assignfeedback_editpdf' => 2017050500
......
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