Skip to content

Commit

Permalink
Dev: Replace file-upload jQuery UI with bootstrap modal
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Mar 23, 2016
1 parent 576198d commit 448c1e0
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 8 deletions.
39 changes: 31 additions & 8 deletions application/helpers/qanda_helper.php
Expand Up @@ -2531,12 +2531,6 @@ function do_file_upload($ia)
$questgrppreview = 0;
}

$uploadurl = $scriptloc . "?sid=" . Yii::app()->getConfig('surveyID') . "&fieldname=" . $ia[1] . "&qid=" . $ia[0];
$uploadurl .= "&preview=" . $questgrppreview . "&show_title=" . $aQuestionAttributes['show_title'];
$uploadurl .= "&show_comment=" . $aQuestionAttributes['show_comment'];
$uploadurl .= "&minfiles=" . $aQuestionAttributes['min_num_of_files']; // TODO: Regression here: Should use LEMval(minfiles)
$uploadurl .= "&maxfiles=" . $aQuestionAttributes['max_num_of_files']; // Same here.

$answer = "<script type='text/javascript'>
function upload_$ia[1]() {
var uploadurl = '{$scriptloc}?sid=".Yii::app()->getConfig('surveyID')."&fieldname={$ia[1]}&qid={$ia[0]}';
Expand Down Expand Up @@ -2628,8 +2622,37 @@ function upload_$ia[1]() {
});
</script>';

//$('<iframe id=\"uploader\" name=\"uploader\" class=\"externalSite\" src=\"' + this.href + '\" />').dialog({
$answer .= "<div id='uploader-div' class='hidden'><iframe id='uploader' name='uploader' class='externalSite' src='{$uploadurl}'></iframe></div>";
$uploadurl = $scriptloc . "?sid=" . Yii::app()->getConfig('surveyID') . "&fieldname=" . $ia[1] . "&qid=" . $ia[0];
$uploadurl .= "&preview=" . $questgrppreview . "&show_title=" . $aQuestionAttributes['show_title'];
$uploadurl .= "&show_comment=" . $aQuestionAttributes['show_comment'];
$uploadurl .= "&minfiles=" . $aQuestionAttributes['min_num_of_files']; // TODO: Regression here? Should use LEMval(minfiles) like above
$uploadurl .= "&maxfiles=" . $aQuestionAttributes['max_num_of_files']; // Same here.

$answer .= '
<!-- Trigger the modal with a button -->
<!-- <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>-->
<!-- Modal -->
<div id="file-upload-modal-' . $ia[1] . '" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content" style="vertical-align: middle;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">' . ngT("Upload file|Upload files", 1) . '</h4>
</div>
<div class="modal-body file-upload-modal-body">
<iframe id="uploader" name="uploader" class="externalSite" src="' . $uploadurl . '"></iframe>
</div>
<div class="modal-footer file-upload-modal-footer">
<button type="button" class="btn btn-success" data-dismiss="modal">' . gT("Save changes") . '</button>
</div>
</div>
</div>
</div>
';

$inputnames[] = $ia[1];
$inputnames[] = $ia[1]."_filecount";
Expand Down
20 changes: 20 additions & 0 deletions scripts/modaldialog.js
Expand Up @@ -18,6 +18,26 @@ function openUploadModalDialog(){

//$('#uploader').dialog('destroy').remove(); // destroy the old modal dialog
//$('<iframe id=\"uploader\" name=\"uploader\" class=\"externalSite\" src=\"' + this.href + '\" />').dialog({
console.log('fieldname', fieldname);
$('#file-upload-modal-' + fieldname).modal();
$('#file-upload-modal-' + fieldname).on('show.bs.modal', function() {
$('#file-upload-modal-' + fieldname).find('iframe').css('height', 'inherit');
});
$('#file-upload-modal-' + fieldname).on('hide.bs.modal', function() {
var pass;
if(document.getElementById('uploader').contentDocument) {
if(document.getElementById('uploader').contentDocument.defaultView)
{ /*Firefox*/
pass=document.getElementById('uploader').contentDocument.defaultView.saveAndExit(fieldname,show_title,show_comment,pos);
}else{ /*IE8*/
pass=document.getElementById('uploader').contentWindow.saveAndExit(fieldname,show_title,show_comment,pos);
}
}else{ /*IE6*/
pass=document.getElementById('uploader').contentWindow.saveAndExit(fieldname,show_title,show_comment,pos);
}
return pass;
});

$('#uploader-div').dialog({
title: uploadLang.title,
autoOpen: true,
Expand Down
4 changes: 4 additions & 0 deletions styles-public/uploader.css
Expand Up @@ -116,3 +116,7 @@ text-align:left;
background-color: #FFBABA;
background-image: url('img/upload-error.png');
}

body.uploader {
padding-top: 2em;
}
32 changes: 32 additions & 0 deletions templates/default/css/template.css
Expand Up @@ -963,3 +963,35 @@ table {
padding: 0;
}
}

/* Center modal vertically, used by file-upload modal */
.modal {
text-align: center;
padding: 0!important;
}
.modal:before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
margin-right: -4px;
}
.modal-dialog {
display: inline-block;
text-align: left;
vertical-align: middle;
}

/* Make file upload modal fit to iframe */
.file-upload-modal-body iframe {
height: inherit;
width: 100%;
border: none;
}
.file-upload-modal-body {
padding: 0;
height: 500px;
}
.file-upload-modal-footer {
margin-top: 0;
}

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Mar 23, 2016

Collaborator

Why not put this in styles-public/upload.css ? And call it for all template ?

5 comments on commit 448c1e0

@LouisGac
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because some people could want to use different CSS to style it ?

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but can easily update in own css if needed.

Actually : the 2 other included template need fix too : http://limesurvey.sondages.pro/index.php/survey/index/sid/914895/newtest/Y/lang/fr

With a upload.css : we don't need to fix each template. Basic fix is done by LS, extra fix is done in template.

You can use bootstrat but add a css to see alert in yellow : one line to update. It's call Cascading Style Sheet.

@olleharstedt
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some problems with CSS load order and styles-public. We can look into this later.

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes , OK . In 2.06 : we load qanda and after we go to templatereplace. Then template/template.css was loaded the last one ....
Your right : order must be

  • core css/js file
  • plugin css/js file (but plugin can be fixed after)
  • template css/js file .

:)

@LouisGac
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work.
But please, don't add HTML in quanda. Use views.

Please sign in to comment.