Skip to content

Commit

Permalink
Dev: Better file upload pop-up on Firefox (still not good enough)
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Mar 23, 2016
1 parent 60ce7e1 commit 576198d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 44 deletions.
9 changes: 9 additions & 0 deletions application/helpers/qanda_helper.php
Expand Up @@ -2531,6 +2531,12 @@ 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 @@ -2622,6 +2628,9 @@ 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>";

$inputnames[] = $ia[1];
$inputnames[] = $ia[1]."_filecount";
return array($answer, $inputnames);
Expand Down
90 changes: 46 additions & 44 deletions scripts/modaldialog.js
Expand Up @@ -16,52 +16,54 @@ function openUploadModalDialog(){
var windowwidth = $(window).width()-30;
var dialogwidth= Math.min(windowwidth, 940);

$('#uploader').dialog('destroy').remove(); // destroy the old modal dialog
$('<iframe id=\"uploader\" name=\"uploader\" class=\"externalSite\" src=\"' + this.href + '\" />').dialog({
title: uploadLang.title,
autoOpen: true,
width: dialogwidth,
height: 'auto',
open: function( event, ui ) {
setWidthUploader();
},
modal: true,
resizable: false,
autoResize: false,
draggable: true,
closeOnEscape: false,
dialogClass: "dialog-upload",
beforeClose: 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*/
//$('#uploader').dialog('destroy').remove(); // destroy the old modal dialog
//$('<iframe id=\"uploader\" name=\"uploader\" class=\"externalSite\" src=\"' + this.href + '\" />').dialog({
$('#uploader-div').dialog({
title: uploadLang.title,
autoOpen: true,
width: dialogwidth,
height: 'auto',
open: function( event, ui ) {
$('#uploader-div').removeClass('hidden');
setWidthUploader();
},
modal: true,
resizable: false,
autoResize: false,
draggable: true,
closeOnEscape: false,
dialogClass: "dialog-upload",
beforeClose: 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);
}
return pass;
},
overlay: {
opacity: 0.85,
background: 'black'
},
buttons: buttonsOpts,
close: function( ) {
checkconditions();
},
create: function() {
// Add Bootstrap class to button
$('.ui-dialog-buttonset button').addClass('btn btn-default');

// Remove borders
// TODO: Use this instead? http://plugins.krajee.com/file-input
$('.ui-widget-content').css('border', 'none');
}else{ /*IE6*/
pass=document.getElementById('uploader').contentWindow.saveAndExit(fieldname,show_title,show_comment,pos);
}
});
return pass;
},
overlay: {
opacity: 0.85,
background: 'black'
},
buttons: buttonsOpts,
close: function( ) {
checkconditions();
},
create: function() {
// Add Bootstrap class to button
$('.ui-dialog-buttonset button').addClass('btn btn-default');

// Remove borders
// TODO: Use this instead? http://plugins.krajee.com/file-input
$('.ui-widget-content').css('border', 'none');
}
});
});
}
$(window).resize(function() {
Expand All @@ -71,7 +73,7 @@ $(window).resize(function() {
});
/* Reset the position of the dialog (recenter) */
function resetUploaderPosition(){
$( "#uploader" ).dialog( "option", "position", $( "#uploader" ).dialog( "option", "position" ) );
//$( "#uploader" ).dialog( "option", "position", $( "#uploader" ).dialog( "option", "position" ) );

}
/* Set the with of upload madal and uploader frame according to windows width */
Expand Down

0 comments on commit 576198d

Please sign in to comment.