Skip to content
This repository has been archived by the owner on Jun 2, 2020. It is now read-only.

Commit

Permalink
MOBILE-924 assign: Complete display of submissions texts and files
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva committed Mar 24, 2015
1 parent a3d2e2d commit a76d9fe
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 7 deletions.
4 changes: 2 additions & 2 deletions emulator/mod_assign_get_assignments.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
"value": "0"
}
],
"intro": "<p>lecture</p>",
"intro": "<p>lecture description here</p>",
"introformat": 1
},
{
Expand Down Expand Up @@ -302,7 +302,7 @@
"value": "0"
}
],
"intro": "<p>Assignment: Requirements for night in the Alps<br></p>",
"intro": "<p>Assignment description here<br></p>",
"introformat": 1,
"introattachments": [
{
Expand Down
20 changes: 18 additions & 2 deletions emulator/mod_assign_get_submissions.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@
"name": "File submissions",
"fileareas": [
{
"area": "submission_files"
"area": "submission_files",
"files": [
{
"filepath": "APDFfile.pdf",
"fileurl": "http://localhost/m/stable_master/webservice/pluginfile.php/247/assignsubmission_file/submission_files/12/somefile.pdf"
},
{
"filepath": "anotherfile.docx",
"fileurl": "http://localhost/m/stable_master/webservice/pluginfile.php/247/assignsubmission_file/submission_files/12/somefile.pdf"
}
]
}
]
},
Expand Down Expand Up @@ -81,7 +91,13 @@
"name": "File submissions",
"fileareas": [
{
"area": "submission_files"
"area": "submission_files",
"files": [
{
"filepath": "somefile.pdf",
"fileurl": "http://localhost/m/stable_master/webservice/pluginfile.php/247/assignsubmission_file/submission_files/12/somefile.pdf"
}
]
}
]
},
Expand Down
1 change: 1 addition & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@
"spaceusage": "Space usage",
"stop": "Stop",
"strings": "Strings",
"submissions": "Submissions",
"synchronization": "Synchronization",
"syncthistasknow": "Synchronize this task now",
"system": "System",
Expand Down
46 changes: 46 additions & 0 deletions lib/mm.widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,52 @@ MM.widgets = {
});
}, 1000);

},

/**
* Renders a modal with an iframe injecting html content.
* @param {String} title Title to show in the modal.
* @param {String} content iframe's content.
*/
renderIframeModalContents: function(title, html) {

var height = $(window).height() - 200;
var iframestyle = 'border: none; width: 100%; height: 100%';
var iframe = '<iframe id="page-view-iframe" style="' + iframestyle + '">';
iframe += '</iframe>';
var divstyle = 'overflow-y: scroll; -webkit-overflow-scrolling: touch; height: ' + height + 'px';
var content = '<div style="' + divstyle + '">' + iframe + '</div>';

var options = {
title: title,
width: "100%",
marginTop: "10px"
};
MM.widgets.dialog(content, options);

MM.handleExternalLinks('.modalHeader a[target="_blank"]');

$("#dialog-close").on(MM.clickType, function(e){
MM.widgets.dialogClose();
});

// Inject the HTMl inside the iframe.
var iframe = $('#page-view-iframe');
iframe.ready(function() {
iframe.contents().find("body").append(html);
});

// Handle external links inside the iframe.
setTimeout(function() {
iframe.contents().find('a').click(function(e) {
var href = $(this).attr('href');
if (href.indexOf("http") > -1) {
e.preventDefault();
window.open(href, '_blank');
}
});
}, 1000);

},

enhanceButton: function(id) {
Expand Down
22 changes: 20 additions & 2 deletions plugins/assign/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,23 @@ define(templates, function (assignTpl, submissionsTpl) {

MM.plugins.assign._downloadFile(url, filename, attachmentId);
});

// View submission texts.
$(".submissiontext", "#panel-right").on(MM.clickType, function(e) {
e.preventDefault();
e.stopPropagation();

var submissionid = $(this).data("submissionid");
var submission = {};
data.submissions.forEach(function(s) {
if (s.id == submissionid) {
submission = s;
}
})
var text = MM.plugins.assign._getSubmissionText(submission);
MM.widgets.renderIframeModalContents(pageTitle, text);

});
},

