diff options
| author | wjames5 <will@tekimaki.com> | 2008-07-15 18:57:49 +0000 |
|---|---|---|
| committer | wjames5 <will@tekimaki.com> | 2008-07-15 18:57:49 +0000 |
| commit | c0aaf386ae6644d8ad16d449c36d8aa1010c729b (patch) | |
| tree | 09c7b84ab8c8a927a919be46b5331892bb9c235b | |
| parent | 99b91b4820069d4c45e11d4ce15ac5399df4dc33 (diff) | |
| download | liberty-c0aaf386ae6644d8ad16d449c36d8aa1010c729b.tar.gz liberty-c0aaf386ae6644d8ad16d449c36d8aa1010c729b.tar.bz2 liberty-c0aaf386ae6644d8ad16d449c36d8aa1010c729b.zip | |
attach a form_id to ajax attachment forms so that you can have multiple attachment forms on a page and have the updates all work smoothly.
| -rw-r--r-- | ajax_edit_storage.php | 11 | ||||
| -rw-r--r-- | attachment_uploader.php | 6 | ||||
| -rw-r--r-- | scripts/LibertyAttachment.js | 10 | ||||
| -rw-r--r-- | templates/attachment_uploader_inc.tpl | 3 | ||||
| -rw-r--r-- | templates/edit_storage.tpl | 7 | ||||
| -rw-r--r-- | templates/edit_storage_list.tpl | 6 | ||||
| -rw-r--r-- | templates/mime_default_upload_inc.tpl | 4 |
7 files changed, 33 insertions, 14 deletions
diff --git a/ajax_edit_storage.php b/ajax_edit_storage.php index 8d3bea9..9828a32 100644 --- a/ajax_edit_storage.php +++ b/ajax_edit_storage.php @@ -1,7 +1,7 @@ <?php /** - * $Header: /cvsroot/bitweaver/_bit_liberty/ajax_edit_storage.php,v 1.6 2008/07/07 06:08:37 squareing Exp $ - * @version $Revision: 1.6 $ + * $Header: /cvsroot/bitweaver/_bit_liberty/ajax_edit_storage.php,v 1.7 2008/07/15 18:57:49 wjames5 Exp $ + * @version $Revision: 1.7 $ * @package liberty * @subpackage functions */ @@ -20,5 +20,12 @@ include_once( LIBERTY_PKG_PATH.'edit_storage_inc.php' ); // fetch the content of the page to display $gBitThemes->setFormatHeader( 'center_only' ); + +$gBitSmarty->assign( 'uploadTab', TRUE ); + +if( isset( $_REQUEST['form_id'] ) ){ + $gBitSmarty->assign( 'form_id', $_REQUEST['form_id'] ); +} + $gBitSystem->display( 'bitpackage:liberty/edit_storage_list.tpl' , NULL, array( 'display_mode' => 'edit' )); ?> diff --git a/attachment_uploader.php b/attachment_uploader.php index b92b8f3..2b5da66 100644 --- a/attachment_uploader.php +++ b/attachment_uploader.php @@ -1,6 +1,6 @@ <?php /** - * @version $Header: /cvsroot/bitweaver/_bit_liberty/attachment_uploader.php,v 1.14 2008/06/25 22:47:56 spiderr Exp $ + * @version $Header: /cvsroot/bitweaver/_bit_liberty/attachment_uploader.php,v 1.15 2008/07/15 18:57:49 wjames5 Exp $ * @package liberty * @subpackage functions */ @@ -96,5 +96,9 @@ $gBitSmarty->assign( 'gContent', $gContent ); $gBitSmarty->assign( 'libertyUploader', TRUE ); $gBitSmarty->assign( 'uploadTab', TRUE ); +if( isset( $_REQUEST['liberty_attachments']['form_id'] ) ){ + $gBitSmarty->assign( 'form_id', $_REQUEST['liberty_attachments']['form_id'] ); +} + echo $gBitSystem->display( 'bitpackage:liberty/attachment_uploader.tpl', NULL, array( 'format'=>'none', 'display_mode' => 'display' )); ?> diff --git a/scripts/LibertyAttachment.js b/scripts/LibertyAttachment.js index 11045b3..495b989 100644 --- a/scripts/LibertyAttachment.js +++ b/scripts/LibertyAttachment.js @@ -1,10 +1,10 @@ /* Dependencies: MochiKit Base Async, BitAjax.j */ LibertyAttachment = { - "fileInputClone":null, + "fileInputClones":{}, "uploader_under_way":0, "uploaderSetup":function(fileid){ - LibertyAttachment.fileInputClone = $(fileid).cloneNode(true); + LibertyAttachment.fileInputClones[fileid] = $(fileid).cloneNode(true); }, "uploader": function(file, action, waitmsg, frmid, cform) { @@ -57,7 +57,7 @@ LibertyAttachment = { var divO = document.getElementById(divid); divR = d.getElementById('result_tab'); if (divO != null) { - divO.innerHTML = (divR != null)?divR.innerHTML:errMsg+"a"; + divO.innerHTML = (divR != null)?divR.innerHTML:errMsg+"a"; } divid = divid + '_tab'; divO = document.getElementById(divid); @@ -67,8 +67,8 @@ LibertyAttachment = { } LibertyAttachment.uploader_under_way = 0; var file = document.getElementById(fileid); - LibertyAttachment.fileInputClone.id = fileid; - MochiKit.DOM.swapDOM(file, LibertyAttachment.fileInputClone); + LibertyAttachment.fileInputClones[fileid].id = fileid; + MochiKit.DOM.swapDOM(file, LibertyAttachment.fileInputClones[fileid]); LibertyAttachment.uploaderSetup( fileid ); // file.value = ''; } diff --git a/templates/attachment_uploader_inc.tpl b/templates/attachment_uploader_inc.tpl index f2b273a..f8a4190 100644 --- a/templates/attachment_uploader_inc.tpl +++ b/templates/attachment_uploader_inc.tpl @@ -11,10 +11,11 @@ <input type="hidden" name="liberty_attachments[content_id]" id="la_content_id" value="{$gContent->mContentId}" /> <input type="hidden" name="liberty_attachments[content_type_guid]" value="{$gContent->mContentTypeGuid}" /> <input type="hidden" name="liberty_attachments[title]" id="la_title" value="{* this is a place holder populated by our upload scrpt - see LibertyAttachable.js *}" /> +<input type="hidden" name="liberty_attachments[form_id]" id="la_form_id" value="{$form_id}" /> {* Note! iFrame MUST not be display: none or Safari pops a window instead. *} {* I am not dynamically creating the iFrame to give a warning for browsers with no iframe support. *} -<iframe src="about:blank" id="liberty_upload_frame" name="liberty_upload_frame" onload="javascript:LibertyAttachment.uploaderComplete('liberty_upload_frame', 'edit_storage_list', 'upload', '{$formid|default:editpageform}');" style="position: absolute; left: -10000px;"> +<iframe src="about:blank" id="liberty_upload_frame_{$form_id}" name="liberty_upload_frame_{$form_id}" onload="javascript:LibertyAttachment.uploaderComplete('liberty_upload_frame_{$form_id}', 'edit_storage_list_{$form_id}', 'upload_{$form_id}', '{$formid|default:editpageform}');" style="position: absolute; left: -10000px;"> <div class="warning"> {tr}iFrame support is required for AJAX uploads.{/tr} {tr}You must save the content to upload an attachment.{/tr} diff --git a/templates/edit_storage.tpl b/templates/edit_storage.tpl index d684db9..738f464 100644 --- a/templates/edit_storage.tpl +++ b/templates/edit_storage.tpl @@ -1,4 +1,11 @@ {strip} +{* in some ajax cases we need to uniquely identify portions of a form so we get an id if we dont already have one *} +{if !$form_id} + {capture name=form_id} + {form_id} + {/capture} + {assign var=form_id value=$smarty.capture.form_id} +{/if} {* we will use the LibertyMime method if available *} {if $gLibertySystem->isPluginActive( $smarty.const.LIBERTY_DEFAULT_MIME_HANDLER )} {foreach from=$gLibertySystem->getAllMimeTemplates('upload') item=tpl} diff --git a/templates/edit_storage_list.tpl b/templates/edit_storage_list.tpl index 55240a6..9f7210e 100644 --- a/templates/edit_storage_list.tpl +++ b/templates/edit_storage_list.tpl @@ -1,7 +1,7 @@ {strip} {* don't replicate the surrounding div when inserting ajax content *} {if !$gBitThemes->isAjaxRequest()} - <div id="edit_storage_list{if !$uploadTab}_tab{/if}"> + <div id="edit_storage_list{if !$uploadTab}_tab{/if}{if $form_id}_{$form_id}{/if}"> {/if} {if $gContent->mStorage} <div class="row"> @@ -54,8 +54,8 @@ {capture name=urlArgs}{$attachmentBaseArgs}content_id={$gContent->mContentId}{if empty($gContent->mContentId)}{foreach from=$gContent->mStorage key=key item=val}&STORAGE[existing][{$val.attachment_id}]={$val.attachment_id}{/foreach}{/if}{/capture} {if $libertyUploader || $gBitSystem->getConfig('liberty_attachment_style') == 'ajax'} <a href="javascript:void(0);" onclick=" - BitAjax.updater('edit_storage_list_tab', '{$smarty.const.LIBERTY_PKG_URL}ajax_edit_storage.php', '{$smarty.capture.urlArgs}&deleteAttachment={$attachmentId}'); - BitAjax.updater('edit_storage_list', '{$smarty.const.LIBERTY_PKG_URL}ajax_edit_storage.php', '{$smarty.capture.urlArgs}');"> + BitAjax.updater('edit_storage_list_tab_{$form_id}', '{$smarty.const.LIBERTY_PKG_URL}ajax_edit_storage.php', '{$smarty.capture.urlArgs}&deleteAttachment={$attachmentId}&form_id={$form_id}'); + BitAjax.updater('edit_storage_list_{$form_id}', '{$smarty.const.LIBERTY_PKG_URL}ajax_edit_storage.php', '{$smarty.capture.urlArgs}&form_id={$form_id}');"> {biticon ipackage="icons" iname="edit-delete" iexplain="delete"} </a> {else} diff --git a/templates/mime_default_upload_inc.tpl b/templates/mime_default_upload_inc.tpl index 05dae4d..be8eb9b 100644 --- a/templates/mime_default_upload_inc.tpl +++ b/templates/mime_default_upload_inc.tpl @@ -14,11 +14,11 @@ </script> {formhelp note='After selecting the file you want to upload, please return to the edit area and click the save button.'} {elseif $gBitSystem->getConfig("liberty_attachment_style") == "ajax"} - <input type="file" name="upload" size="40" id="upload" onchange="javascript:LibertyAttachment.uploader(this, '{$smarty.const.LIBERTY_PKG_URL}attachment_uploader.php','{tr}Please wait for the current upload to finish.{/tr}', 'liberty_upload_frame', '{$formid|default:editpageform}');" /> + <input type="file" name="upload" size="40" id="upload_{$form_id}" onchange="javascript:LibertyAttachment.uploader(this, '{$smarty.const.LIBERTY_PKG_URL}attachment_uploader.php','{tr}Please wait for the current upload to finish.{/tr}', 'liberty_upload_frame_{$form_id}', '{$formid|default:editpageform}');" /> {include file="bitpackage:liberty/attachment_uploader_inc.tpl"} {formhelp note='After selecting the file you want to upload, please return to the edit area and click the save button.'} <script type="text/javascript"> - LibertyAttachment.uploaderSetup( 'upload' ); + LibertyAttachment.uploaderSetup( 'upload_{$form_id}' ); </script> {else} <input type="file" name="upload" size="40" /> |
