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); ...@@ -87,31 +87,20 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
data-draft-object-id="<?php if (isset($canned)) echo $canned->getId(); ?>" data-draft-object-id="<?php if (isset($canned)) echo $canned->getId(); ?>"
style="width:98%;" class="richtext draft"><?php style="width:98%;" class="richtext draft"><?php
echo $info['response']; ?></textarea> echo $info['response']; ?></textarea>
<br><br> <div><h3><?php echo __('Canned Attachments'); ?> <?php echo __('(optional)'); ?>
<div><b><?php echo __('Canned Attachments'); ?></b> <?php echo __('(optional)'); ?> &nbsp;<i class="help-tip icon-question-sign" href="#canned_attachments"></i></h3>
&nbsp;<i class="help-tip icon-question-sign" href="#canned_attachments"></i> <div class="error"><?php echo $errors['files']; ?></div>
<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> </div>
<?php <?php
}?> if($canned && ($files=$canned->attachments->getSeparates())) {
<div class="faded"><?php echo __('You can upload up to 10 attachments per canned response.');?></div> $attachments = $canned_form->getField('attachments');
$ids = array();
foreach ($files as $f)
$ids[] = $f['id'];
$attachments->value = $ids;
print $attachments->render();
} ?>
<br/>
</td> </td>
</tr> </tr>
<tr> <tr>
......
...@@ -28,6 +28,13 @@ $canned=null; ...@@ -28,6 +28,13 @@ $canned=null;
if($_REQUEST['id'] && !($canned=Canned::lookup($_REQUEST['id']))) if($_REQUEST['id'] && !($canned=Canned::lookup($_REQUEST['id'])))
$errors['err']=sprintf(__('%s: Unknown or invalid ID.'), __('canned response')); $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()) { if($_POST && $thisstaff->canManageCannedResponses()) {
switch(strtolower($_POST['do'])) { switch(strtolower($_POST['do'])) {
case 'update': case 'update':
...@@ -46,8 +53,9 @@ if($_POST && $thisstaff->canManageCannedResponses()) { ...@@ -46,8 +53,9 @@ if($_POST && $thisstaff->canManageCannedResponses()) {
} }
} }
//Upload NEW attachments IF ANY - TODO: validate attachment types?? //Upload NEW attachments IF ANY - TODO: validate attachment types??
if($_FILES['attachments'] && ($files=AttachmentFile::format($_FILES['attachments']))) $attachments = $canned_form->getField('attachments')->getClean();
$canned->attachments->upload($files); if ($attachments)
$canned->attachments->upload($attachments);
// Attach inline attachments from the editor // Attach inline attachments from the editor
if (isset($_POST['draft_id']) if (isset($_POST['draft_id'])
...@@ -169,5 +177,6 @@ $ost->addExtraHeader('<meta name="tip-namespace" content="' . $tip_namespace . ' ...@@ -169,5 +177,6 @@ $ost->addExtraHeader('<meta name="tip-namespace" content="' . $tip_namespace . '
"$('#content').data('tipNamespace', '".$tip_namespace."');"); "$('#content').data('tipNamespace', '".$tip_namespace."');");
require(STAFFINC_DIR.'header.inc.php'); require(STAFFINC_DIR.'header.inc.php');
require(STAFFINC_DIR.$page); require(STAFFINC_DIR.$page);
print $canned_form->getMedia();
include(STAFFINC_DIR.'footer.inc.php'); include(STAFFINC_DIR.'footer.inc.php');
?> ?>
...@@ -229,8 +229,9 @@ var scp_prep = function() { ...@@ -229,8 +229,9 @@ var scp_prep = function() {
redactor.observeStart(); redactor.observeStart();
} }
//Canned attachments. //Canned attachments.
if(canned.files && $('.canned_attachments',fObj).length) { var ca = $('.canned_attachments', fObj);
var fdb = $('#filedrop-attach .dropzone').data('dropbox'); if(canned.files && ca.length) {
var fdb = ca.parent().find('.dropzone').data('dropbox');
$.each(canned.files,function(i, j) { $.each(canned.files,function(i, j) {
fdb.addNode(j); fdb.addNode(j);
}); });
......
...@@ -182,7 +182,7 @@ if($_POST && !$errors): ...@@ -182,7 +182,7 @@ if($_POST && !$errors):
break; break;
case 'postnote': /* Post Internal Note */ case 'postnote': /* Post Internal Note */
$vars = $_POST; $vars = $_POST;
$attachments = $response_form->getField('attachments')->getClean(); $attachments = $note_form->getField('attachments')->getClean();
$vars['cannedattachments'] = array_merge( $vars['cannedattachments'] = array_merge(
$vars['cannedattachments'] ?: array(), $attachments); $vars['cannedattachments'] ?: array(), $attachments);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment