Skip to content

Commit 2748d8e

Browse files
committed
MDL-33946 course dndupload - fixes to dialog when dragging text
Radio buttons have unique IDs, matching the label IDs 'What do you want to call this text' input moved down and disabled when 'label' selected 'Add page here' changed to 'Add text here'
1 parent 5efae68 commit 2748d8e

File tree

4 files changed

+41
-14
lines changed

4 files changed

+41
-14
lines changed

course/dndupload.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,13 @@ M.course_dndupload = {
798798
return;
799799
}
800800

801+
if (type.handlers.length == 1 && type.handlers[0].noname) {
802+
// Only one handler and it doesn't need a name (i.e. a label).
803+
this.upload_item('', type.type, contents, section, sectionnumber, type.handlers[0].module);
804+
this.check_upload_queue();
805+
return;
806+
}
807+
801808
if (this.uploaddialog) {
802809
var details = new Object();
803810
details.isfile = false;
@@ -814,21 +821,22 @@ M.course_dndupload = {
814821
var uploadid = Math.round(Math.random()*100000)+'-'+timestamp;
815822
var nameid = 'dndupload_handler_name'+uploadid;
816823
var content = '';
817-
content += '<label for="'+nameid+'">'+type.namemessage+'</label>';
818-
content += ' <input type="text" id="'+nameid+'" value="" />';
819824
if (type.handlers.length > 1) {
820825
content += '<div id="dndupload_handlers'+uploadid+'">';
821826
var sel = type.handlers[0].module;
822827
for (var i=0; i<type.handlers.length; i++) {
823-
var id = 'dndupload_handler'+uploadid;
828+
var id = 'dndupload_handler'+uploadid+type.handlers[i].module;
824829
var checked = (type.handlers[i].module == sel) ? 'checked="checked" ' : '';
825-
content += '<input type="radio" name="handler" value="'+type.handlers[i].module+'" id="'+id+'" '+checked+'/>';
830+
content += '<input type="radio" name="handler" value="'+i+'" id="'+id+'" '+checked+'/>';
826831
content += ' <label for="'+id+'">';
827832
content += type.handlers[i].message;
828833
content += '</label><br/>';
829834
}
830835
content += '</div>';
831836
}
837+
var disabled = (type.handlers[0].noname) ? ' disabled = "disabled" ' : '';
838+
content += '<label for="'+nameid+'">'+type.namemessage+'</label>';
839+
content += ' <input type="text" id="'+nameid+'" value="" '+disabled+' />';
832840

833841
var Y = this.Y;
834842
var self = this;
@@ -846,23 +854,27 @@ M.course_dndupload = {
846854
e.preventDefault();
847855
var name = Y.one('#dndupload_handler_name'+uploadid).get('value');
848856
name = name.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); // Trim
849-
if (name == '') {
850-
return;
851-
}
852857
var module = false;
858+
var noname = false;
853859
if (type.handlers.length > 1) {
854860
// Find out which module was selected
855861
var div = Y.one('#dndupload_handlers'+uploadid);
856862
div.all('input').each(function(input) {
857863
if (input.get('checked')) {
858-
module = input.get('value');
864+
var idx = input.get('value');
865+
module = type.handlers[idx].module;
866+
noname = type.handlers[idx].noname;
859867
}
860868
});
861869
if (!module) {
862870
return;
863871
}
864872
} else {
865873
module = type.handlers[0].module;
874+
noname = type.handlers[0].noname;
875+
}
876+
if (name == '' && !noname) {
877+
return;
866878
}
867879
panel.hide();
868880
// Do the upload
@@ -887,6 +899,17 @@ M.course_dndupload = {
887899
});
888900
// Focus on the 'name' box
889901
Y.one('#'+nameid).focus();
902+
for (i=0; i<type.handlers.length; i++) {
903+
if (type.handlers[i].noname) {
904+
Y.one('#dndupload_handler'+uploadid+type.handlers[i].module).on('click', function (e) {
905+
Y.one('#'+nameid).set('disabled', 'disabled');
906+
});
907+
} else {
908+
Y.one('#dndupload_handler'+uploadid+type.handlers[i].module).on('click', function (e) {
909+
Y.one('#'+nameid).removeAttribute('disabled');
910+
});
911+
}
912+
}
890913
},
891914

892915
/**

course/dnduploadlib.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ public function __construct($course, $modnames = null) {
151151
}
152152
if (isset($resp['types'])) {
153153
foreach ($resp['types'] as $type) {
154-
$this->add_type_handler($type['identifier'], $modname, $type['message']);
154+
$noname = !empty($type['noname']);
155+
$this->add_type_handler($type['identifier'], $modname, $type['message'], $noname);
155156
}
156157
}
157158
}
@@ -195,8 +196,10 @@ public function add_type($identifier, $datatransfertypes, $addmessage, $namemess
195196
* @param string $module The name of the module to handle this type
196197
* @param string $message The message to show the user if more than one handler is registered
197198
* for a type and the user needs to make a choice between them
199+
* @param bool $noname If true, the 'name' dialog should be disabled in the pop-up.
200+
* @throws coding_exception
198201
*/
199-
public function add_type_handler($type, $module, $message) {
202+
public function add_type_handler($type, $module, $message, $noname) {
200203
if (!$this->is_known_type($type)) {
201204
throw new coding_exception("Trying to add handler for unknown type $type");
202205
}
@@ -205,6 +208,7 @@ public function add_type_handler($type, $module, $message) {
205208
$add->type = $type;
206209
$add->module = $module;
207210
$add->message = $message;
211+
$add->noname = $noname ? 1 : 0;
208212

209213
$this->types[$type]->handlers[] = $add;
210214
}

lang/en/moodle.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
$string['addnewcourse'] = 'Add a new course';
6666
$string['addnewuser'] = 'Add a new user';
6767
$string['addnousersrecip'] = 'Add users who haven\'t accessed this {$a} to recipient list';
68-
$string['addpagehere'] = 'Add page here';
68+
$string['addpagehere'] = 'Add text here';
6969
$string['addresource'] = 'Add a resource...';
7070
$string['addresourceoractivity'] = 'Add an activity or resource';
7171
$string['addresourcetosection'] = 'Add a resource to section \'{$a}\'';
@@ -1097,7 +1097,7 @@
10971097
$string['myprofile'] = 'My profile';
10981098
$string['name'] = 'Name';
10991099
$string['nameforlink'] = 'What do you want to call this link?';
1100-
$string['nameforpage'] = 'What do you want to call this page?';
1100+
$string['nameforpage'] = 'What do you want to call this text?';
11011101
$string['navigation'] = 'Navigation';
11021102
$string['needed'] = 'Needed';
11031103
$string['never'] = 'Never';

mod/label/lib.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ function label_dndupload_register() {
222222

223223
$strdndtext = get_string('dnduploadlabeltext', 'mod_label');
224224
return array_merge($ret, array('types' => array(
225-
array('identifier' => 'text/html', 'message' => $strdndtext),
226-
array('identifier' => 'text', 'message' => $strdndtext)
225+
array('identifier' => 'text/html', 'message' => $strdndtext, 'noname' => true),
226+
array('identifier' => 'text', 'message' => $strdndtext, 'noname' => true)
227227
)));
228228
}
229229

0 commit comments

Comments
 (0)