Skip to content
Snippets Groups Projects
Commit 033ac171 authored by Jared Hancock's avatar Jared Hancock
Browse files

forms: Use new file upload widget for canned response designer

parent 04733190
No related branches found
No related tags found
No related merge requests found
......@@ -87,31 +87,20 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
data-draft-object-id="<?php if (isset($canned)) echo $canned->getId(); ?>"
style="width:98%;" class="richtext draft"><?php
echo $info['response']; ?></textarea>
<br><br>
<div><b><?php echo __('Canned Attachments'); ?></b> <?php echo __('(optional)'); ?>
&nbsp;<i class="help-tip icon-question-sign" href="#canned_attachments"></i>
<font class="error"><?php echo $errors['files']; ?></font></div>
<?php
if($canned && ($files=$canned->attachments->getSeparates())) {
echo '<div id="canned_attachments"><span class="faded">'.__('Uncheck to delete the attachment on submit').'</span><br>';
foreach($files as $file) {
$hash=$file['key'].md5($file['id'].session_id().strtolower($file['key']));
echo sprintf('<label><input type="checkbox" name="files[]" id="f%d" value="%d" checked="checked">
<a href="file.php?h=%s">%s</a>&nbsp;&nbsp;</label>&nbsp;',
$file['id'], $file['id'], $hash, $file['name']);
}
echo '</div><br>';
}
//Hardcoded limit... TODO: add a setting on admin panel - what happens on tickets page??
if(count($files)<10) {
?>
<div>
<input type="file" name="attachments[]" value=""/>
<div><h3><?php echo __('Canned Attachments'); ?> <?php echo __('(optional)'); ?>
&nbsp;<i class="help-tip icon-question-sign" href="#canned_attachments"></i></h3>
<div class="error"><?php echo $errors['files']; ?></div>
</div>
<?php
}?>
<div class="faded"><?php echo __('You can upload up to 10 attachments per canned response.');?></div>
if($canned && ($files=$canned->attachments->getSeparates())) {
$attachments = $canned_form->getField('attachments');
$ids = array();
foreach ($files as $f)
$ids[] = $f['id'];
$attachments->value = $ids;
print $attachments->render();
} ?>
<br/>
</td>
</tr>
<tr>
......
......@@ -28,6 +28,13 @@ $canned=null;
if($_REQUEST['id'] && !($canned=Canned::lookup($_REQUEST['id'])))
$errors['err']=sprintf(__('%s: Unknown or invalid ID.'), __('canned response'));
$canned_form = new Form(array(
'attachments' => new FileUploadField(array('id'=>'attach',
'configuration'=>array('extensions'=>false,
'size'=>$cfg->getMaxFileSize())
)),
));
if($_POST && $thisstaff->canManageCannedResponses()) {
switch(strtolower($_POST['do'])) {
case 'update':
......@@ -46,8 +53,9 @@ if($_POST && $thisstaff->canManageCannedResponses()) {
}
}
//Upload NEW attachments IF ANY - TODO: validate attachment types??
if($_FILES['attachments'] && ($files=AttachmentFile::format($_FILES['attachments'])))
$canned->attachments->upload($files);
$attachments = $canned_form->getField('attachments')->getClean();
if ($attachments)
$canned->attachments->upload($attachments);
// Attach inline attachments from the editor
if (isset($_POST['draft_id'])
......@@ -169,5 +177,6 @@ $ost->addExtraHeader('<meta name="tip-namespace" content="' . $tip_namespace . '
"$('#content').data('tipNamespace', '".$tip_namespace."');");
require(STAFFINC_DIR.'header.inc.php');
require(STAFFINC_DIR.$page);
print $canned_form->getMedia();
include(STAFFINC_DIR.'footer.inc.php');
?>
......@@ -229,8 +229,9 @@ var scp_prep = function() {
redactor.observeStart();
}
//Canned attachments.
if(canned.files && $('.canned_attachments',fObj).length) {
var fdb = $('#filedrop-attach .dropzone').data('dropbox');
var ca = $('.canned_attachments', fObj);
if(canned.files && ca.length) {
var fdb = ca.parent().find('.dropzone').data('dropbox');
$.each(canned.files,function(i, j) {
fdb.addNode(j);
});
......
......@@ -182,7 +182,7 @@ if($_POST && !$errors):
break;
case 'postnote': /* Post Internal Note */
$vars = $_POST;
$attachments = $response_form->getField('attachments')->getClean();
$attachments = $note_form->getField('attachments')->getClean();
$vars['cannedattachments'] = array_merge(
$vars['cannedattachments'] ?: array(), $attachments);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment