MDL-42801 JavaScript: Fix dndupload to match actual style

This commit is contained in:
Andrew Nicols 2013-11-06 23:52:04 +08:00
parent bbb291b7b7
commit 9b2ad813b8
2 changed files with 21 additions and 82 deletions

View File

@ -736,38 +736,13 @@ M.course_dndupload = {
var result = JSON.parse(xhr.responseText);
if (result) {
if (result.error == 0) {
// All OK - update the dummy element
if (result.content) {
// A label
resel.indentdiv.innerHTML = '<div class="activityinstance" ></div>' + result.content + result.commands;
} else {
// Not a label
resel.icon.src = result.icon;
resel.a.href = result.link;
resel.namespan.innerHTML = result.name;
if (!parseInt(result.visible, 10)) {
resel.a.className = 'dimmed';
}
if (result.groupingname) {
resel.groupingspan.innerHTML = '(' + result.groupingname + ')';
} else {
resel.div.removeChild(resel.groupingspan);
}
resel.div.removeChild(resel.progressouter);
resel.indentdiv.innerHTML += result.commands;
if (result.onclick) {
resel.a.onclick = result.onclick;
}
if (self.Y.UA.gecko > 0) {
// Fix a Firefox bug which makes sites with a '~' in their wwwroot
// log the user out when clicking on the link (before refreshing the page).
resel.div.innerHTML = unescape(resel.div.innerHTML);
}
// All OK - replace the dummy element.
resel.li.outerHTML = result.fullcontent;
if (self.Y.UA.gecko > 0) {
// Fix a Firefox bug which makes sites with a '~' in their wwwroot
// log the user out when clicking on the link (before refreshing the page).
resel.li.outerHTML = unescape(resel.li.outerHTML);
}
resel.li.id = result.elementid;
self.add_editing(result.elementid);
} else {
// Error - remove the dummy element
@ -986,39 +961,14 @@ M.course_dndupload = {
var result = JSON.parse(xhr.responseText);
if (result) {
if (result.error == 0) {
// All OK - update the dummy element
if (result.content) {
// A label
resel.indentdiv.innerHTML = '<div class="activityinstance" ></div>' + result.content + result.commands;
} else {
// Not a label
resel.icon.src = result.icon;
resel.a.href = result.link;
resel.namespan.innerHTML = result.name;
if (!parseInt(result.visible, 10)) {
resel.a.className = 'dimmed';
}
if (result.groupingname) {
resel.groupingspan.innerHTML = '(' + result.groupingname + ')';
} else {
resel.div.removeChild(resel.groupingspan);
}
resel.div.removeChild(resel.progressouter);
resel.div.innerHTML += result.commands;
if (result.onclick) {
resel.a.onclick = result.onclick;
}
if (self.Y.UA.gecko > 0) {
// Fix a Firefox bug which makes sites with a '~' in their wwwroot
// log the user out when clicking on the link (before refreshing the page).
resel.div.innerHTML = unescape(resel.div.innerHTML);
}
// All OK - replace the dummy element.
resel.li.outerHTML = result.fullcontent;
if (self.Y.UA.gecko > 0) {
// Fix a Firefox bug which makes sites with a '~' in their wwwroot
// log the user out when clicking on the link (before refreshing the page).
resel.li.outerHTML = unescape(resel.li.outerHTML);
}
resel.li.id = result.elementid;
self.add_editing(result.elementid, sectionnumber);
self.add_editing(result.elementid);
} else {
// Error - remove the dummy element
resel.parent.removeChild(resel.li);

View File

@ -722,29 +722,18 @@ class dndupload_ajax_processor {
*/
protected function send_response($mod) {
global $OUTPUT, $PAGE;
$courserenderer = $PAGE->get_renderer('core', 'course');
$resp = new stdClass();
$resp->error = self::ERROR_OK;
$resp->icon = $mod->get_icon_url()->out();
$resp->name = $mod->name;
if ($mod->has_view()) {
$resp->link = $mod->get_url()->out();
} else {
$resp->link = null;
}
$resp->content = $mod->get_content();
$resp->elementid = 'module-'.$mod->id;
$actions = course_get_cm_edit_actions($mod, 0, $mod->sectionnum);
$resp->commands = ' '. $courserenderer->course_section_cm_edit_actions($actions, $mod);
$resp->onclick = $mod->get_on_click();
$resp->visible = $mod->visible;
$resp->elementid = 'module-' . $mod->id;
// If using groupings, then display grouping name.
if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', $this->context)) {
$groupings = groups_get_all_groupings($this->course->id);
$resp->groupingname = format_string($groupings[$mod->groupingid]->name);
}
$courserenderer = $PAGE->get_renderer('core', 'course');
$completioninfo = new completion_info($this->course);
$info = get_fast_modinfo($this->course);
$sr = null;
$modulehtml = $courserenderer->course_section_cm($this->course, $completioninfo,
$mod, null, array());
$resp->fullcontent = $courserenderer->course_section_cm_list_item($this->course, $completioninfo, $mod, $sr);
echo $OUTPUT->header();
echo json_encode($resp);