Gitlab CSE Unil

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

déplacement d'un outil par drag and drop

parent fef32ab6
This diff is collapsed.
define(["./global"],function(a){function b(){return this._instanceID=d(),this}var c=0,d=function(){return++c};return b.getInstanceCount=function(){return c},b.prototype.getInstanceID=function(){return this._instanceID},b.id=-1,b.axis=-1,b.typetool=-1,b.type=null,b.colors="",b.cartridge="",b.cartridgeColor="",b.texts="",b.label="",b.reply=!0,b.enabled=!0,b.orderTool=1e3,b.prototype.init=function(a){this.id=parseInt(a.id,10)||0,this.axis=parseInt(a.axis,10)||0,this.type=a.type,this.colors=a.colors,this.cartridge=a.cartridge,this.cartridgeColor=a.cartridgeColor,this.texts=a.texts,this.label=a.label,this.reply=a.reply,this.enabled=a.enabled,this.orderTool=a.orderTool},b.prototype.initAdmin=function(a){this.id=parseInt(a.toolid,10)||0,this.axis=parseInt(a.axis,10)||0,this.typetool=a.typetool,this.label=a.button,this.enabled=a.enable,this.orderTool=a.orderTool},b.prototype.getToolTypeLabel=function(){return this.type.label},b.prototype.getToolTypeCartX=function(){return this.type.cartridgeX},b.prototype.getToolTypeCartY=function(){return this.type.cartridgeY},b.prototype.get_color=function(){var b=a.ANNOTATIONCOLOUR[this.colors];return b?(b=b.replace("rgb","rgba"),b=b.replace(")",",0.5)")):b=this.colors,b&&""!==b?b:this.type.get_color()},b.prototype.get_color_cartridge=function(){var b=a.ANNOTATIONCOLOUR[this.cartridgeColor];return b?(b=b.replace("rgb","rgba"),b=b.replace(")",",0.5)")):b=this.cartridgeColor,b&&""!==b?b:this.type.get_color_cartridge()},b.prototype.getButton=function(a){var b="btn-default",c="";1!==this.enabled&&(b="",c="background-image:none;background-color:#CCCCCC;"),this.id===a&&(b="btn-primary"),4!==this.typetool&&1!==this.typetool||(c+="text-decoration: underline;");var d=this.label;4!==this.typetool&&5!==this.typetool||(d="| "+d,4===this.typetool&&(d+=" |"));var e="<button class='btn "+b+" editpdlplus_tool' id='editpdlplus_tool_"+this.id+"' style='"+c+"' value='"+this.id+"' data-enable='"+this.enabled+"'>"+d+"</button>";return e},b});
\ No newline at end of file
define(["./global"],function(a){function b(){return this._instanceID=d(),this}var c=0,d=function(){return++c};return b.getInstanceCount=function(){return c},b.prototype.getInstanceID=function(){return this._instanceID},b.id=-1,b.axis=-1,b.typetool=-1,b.type=null,b.colors="",b.cartridge="",b.cartridgeColor="",b.texts="",b.label="",b.reply=!0,b.enabled=!0,b.orderTool=1e3,b.prototype.init=function(a){this.id=parseInt(a.id,10)||0,this.axis=parseInt(a.axis,10)||0,this.type=a.type,this.colors=a.colors,this.cartridge=a.cartridge,this.cartridgeColor=a.cartridgeColor,this.texts=a.texts,this.label=a.label,this.reply=a.reply,this.enabled=a.enabled,this.orderTool=a.orderTool},b.prototype.initAdmin=function(a){this.id=parseInt(a.toolid,10)||0,this.axis=parseInt(a.axis,10)||0,this.typetool=a.typetool,this.label=a.button,this.enabled=a.enable,this.orderTool=a.orderTool},b.prototype.getToolTypeLabel=function(){return this.type.label},b.prototype.getToolTypeCartX=function(){return this.type.cartridgeX},b.prototype.getToolTypeCartY=function(){return this.type.cartridgeY},b.prototype.get_color=function(){var b=a.ANNOTATIONCOLOUR[this.colors];return b?(b=b.replace("rgb","rgba"),b=b.replace(")",",0.5)")):b=this.colors,b&&""!==b?b:this.type.get_color()},b.prototype.get_color_cartridge=function(){var b=a.ANNOTATIONCOLOUR[this.cartridgeColor];return b?(b=b.replace("rgb","rgba"),b=b.replace(")",",0.5)")):b=this.cartridgeColor,b&&""!==b?b:this.type.get_color_cartridge()},b.prototype.getButton=function(a){var b="btn-default",c="";1!==this.enabled&&(b="",c="background-image:none;background-color:#CCCCCC;"),this.id===a&&(b="btn-primary"),4!==this.typetool&&1!==this.typetool||(c+="text-decoration: underline;");var d=this.label;4!==this.typetool&&5!==this.typetool||(d="| "+d,4===this.typetool&&(d+=" |"));var e="<button class='btn "+b+" editpdlplus_tool' id='editpdlplus_tool_"+this.id+"' style='"+c+"' value='"+this.id+"' data-enable='"+this.enabled+"'>"+d+"</button>";return e},b.prototype.getButtonSortable=function(a){return"<li style='float: left;display: block;'>"+this.getButton(a)+"</li>"},b});
\ No newline at end of file
......@@ -20,6 +20,7 @@
/**
* @module mod_assignfeedback_editpdfplus/admin_panel
* @param {Jquery} $
* @param {Jqueryui} $.ui
* @param {core/notification} notification
* @param {core/templates} templates
* @param {core/fragment} fragment
......@@ -34,13 +35,13 @@
* @param {assignfeedback_editpdfplus/annotationverticalline} AnnotationVerticalline
* @param {assignfeedback_editpdfplus/annotationstampcomment} AnnotationStampcomment
*/
define(['jquery', 'core/notification', 'core/templates', 'core/fragment',
define(['jquery', 'jqueryui', 'core/notification', 'core/templates', 'core/fragment',
'core/ajax', 'core/str', 'assignfeedback_editpdfplus/tool', 'assignfeedback_editpdfplus/tooltype',
'assignfeedback_editpdfplus/annotationhighlightplus',
'assignfeedback_editpdfplus/annotationstampplus', 'assignfeedback_editpdfplus/annotationframe',
'assignfeedback_editpdfplus/annotationcommentplus', 'assignfeedback_editpdfplus/annotationverticalline',
'assignfeedback_editpdfplus/annotationstampcomment'],
function ($, notification, templates, fragment, ajax, str, Tool, ToolType,
function ($, jqui, notification, templates, fragment, ajax, str, Tool, ToolType,
AnnotationHighlightplus, AnnotationStampplus, AnnotationFrame,
AnnotationCommentplus, AnnotationVerticalline, AnnotationStampcomment) {
......@@ -219,6 +220,49 @@ define(['jquery', 'core/notification', 'core/templates', 'core/fragment',
AdminPanel.prototype.initToolUI = function () {
$(this.selectTool).removeClass("btn-default");
$(this.selectTool).addClass("btn-primary");
initSortableToolBar();
};
var initSortableToolBar = function () {
$(".sortable").sortable({
placeholder: "alert-warning",
handle: 'button',
cancel: '',
stop: function (event, uiElement) {
var prevButtonId = $(uiElement.item).prev().find("button").val();
var nextButtonId = $(uiElement.item).next().find("button").val();
var currentButtonId = $(uiElement.item).find("button").val();
$("input[name^='previoustoolid']").val(prevButtonId);
$("input[name^='toolid']").val(currentButtonId);
$("input[name^='nexttoolid']").val(nextButtonId);
var form = $('#assignfeedback_editpdfplus_order_tool');
var data = form.serialize() + "&courseid=" + $("#courseid").val();
ajax.call([
{
methodname: 'assignfeedback_editpdfplus_submit_tool_order_form',
args: {jsonformdata: JSON.stringify(data)}
}
])[0].done(function (retour) {
if (retour.message === "ok") {
//mise à jour du message
$("#message_order_tool").show();
$("#message_order_tool").html(AdminPanel.messageEditOk);
$("#message_order_tool").addClass("alert-success");
$("#message_order_tool").removeClass("alert-danger");
$("#message_order_tool").removeClass("alert-warning");
$("#message_order_tool").fadeOut(5000);
} else {
$("#message_order_tool").show();
$("#message_order_tool").html(AdminPanel.messageko);
$("#message_order_tool").addClass("alert-danger");
$("#message_order_tool").removeClass("alert-success");
$("#message_order_tool").fadeOut(5000);
}
}).fail(notification.exception);
}
});
$(".sortable").disableSelection();
};
/**
......@@ -486,8 +530,11 @@ define(['jquery', 'core/notification', 'core/templates', 'core/fragment',
//maj axis
var divAxis = "<div id='editpdlplus_toolbar_"
+ toolbar[0].axeid
+ "' class='btn-group toolbar' style='display: none;'></div>";
+ "' class='btn-group toolbar' style='display: none;'>"
+ "<ul class='sortable' style='list-style-type: none;margin: 0;padding: 0;width: 100%;'></ul>"
+ "</div>";
$('#editpdlplus_toolbars').append(divAxis);
initSortableToolBar();
var option = new Option(toolbar[0].axelabel, toolbar[0].axeid, true, true);
$("#editpdlplus_axes").append(option);
var axeOption = $("#editpdlplus_axes option[value='" + toolbar[0].axeid + "']");
......@@ -500,8 +547,8 @@ define(['jquery', 'core/notification', 'core/templates', 'core/fragment',
for (var i = 0; i < toolbar.length; i++) {
var toolTmp = new Tool();
toolTmp.initAdmin(toolbar[i]);
var buttonTmp = toolTmp.getButton(toolbar[i].selecttool);
$("#editpdlplus_toolbar_" + toolbar[0].axeid).append(buttonTmp);
var buttonTmp = toolTmp.getButtonSortable(toolbar[i].selecttool);
$("#editpdlplus_toolbar_" + toolbar[0].axeid + " > ul").append(buttonTmp);
}
} else {
var axeid = toolbar[0].axeid;
......@@ -621,12 +668,12 @@ define(['jquery', 'core/notification', 'core/templates', 'core/fragment',
$("#message_edit_tool").removeClass("alert-warning");
//mise à jour bar d'outils
$("#editpdlplus_tool_" + toolbar[0].selecttool).remove();
$("#editpdlplus_toolbar_" + toolbar[0].axeid).html("");
$("#editpdlplus_toolbar_" + toolbar[0].axeid + " > ul").html("");
for (var i = 0; i < toolbar.length; i++) {
var toolTmp = new Tool();
toolTmp.initAdmin(toolbar[i]);
var buttonTmp = toolTmp.getButton(toolbar[i].selecttool);
$("#editpdlplus_toolbar_" + toolbar[0].axeid).append(buttonTmp);
var buttonTmp = toolTmp.getButtonSortable(toolbar[i].selecttool);
$("#editpdlplus_toolbar_" + toolbar[0].axeid + " > ul").append(buttonTmp);
}
$(".editpdlplus_tool").on("click", refreshToolView);
var oldaxeid = $("#axisid").val();
......@@ -678,13 +725,13 @@ define(['jquery', 'core/notification', 'core/templates', 'core/fragment',
$("#message_edit_tool").removeClass("alert-danger");
$("#message_edit_tool").removeClass("alert-warning");
//mise à jour bar d'outils
$("#editpdlplus_toolbar_" + toolbar[0].axeid).html("");
$("#editpdlplus_toolbar_" + toolbar[0].axeid + " > ul").html("");
if (parseInt(toolbar[0].toolid) > 0) {
for (var i = 0; i < toolbar.length; i++) {
var toolTmp = new Tool();
toolTmp.initAdmin(toolbar[i]);
var buttonTmp = toolTmp.getButton(toolbar[i].selecttool);
$("#editpdlplus_toolbar_" + toolbar[0].axeid).append(buttonTmp);
var bT = toolTmp.getButtonSortable(toolbar[i].selecttool);
$("#editpdlplus_toolbar_" + toolbar[0].axeid + " > ul").append(bT);
}
$(".editpdlplus_tool").on("click", refreshToolView);
} else {
......@@ -793,12 +840,12 @@ define(['jquery', 'core/notification', 'core/templates', 'core/fragment',
$("#message_edit_tool").removeClass("alert-danger");
$("#message_edit_tool").removeClass("alert-warning");
//mise à jour bar d'outils
$("#editpdlplus_toolbar_" + toolbar[0].axeid).html("");
$("#editpdlplus_toolbar_" + toolbar[0].axeid + " > ul").html("");
for (var i = 0; i < toolbar.length; i++) {
var toolTmp = new Tool();
toolTmp.initAdmin(toolbar[i]);
var buttonTmp = toolTmp.getButton(toolbar[i].selecttool);
$("#editpdlplus_toolbar_" + toolbar[0].axeid).append(buttonTmp);
var btnTmp = toolTmp.getButtonSortable(toolbar[i].selecttool);
$("#editpdlplus_toolbar_" + toolbar[0].axeid + " > ul").append(btnTmp);
}
$(".editpdlplus_tool").on("click", refreshToolView);
$('#toolworkspace').html("");
......
......@@ -267,6 +267,14 @@ define(['./global'],
+ "</button>";
return buttonTmp;
};
/**
* Get the html code for design the tool's button into the toolbar
* @param {int} selectToolId
* @return {string} HTML code
*/
Tool.prototype.getButtonSortable = function (selectToolId) {
return "<li style='float: left;display: block;'>" + this.getButton(selectToolId) + "</li>";
};
return Tool;
});
\ No newline at end of file
......@@ -108,6 +108,34 @@ class admin_editor {
return null;
}
public static function edit_tool_order($data) {
global $DB;
$record = $DB->get_record('assignfeedback_editpp_tool', array('id' => $data->toolid), '*', MUST_EXIST);
$toolCurrent = new tool($record);
$previousorder = -1;
$toolPrevious = null;
$toolNext = null;
if ($data->previoustoolid) {
$record = $DB->get_record('assignfeedback_editpp_tool', array('id' => $data->previoustoolid), '*', MUST_EXIST);
$toolPrevious = new tool($record);
$previousorder = $toolPrevious->order_tool + 1;
} elseif ($data->nexttoolid) {
$record = $DB->get_record('assignfeedback_editpp_tool', array('id' => $data->nexttoolid), '*', MUST_EXIST);
$toolNext = new tool($record);
$previousorder = $toolNext->order_tool - 1;
}
if ($previousorder > -1 && ($toolPrevious || $toolNext )) {
if ($previousorder == 0) {
$previousorder = 1;
}
$toolCurrent->order_tool = $previousorder;
debugging($previousorder);
if ($DB->update_record('assignfeedback_editpp_tool', $toolCurrent)) {
admin_editor::reorder_tool($toolCurrent->axis, $data->toolid);
}
}
}
/**
* Order tools of a toolbar
* @global type $DB
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the tool_form class for the assignfeedback_editpdfplus plugin
*
* @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;
/**
* Form to add and edit a tool
*
* @package assignfeedback_editpdfplus
* @copyright 2017 Université de Lausanne
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_order_form extends moodleform {
protected function definition() {
$mform = $this->_form;
$mform->addElement('hidden', 'previoustoolid', 'previoustoolid'); // Add elements to your form
$mform->setType('previoustoolid', PARAM_INT); //Set type of element
$mform->addElement('hidden', 'toolid', ''); // Add elements to your form
$mform->setType('toolid', PARAM_INT); //Set type of element
$mform->addElement('hidden', 'nexttoolid', ''); // Add elements to your form
$mform->setType('nexttoolid', PARAM_INT); //Set type of element
}
//Custom validation should be added here
function validation($data, $files) {
return array();
}
}
......@@ -99,5 +99,16 @@ $functions = array(
'requiredcapability' => 'assignfeedback/editpdfplus:managetools',
'enabled' => 1,
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
),
'assignfeedback_editpdfplus_submit_tool_order_form' => array(
'classname' => 'assignfeedback_editpdfplus_external',
'methodname' => 'submit_tool_order_form',
'classpath' => 'mod/assign/feedback/editpdfplus/externallib.php',
'description' => 'Order a tool',
'type' => 'write',
'ajax' => true,
'requiredcapability' => 'assignfeedback/editpdfplus:managetools',
'enabled' => 1,
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
)
);
......@@ -551,4 +551,72 @@ class assignfeedback_editpdfplus_external extends external_api {
);
}
/**
* Returns description of method parameters
* @return external_function_parameters
*/
public static function submit_tool_order_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')
)
);
}
/**
* Submit tool form for changing order
* @global $USER
* @global $PAGE
* @global $DB
* @param String $jsonformdata
* @return array
*/
public static function submit_tool_order_form($jsonformdata) {
global $USER, $PAGE, $DB;
$params = self::validate_parameters(self::submit_tool_order_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;
$sessionkey = sesskey();
if ($sessionkey == $customdata->sesskey && $customdata->toolid) {
admin_editor::edit_tool_order($customdata);
$warnings = array('message' => 'ok');
} else {
$warnings = array('message' => get_string('admin_messageko', 'assignfeedback_editpdfplus'));
}
return $warnings;
}
/**
* Form return structure
* @return \external_multiple_structure
*/
public static function submit_tool_order_form_returns() {
return new external_single_structure(
array(
'message' => new external_value(PARAM_TEXT, 'message', VALUE_OPTIONAL)
)
);
}
}
......@@ -29,6 +29,7 @@ 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\form\tool_order_form;
use \assignfeedback_editpdfplus\admin_editor;
class assign_feedback_editpdfplus_admin {
......@@ -58,8 +59,13 @@ class assign_feedback_editpdfplus_admin {
$axisimportform->id = "assignfeedback_editpdfplus_import_axis";
$axisimportform->title = "";
$axisimportform->action = "import";
$toolorderform = new tool_order_form(null, array('id' => $this->course->id), null, null, array('id' => "assignfeedback_editpdfplus_order_tool"));
$toolorderform->id = "assignfeedback_editpdfplus_order_tool";
$toolorderform->title = "";
$toolorderform->action = "order";
$widget = $this->get_widget();
$widget->axisimportform = $axisimportform;
$widget->toolorderform = $toolorderform;
$widget->courseid = $this->course->id;
$html .= $renderer->render_assignfeedback_editpdfplus_widget_admin($widget);
return $html;
......
......@@ -32,6 +32,15 @@
<div class="assignfeedback_editpdfplus_widget_admin">
<h5>{{# str }} adminsubtitle, assignfeedback_editpdfplus {{/ str }}</h5>
<!--ul id="sortable" style="list-style-type: none;margin: 0;padding: 0;overflow: hidden;">
<li style="float: left;display: block;text-decoration: none;"><button class="sortable">Item 1</button></li>
<li style="float: left;display: block;text-decoration: none;"><button class="sortable">Item 2</button></li>
<li style="float: left;display: block;text-decoration: none;"><button class="sortable">Item 3</button></li>
<li style="float: left;display: block;text-decoration: none;"><button class="sortable">Item 4</button></li>
<li style="float: left;display: block;text-decoration: none;"><button class="sortable">Item 5</button></li>
</ul-->
<div class="panel panel-default">
<div class="panel-heading">
<a data-toggle="collapse" href="#collapseadmin1" >{{# str }} adminaxisimporttitle, assignfeedback_editpdfplus {{/ str }}</a>
......@@ -77,6 +86,7 @@
</div>
<div class="panel-body">
<div id="message_import_axis" class="alert" style="display:none;"></div>
<div id="message_order_tool" class="alert" style="display:none;"></div>
<table>
<tr>
<td class='assignfeedback_editpdfplus_widget_admin_col1'>
......@@ -118,15 +128,20 @@
<td id='assignfeedback_editpdfplus_widget_admin_toolworkspace' class='assignfeedback_editpdfplus_widget_admin_col2'>
<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 id="editpdlplus_toolbar_{{axis.id}}" class="btn-group toolbar sortable" style="display: none;width: 100%;">
<ul class="sortable" style="list-style-type: none;margin: 0;padding: 0;width: 100%;">
{{# tools }}
<li style="float: left;display: block;">
<button class="btn {{button}} editpdlplus_tool" id="editpdlplus_tool_{{id}}" value="{{id}}" style="{{style}}" data-enable="{{enabled}}">
{{label}}
</button>
</li>
{{/ tools }}
</ul>
</div>
{{/ toolbars }}
</div>
{{{ toolorderform.render }}}
<div class="alert" id="message_edit_tool"></div>
......
......@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017081801;
$plugin->version = 2017100400;
$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