_getSubmissionText: function(submission) {
Expand All @@ -243,13 +260,14 @@ define(templates, function (assignTpl, submissionsTpl) {
var files = [];
if (submission.plugins) {
submission.plugins.forEach(function(plugin) {
if (plugin.type == 'file' && plugin.fileareas) {
if (plugin.type == 'file' && plugin.fileareas && plugin.fileareas[0] && plugin.fileareas[0].files) {
files = plugin.fileareas[0].files;
}
});
}
// Find local path of files.
if (files.length > 0) {
console.log(files);
for (var el in files) {
var file = files[el];

Expand All @@ -261,7 +279,7 @@ define(templates, function (assignTpl, submissionsTpl) {
files[el].localpath = path.get("localpath");
}

var extension = MM.util.getFileExtension(file.filename);
var extension = MM.util.getFileExtension(file.filepath);
if (typeof(MM.plugins.contents.templates.mimetypes[extension]) != "undefined") {
files[el].icon = MM.plugins.contents.templates.mimetypes[extension]["icon"] + "-64.png";
}
Expand Down
44 changes: 43 additions & 1 deletion plugins/assign/submissions.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ <h2><%= MM.util.formatText(assign.name) %></h2>
</div>

<% if (canviewsubmissions) { %>
<h3><%= MM.lang.s('submissions') %></h3>
<% _.each(submissions, function(submission) { %>
<% user = {'fullname': 'User with Id' + submission.userid, 'profileimageurl': ''}; %>
<% if (typeof users[submission.userid] != 'undefined') { %>
Expand All @@ -106,7 +107,48 @@ <h2><%= MM.util.formatText(assign.name) %></h2>
<time><img src="img/time.png"><%= MM.util.timestampToUserDate(submission.timemodified) %></time>
<p><%= MM.lang.s('attempnumber') %> <%= submission.attemptnumber %></p>

<a href=""><%= MM.lang.s('viewsubmission') %></a>
<% var text = MM.plugins.assign._getSubmissionText(submission); %>
<% var files = MM.plugins.assign._getSubmissionFiles(submission); %>

<% if (text != '') { %>
<a href="#" class="submissiontext" data-submissionid="<%= submission.id %>"><%= MM.lang.s('viewsubmission') %></a>
<% } %>

<% if (files.length > 0) { %>

<div class="files">
<% _.each(files, function(file) { %>
<% if (file.localpath) { %>
<% var dImg = "reloadgrey"; %>
<% } else { %>
<% var dImg = "download"; %>
<% } %>
<div class="file media">
<div class="content-actions app-icon">
<img id="downimg-<%= file.id %>" src="img/<%= dImg %>.png" class="assign-download" data-downloadurl="<%= file.fileurl %>" data-filename="<%= file.filepath %>" data-attachmentid="<%= file.id %>">
</div>
<div class="content-name">
<div class="img app-ico">
<img src="img/files/<%= file.icon %>" alt="img">
</div>
<div class="bd">
<% if (!file.localpath) { %>
<a id="file-<%= file.id %>" class="assign-download" href="#" data-downloadurl="<%= file.fileurl %>" data-filename="<%= file.filepath %>" data-attachmentid="<%= file.id %>">
<%= file.filepath %>
</a>
<% } else { %>
<a id="file-<%= file.id %>" href="<%= file.localpath %>" rel="external"
><%= file.filepath %>
</a>
<% } %>
</div>
</div>
</div>

<% }); %>
</div>

<% } %>

</div>
</div>
Expand Down

0 comments on commit a76d9fe

Please sign in to comment.