Gitlab CSE Unil

Commit 71c2cc3b authored by M. Chardon's avatar M. Chardon
Browse files

import des axes

parent 0945bd1e
This diff is collapsed.
......@@ -88,6 +88,8 @@ define(['jquery'/*, 'core/yui'*/, 'core/notification', 'core/templates', 'core/f
$(".btn-primary").click();
$(".btnimport").on('click', this.importAxis);
initMessages();
};
//init message
......@@ -340,6 +342,79 @@ define(['jquery'/*, 'core/yui'*/, 'core/notification', 'core/templates', 'core/f
//return true;
};
//
AdminPanel.prototype.importAxis = function () {
var axisimportid = $(this).data('axis');
if (axisimportid && parseInt(axisimportid) > 0) {
$("#assignfeedback_editpdfplus_import_axis > div > input[name^='axeid']").val(axisimportid);
var form = $('#assignfeedback_editpdfplus_import_axis');
var data = form.serialize() + "&courseid=" + $("#courseid").val();
ajax.call([
{
methodname: 'assignfeedback_editpdfplus_submit_axis_import_form',
args: {jsonformdata: JSON.stringify(data)}
}
])[0].done(function (toolbar) {
if (toolbar[0].message === "") {
//mise à jour du message
$("#message_import_axis").show();
$("#message_import_axis").html(AdminPanel.messageaddok);
$("#message_import_axis").addClass("alert-success");
$("#message_import_axis").removeClass("alert-danger");
$("#message_import_axis").removeClass("alert-warning");
//maj axe
var divAxis = "<div id='editpdlplus_toolbar_"
+ toolbar[0].axeid
+ "' class='btn-group toolbar' style='display: none;'></div>";
$('#editpdlplus_toolbars').append(divAxis);
var option = new Option(toolbar[0].axelabel, toolbar[0].axeid, true, true);
$("#editpdlplus_axes").append(option);
$('#editpdlplus_tool_item').html("");
//maj toolbar
for (var i = 0; i < toolbar.length; i++) {
if (toolbar[i].toolid && toolbar[i].toolid > 0) {
var classButton = "btn-default";
if (toolbar[i].enable !== 1) {
classButton = "";
}
var style = "";
if (toolbar[i].typetool === 4 || toolbar[i].typetool === 1) {
style = "text-decoration: underline;";
}
var label = toolbar[i].button;
if (toolbar[i].typetool === 4 || toolbar[i].typetool === 5) {
label = "| " + label;
if (toolbar[i].typetool === 4) {
label += " |";
}
}
var buttonTmp = "<button class='btn "
+ classButton
+ " editpdlplus_tool' id='editpdlplus_tool_"
+ toolbar[i].toolid + "' style='"
+ style
+ "' value='"
+ toolbar[i].toolid
+ "' data-enable='"
+ toolbar[i].enable + "'>"
+ label
+ "</button>";
$("#editpdlplus_toolbar_" + toolbar[0].axeid).append(buttonTmp);
}
}
$(".editpdlplus_tool").on("click", refreshToolView);
//maj visu
$("#editpdlplus_axes").change();
$("a[href^='#collapseadmin2'").click();
} else {
$("#message_import_axis").show();
$("#message_import_axis").html(toolbar[0].message);
$("#message_import_axis").addClass("alert-danger");
$("#message_import_axis").removeClass("alert-success");
}
}).fail(notification.exception);
}
};
//
var refreshToolView = function () {
var selectid = $(this).val();
$(".editpdlplus_tool").each(function () {
......
......@@ -281,4 +281,49 @@ class admin_editor {
return $typetools;
}
public static function getAxisById($axeid) {
global $DB;
$axis = $DB->get_record('assignfeedback_editpp_axis', array('id' => $axeid), '*', MUST_EXIST);
return $axis;
}
public static function import_axis($axisOrigin, $context) {
global $DB;
$record = $DB->get_record_sql('SELECT max(order_axis) as order_max FROM {assignfeedback_editpp_axis} WHERE contextid = :contextid', array('contextid' => $context));
$axis = new axis();
$axis->contextid = $context;
$axis->label = $axisOrigin->label;
if ($record->order_max == null) {
$axis->order_axis = 1;
} else {
$axis->order_axis = $record->order_max + 1;
}
return $DB->insert_record('assignfeedback_editpp_axis', $axis);
}
public static function import_tool($toolToImport, $axeNew, $context) {
global $DB;
$record = $DB->get_record_sql('SELECT max(order_tool) as order_max FROM {assignfeedback_editpp_tool} WHERE contextid = :contextid', array('axis' => $axeNew->id, 'contextid' => $context));
$tool = new tool();
$tool->axis = $axeNew;
$tool->cartridge = $toolToImport->cartridge;
$tool->cartridge_color = $toolToImport->cartridge_color;
$tool->colors = $toolToImport->colors;
$tool->contextid = $context;
$tool->enabled = $toolToImport->enabled;
$tool->label = $toolToImport->label;
$tool->reply = $toolToImport->reply;
$tool->texts = $toolToImport->texts;
$tool->type = $toolToImport->type;
if ($record->order_max == null) {
$tool->order_tool = 1;
} else {
$tool->order_tool = $record->order_max + 1;
}
return $DB->insert_record('assignfeedback_editpp_tool', $tool);
}
}
<?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_import_form extends moodleform {
protected function definition() {
global $CFG;
$mform = $this->_form;
$mform->addElement('hidden', 'axeid', '');
$mform->setType('axeid', PARAM_INTEGER);
}
//Custom validation should be added here
function validation($data, $files) {
return array();
}
}
......@@ -89,4 +89,15 @@ $functions = array(
'enabled' => 1,
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
),
'assignfeedback_editpdfplus_submit_axis_import_form' => array(
'classname' => 'assignfeedback_editpdfplus_external',
'methodname' => 'submit_axis_import_form',
'classpath' => 'mod/assign/feedback/editpdfplus/externallib.php',
'description' => 'Import an axis with its tools',
'type' => 'write',
'ajax' => true,
'requiredcapability' => 'assignfeedback/editpdfplus:managetools',
'enabled' => 1,
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
)
);
......@@ -32,6 +32,7 @@ require_once("locallib_admin.php");
use \assignfeedback_editpdfplus\form\axis_form;
use \assignfeedback_editpdfplus\form\axis_del_form;
use \assignfeedback_editpdfplus\form\axis_import_form;
use \assignfeedback_editpdfplus\admin_editor;
class assignfeedback_editpdfplus_external extends external_api {
......@@ -431,4 +432,95 @@ class assignfeedback_editpdfplus_external extends external_api {
);
}
/**
* Returns description of method parameters
* @return external_function_parameters
*/
public static function submit_axis_import_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_import_form($jsonformdata) {
global $USER, $PAGE, $DB;
$params = self::validate_parameters(self::submit_axis_import_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;
//$data['_qf__mod_assign_grade_form_' . $params['userid']] = 1;
}
$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_import_form(null, $formparams, 'post', '', null, true, $data);
$validateddata = $mform->get_data();
if ($validateddata && $validateddata->axeid) {
$axeToImport = admin_editor::getAxisById($validateddata->axeid);
$axeNew = admin_editor::import_axis($axeToImport, $context->id);
if ($axeNew) {
$tools = admin_editor::get_tools_by_axis($axeToImport->id);
//$toolsNew = array();
foreach ($tools as $toolToImport) {
admin_editor::import_tool($toolToImport, $axeNew, $context->id);
}
//$res = array('axeid' => $axeNew, 'axelabel' => $axeToImport->label);
$res = array();
$toolsNew = admin_editor::get_tools_by_axis($axeNew);
if (sizeof($toolsNew) > 0) {
foreach ($toolsNew as $tool) {
$res[] = array('axeid' => $axeNew, 'axelabel' => $axeToImport->label, 'message' => "", 'enable' => $tool->enabled, 'toolid' => $tool->id, 'typetool' => $tool->type, 'button' => $tool->label, 'message' => '');
}
} else {
$res = array(array('axeid' => $axeNew, 'axelabel' => $axeToImport->label, 'message' => ""));
}
return $res;
}
}
$warnings[] = array('message' => get_string('admin_messageko', 'assignfeedback_editpdfplus'));
return $warnings;
}
/* public static function submit_axis_form_returns() {
return new external_warnings();
} */
public static function submit_axis_import_form_returns() {
return new external_multiple_structure(
new external_single_structure(
array(
'axeid' => new external_value(PARAM_INT, 'axis id', VALUE_OPTIONAL),
'axelabel' => new external_value(PARAM_TEXT, 'axis label', VALUE_OPTIONAL),
'message' => new external_value(PARAM_TEXT, 'message'),
'enable' => new external_value(PARAM_INT, 'tool enable', VALUE_OPTIONAL),
'toolid' => new external_value(PARAM_INT, 'tool id', VALUE_OPTIONAL),
'typetool' => new external_value(PARAM_INT, 'tool type', VALUE_OPTIONAL),
'button' => new external_value(PARAM_TEXT, 'tool label', VALUE_OPTIONAL)
)
)
);
}
}
......@@ -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_import_form;
use \assignfeedback_editpdfplus\form\axis_del_form;
use \assignfeedback_editpdfplus\admin_editor;
......@@ -68,8 +69,14 @@ class assign_feedback_editpdfplus_admin {
//Set default data (if any)
$formAddAxis->set_data($toform);
} */
$axisimportform = new axis_import_form(null, array('id' => $this->course->id), null, null, array('id' => "assignfeedback_editpdfplus_import_axis"));
$axisimportform->id = "assignfeedback_editpdfplus_import_axis";
$axisimportform->title = "";
$axisimportform->action = "import";
$widget = $this->get_widget();
//$widget->axisaddform = $formAddAxis;
$widget->axisimportform = $axisimportform;
$widget->courseid = $this->course->id;
$html .= $renderer->render_assignfeedback_editpdfplus_widget_admin($widget);
return $html;
}
......
......@@ -5,109 +5,118 @@
<div class="assignfeedback_editpdfplus_widget_admin">
<h5>{{# str }} adminsubtitle, assignfeedback_editpdfplus {{/ str }}</h5>
<div class="panel panel-default">
<div class="panel-heading">
Importation axe
</div>
<div class="panel-body">
Axes disponibles à l'importation
<table class='table table-bordered table-striped'>
<thead>
<tr>
<!--th>Cours / activité</th-->
<th>Nom</th>
<th>Outils</th>
<th>Importer</th>
</tr>
</thead>
<tbody>
{{# toolbarsDispo }}
<tr>
<!--td></td-->
<td>{{axis.label}}</td>
<td>
{{# tools }}
<button class="btn btn-default" style="{{style}}">
{{label}}
</button>
{{/ tools }}
</td>
<td><button class='btn btn-primary btn-sm' class='btnimport' data-axis='{{axis.id}}'><i class='fa fa-download'></i></button></td>
</tr>
{{/ toolbarsDispo }}
</tbody>
</table>
<div class="panel-group" id="adminAccordion">
<div class="panel panel-default">
<div class="panel-heading">
<a data-toggle="collapse" href="#collapseadmin1" data-parent="#adminAccordion">Importation axe</a>
</div>
<div id="collapseadmin1" class="panel-collapse collapse">
<div class="panel-body">
Axes disponibles à l'importation
{{{ axisimportform.render }}}
<input type="hidden" id="courseid" value="{{courseid}}" />
<table class='table table-bordered table-striped'>
<thead>
<tr>
<!--th>Cours / activité</th-->
<th>Nom</th>
<th>Outils</th>
<th>Importer</th>
</tr>
</thead>
<tbody>
{{# toolbarsDispo }}
<tr>
<!--td></td-->
<td>{{axis.label}}</td>
<td>
{{# tools }}
<button class="btn btn-default" style="{{style}}">
{{label}}
</button>
{{/ tools }}
</td>
<td><button class='btn btn-primary btn-sm btnimport' data-axis='{{axis.id}}'><i class='fa fa-download'></i></button></td>
</tr>
{{/ toolbarsDispo }}
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
{{# str }} admincurrenttoolbar, assignfeedback_editpdfplus {{/ str }}
</div>
<div class="panel-body">
<div class='row'>
<div class='col-sm-2'>
<h6>
{{# str }} adminaxis, assignfeedback_editpdfplus {{/ str }}
<button type="button" class="btn btn-default" id="assignfeedback_editpdfplus_widget_admin_button_addaxis">
<i class="fa fa-plus" aria-hidden="true"></i>
</button>
</h6>
</div>
<div class='col-sm-10' id='assignfeedback_editpdfplus_widget_admin_toolheader'>
<h6>
{{# str }} admintools, assignfeedback_editpdfplus {{/ str }}
<button type="button" class="btn btn-default" id="assignfeedback_editpdfplus_widget_admin_button_addtool">
<i class="fa fa-plus" aria-hidden="true"></i>
</button>
</h6>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<a data-toggle="collapse" href="#collapseadmin2" data-parent="#adminAccordion">{{# str }} admincurrenttoolbar, assignfeedback_editpdfplus {{/ str }}</a>
</div>
<div class='row' id='assignfeedback_editpdfplus_widget_admin_workspace'>
<div class='col-sm-2'>
<select id='editpdlplus_axes' class='form-control'>
{{# axis }}
<option value="{{id}}" data-delete="{{children}}">{{label}}</option>
{{/ axis }}
</select>
<div class="panel panel-default" id="axistool">
<div class="panel-body" style="text-align: center;">
<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" id="assignfeedback_editpdfplus_widget_admin_button_delaxis">
<i class="fa fa-remove" aria-hidden="true"></i>
</button>
<div id="collapseadmin2" class="panel-collapse collapse in">
<div class="panel-body">
<div id="message_import_axis" class="alert" style="display:none;"></div>
<div class='row'>
<div class='col-sm-2'>
<h6>
{{# str }} adminaxis, assignfeedback_editpdfplus {{/ str }}
<button type="button" class="btn btn-default" id="assignfeedback_editpdfplus_widget_admin_button_addaxis">
<i class="fa fa-plus" aria-hidden="true"></i>
</button>
</h6>
</div>
</div>
</div>
<div class='col-sm-10' id='assignfeedback_editpdfplus_widget_admin_toolworkspace'>
<div id='editpdlplus_toolbars'>
{{# toolbars }}
<div id="editpdlplus_toolbar_{{axis.id}}" class="btn-group toolbar" style="display: none;">
{{# tools }}
<button class="btn {{button}} editpdlplus_tool" id="editpdlplus_tool_{{id}}" value="{{id}}" style="{{style}}" data-enable="{{enabled}}">
{{label}}
</button>
{{/ tools }}
<div class='col-sm-10' id='assignfeedback_editpdfplus_widget_admin_toolheader'>
<h6>
{{# str }} admintools, assignfeedback_editpdfplus {{/ str }}
<button type="button" class="btn btn-default" id="assignfeedback_editpdfplus_widget_admin_button_addtool">
<i class="fa fa-plus" aria-hidden="true"></i>
</button>
</h6>
</div>
{{/ toolbars }}
</div>
<div class='row' id='assignfeedback_editpdfplus_widget_admin_workspace'>
<div class='col-sm-2'>
<select id='editpdlplus_axes' class='form-control'>
{{# axis }}
<option value="{{id}}" data-delete="{{children}}">{{label}}</option>
{{/ axis }}
</select>
<div class="panel panel-default" id="axistool">
<div class="panel-body" style="text-align: center;">
<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" id="assignfeedback_editpdfplus_widget_admin_button_delaxis">
<i class="fa fa-remove" aria-hidden="true"></i>
</button>
</div>
</div>
</div>
<div class='col-sm-10' id='assignfeedback_editpdfplus_widget_admin_toolworkspace'>
<div id='editpdlplus_toolbars'>
{{# toolbars }}
<div id="editpdlplus_toolbar_{{axis.id}}" class="btn-group toolbar" style="display: none;">
{{# tools }}
<button class="btn {{button}} editpdlplus_tool" id="editpdlplus_tool_{{id}}" value="{{id}}" style="{{style}}" data-enable="{{enabled}}">
{{label}}
</button>
{{/ tools }}
</div>
{{/ toolbars }}
</div>
<div class="alert col-sm-5" id="message_edit_tool" style="margin-top: 10px;margin-bottom: 0px;display: none;"></div>
<div class="alert col-sm-5" id="message_edit_tool" style="margin-top: 10px;margin-bottom: 0px;display: none;"></div>
<div id="editpdlplus_tool_item" class="alert col-sm-12" style="margin-top: 0px;"></div>
<div id="editpdlplus_tool_item" class="alert col-sm-12" style="margin-top: 0px;"></div>
</div>
<div class='col-sm-10'>
<div id="assignfeedback_editpdfplus_widget_admin_div_addaxis" style="display:none;">
<div class="panel-body"></div>
</div>
<div id="assignfeedback_editpdfplus_widget_admin_div_editaxis" style="display:none;">
<div class="panel-body"></div>
</div>
<div id="assignfeedback_editpdfplus_widget_admin_div_delaxis" style="display:none;">
<div class="panel-body"></div>
</div>
<div class='col-sm-10'>
<div id="assignfeedback_editpdfplus_widget_admin_div_addaxis" style="display:none;">
<div class="panel-body"></div>
</div>
<div id="assignfeedback_editpdfplus_widget_admin_div_editaxis" style="display:none;">
<div class="panel-body"></div>
</div>
<div id="assignfeedback_editpdfplus_widget_admin_div_delaxis" style="display:none;">
<div class="panel-body"></div>
</div>
</div>
</div>
</div>
</div>
......
......@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017081601;
$plugin->version = 2017081800;
$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