|
@@ -67,152 +67,17 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
|
|
|
{
|
|
|
public function OnDisplayProperties($oObject, WebPage $oPage, $bEditMode = false)
|
|
|
{
|
|
|
+ if ($this->GetAttachmentsPosition() == 'properties')
|
|
|
+ {
|
|
|
+ $this->DisplayAttachments($oObject, $oPage, $bEditMode);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public function OnDisplayRelations($oObject, WebPage $oPage, $bEditMode = false)
|
|
|
{
|
|
|
- $bDisplayTab = $this->IsTargetObject($oObject);
|
|
|
- // Exit here if the class is not allowed
|
|
|
- if (!$bDisplayTab) return;
|
|
|
-
|
|
|
- $oSearch = DBObjectSearch::FromOQL("SELECT Attachment WHERE item_class = :class AND item_id = :item_id");
|
|
|
- $oSet = new DBObjectSet($oSearch, array(), array('class' => get_class($oObject), 'item_id' => $oObject->GetKey()));
|
|
|
- $sTitle = ($oSet->Count() > 0)? Dict::Format('Attachments:TabTitle_Count', $oSet->Count()) : Dict::S('Attachments:EmptyTabTitle');
|
|
|
- $oPage->SetCurrentTab($sTitle);
|
|
|
- $oPage->add_style(
|
|
|
-<<<EOF
|
|
|
-.attachment {
|
|
|
- display: inline-block;
|
|
|
- text-align:center;
|
|
|
- float:left;
|
|
|
- padding:5px;
|
|
|
-}
|
|
|
-.attachment:hover {
|
|
|
- background-color: #e0e0e0;
|
|
|
-}
|
|
|
-.attachment img {
|
|
|
- border: 0;
|
|
|
-}
|
|
|
-.attachment a {
|
|
|
- text-decoration: none;
|
|
|
- color: #1C94C4;
|
|
|
-}
|
|
|
-.btn_hidden {
|
|
|
- display: none;
|
|
|
-}
|
|
|
-EOF
|
|
|
- );
|
|
|
- $oPage->add('<fieldset>');
|
|
|
- $oPage->add('<legend>'.Dict::S('Attachments:FieldsetTitle').'</legend>');
|
|
|
-
|
|
|
- if ($bEditMode)
|
|
|
+ if ($this->GetAttachmentsPosition() == 'relations')
|
|
|
{
|
|
|
- $sIsDeleteEnabled = $this->m_bDeleteEnabled ? 'true' : 'false';
|
|
|
- $iTransactionId = $oPage->GetTransactionId();
|
|
|
- $oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'modules/itop-attachments/ajaxfileupload.js');
|
|
|
- $sClass = get_class($oObject);
|
|
|
- $sTempId = session_id().'_'.$iTransactionId;
|
|
|
- $sDeleteBtn = Dict::S('Attachments:DeleteBtn');
|
|
|
- $oPage->add_script(
|
|
|
-<<<EOF
|
|
|
- function RemoveNewAttachment(att_id)
|
|
|
- {
|
|
|
- $('#attachment_'+att_id).attr('name', 'removed_attachments[]');
|
|
|
- $('#display_attachment_'+att_id).hide();
|
|
|
- return false; // Do not submit the form !
|
|
|
- }
|
|
|
- function ajaxFileUpload()
|
|
|
- {
|
|
|
- //starting setting some animation when the ajax starts and completes
|
|
|
- $("#loading").ajaxStart(function(){
|
|
|
- $(this).show();
|
|
|
- }).ajaxComplete(function(){
|
|
|
- $(this).hide();
|
|
|
- });
|
|
|
-
|
|
|
- /*
|
|
|
- prepareing ajax file upload
|
|
|
- url: the url of script file handling the uploaded files
|
|
|
- fileElementId: the file type of input element id and it will be the index of $_FILES Array()
|
|
|
- dataType: it support json, xml
|
|
|
- secureuri:use secure protocol
|
|
|
- success: call back function when the ajax complete
|
|
|
- error: callback function when the ajax failed
|
|
|
-
|
|
|
- */
|
|
|
- $.ajaxFileUpload
|
|
|
- (
|
|
|
- {
|
|
|
- url: GetAbsoluteUrlAppRoot()+'modules/itop-attachments/ajax.attachment.php?obj_class={$sClass}&temp_id={$sTempId}&operation=add',
|
|
|
- secureuri:false,
|
|
|
- fileElementId:'file',
|
|
|
- dataType: 'json',
|
|
|
- success: function (data, status)
|
|
|
- {
|
|
|
- if(typeof(data.error) != 'undefined')
|
|
|
- {
|
|
|
- if(data.error != '')
|
|
|
- {
|
|
|
- alert(data.error);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var sDownloadLink = GetAbsoluteUrlAppRoot()+'pages/ajax.render.php/?operation=download_document&class=Attachment&id='+data.att_id+'&field=contents';
|
|
|
- $('#attachments').append('<div class="attachment" id="display_attachment_'+data.att_id+'"><a href="'+sDownloadLink+'"><img src="'+data.icon+'"><br/>'+data.msg+'<input id="attachment_'+data.att_id+'" type="hidden" name="attachments[]" value="'+data.att_id+'"/></a><br/><input type="button" class="btn_hidden" value="{$sDeleteBtn}" onClick="RemoveNewAttachment('+data.att_id+');"/></div>');
|
|
|
- if($sIsDeleteEnabled)
|
|
|
- {
|
|
|
- $('#display_attachment_'+data.att_id).hover( function() { $(this).children(':button').toggleClass('btn_hidden'); } );
|
|
|
- }
|
|
|
- //alert(data.msg);
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- error: function (data, status, e)
|
|
|
- {
|
|
|
- alert(e);
|
|
|
- }
|
|
|
- }
|
|
|
- )
|
|
|
-
|
|
|
- return false;
|
|
|
-
|
|
|
- }
|
|
|
-EOF
|
|
|
-);
|
|
|
- $oPage->add('<span id="attachments">');
|
|
|
- while ($oAttachment = $oSet->Fetch())
|
|
|
- {
|
|
|
- $iAttId = $oAttachment->GetKey();
|
|
|
- $oDoc = $oAttachment->Get('contents');
|
|
|
- $sFileName = $oDoc->GetFileName();
|
|
|
- $sIcon = utils::GetAbsoluteUrlAppRoot().AttachmentPlugIn::GetFileIcon($sFileName);
|
|
|
- $sDownloadLink = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php/?operation=download_document&class=Attachment&id='.$iAttId.'&field=contents';
|
|
|
- $oPage->add('<div class="attachment" id="attachment_'.$iAttId.'"><a href="'.$sDownloadLink.'"><img src="'.$sIcon.'"><br/>'.$sFileName.'<input type="hidden" name="attachments[]" value="'.$iAttId.'"/></a><br/> <input id="btn_remove_'.$iAttId.'" type="button" class="btn_hidden" value="Delete" onClick="$(\'#attachment_'.$iAttId.'\').remove();"/> </div>');
|
|
|
- }
|
|
|
- $oPage->add('</span>');
|
|
|
- $oPage->add('<div style="clear:both"></div>');
|
|
|
- $sMaxUpload = $this->GetMaxUpload();
|
|
|
- $oPage->p(Dict::S('Attachments:AddAttachment').'<input type="file" name="file" id="file" onChange="ajaxFileUpload();"><span style="display:none;" id="loading"> <img src="../images/indicator.gif"></span> '.$sMaxUpload);
|
|
|
- //$oPage->p('<input type="button" onClick="ajaxFileUpload();" value=" Upload !">');
|
|
|
- $oPage->p('<span style="display:none;" id="loading">Loading, please wait...</span>');
|
|
|
- $oPage->add('</fieldset>');
|
|
|
- if ($this->m_bDeleteEnabled)
|
|
|
- {
|
|
|
- $oPage->add_ready_script('$(".attachment").hover( function() {$(this).children(":button").toggleClass("btn_hidden"); } );');
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- $oPage->add('<span id="attachments">');
|
|
|
- while ($oAttachment = $oSet->Fetch())
|
|
|
- {
|
|
|
- $iAttId = $oAttachment->GetKey();
|
|
|
- $oDoc = $oAttachment->Get('contents');
|
|
|
- $sFileName = $oDoc->GetFileName();
|
|
|
- $sIcon = utils::GetAbsoluteUrlAppRoot().AttachmentPlugIn::GetFileIcon($sFileName);
|
|
|
- $sDownloadLink = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php/?operation=download_document&class=Attachment&id='.$iAttId.'&field=contents';
|
|
|
- $oPage->add('<div class="attachment" id="attachment_'.$iAttId.'"><a href="'.$sDownloadLink.'"><img src="'.$sIcon.'"><br/>'.$sFileName.'</a><input type="hidden" name="attachments[]" value="'.$iAttId.'"/><br/> </div>');
|
|
|
- }
|
|
|
+ $this->DisplayAttachments($oObject, $oPage, $bEditMode);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -347,7 +212,7 @@ EOF
|
|
|
|
|
|
protected function IsTargetObject($oObject)
|
|
|
{
|
|
|
- $aAllowedClasses = MetaModel::GetModuleSetting('attachments', 'allowed_classes', array('Ticket'));
|
|
|
+ $aAllowedClasses = MetaModel::GetModuleSetting('itop-attachments', 'allowed_classes', array('Ticket'));
|
|
|
foreach($aAllowedClasses as $sAllowedClass)
|
|
|
{
|
|
|
if ($oObject instanceof $sAllowedClass)
|
|
@@ -358,6 +223,11 @@ EOF
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ protected function GetAttachmentsPosition()
|
|
|
+ {
|
|
|
+ return MetaModel::GetModuleSetting('itop-attachments', 'position', 'relations');
|
|
|
+ }
|
|
|
+
|
|
|
var $m_bDeleteEnabled = true;
|
|
|
|
|
|
public function EnableDelete($bEnabled)
|
|
@@ -365,6 +235,154 @@ EOF
|
|
|
$this->m_bDeleteEnabled = $bEnabled;
|
|
|
}
|
|
|
|
|
|
+ public function DisplayAttachments($oObject, WebPage $oPage, $bEditMode = false)
|
|
|
+ {
|
|
|
+ // Exit here if the class is not allowed
|
|
|
+ if (!$this->IsTargetObject($oObject)) return;
|
|
|
+
|
|
|
+ $oSearch = DBObjectSearch::FromOQL("SELECT Attachment WHERE item_class = :class AND item_id = :item_id");
|
|
|
+ $oSet = new DBObjectSet($oSearch, array(), array('class' => get_class($oObject), 'item_id' => $oObject->GetKey()));
|
|
|
+ if ($this->GetAttachmentsPosition() == 'relations')
|
|
|
+ {
|
|
|
+ $sTitle = ($oSet->Count() > 0)? Dict::Format('Attachments:TabTitle_Count', $oSet->Count()) : Dict::S('Attachments:EmptyTabTitle');
|
|
|
+ $oPage->SetCurrentTab($sTitle);
|
|
|
+ }
|
|
|
+ $oPage->add_style(
|
|
|
+<<<EOF
|
|
|
+.attachment {
|
|
|
+ display: inline-block;
|
|
|
+ text-align:center;
|
|
|
+ float:left;
|
|
|
+ padding:5px;
|
|
|
+}
|
|
|
+.attachment:hover {
|
|
|
+ background-color: #e0e0e0;
|
|
|
+}
|
|
|
+.attachment img {
|
|
|
+ border: 0;
|
|
|
+}
|
|
|
+.attachment a {
|
|
|
+ text-decoration: none;
|
|
|
+ color: #1C94C4;
|
|
|
+}
|
|
|
+.btn_hidden {
|
|
|
+ display: none;
|
|
|
+}
|
|
|
+EOF
|
|
|
+ );
|
|
|
+ $oPage->add('<fieldset>');
|
|
|
+ $oPage->add('<legend>'.Dict::S('Attachments:FieldsetTitle').'</legend>');
|
|
|
+
|
|
|
+ if ($bEditMode)
|
|
|
+ {
|
|
|
+ $sIsDeleteEnabled = $this->m_bDeleteEnabled ? 'true' : 'false';
|
|
|
+ $iTransactionId = $oPage->GetTransactionId();
|
|
|
+ $oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'modules/itop-attachments/ajaxfileupload.js');
|
|
|
+ $sClass = get_class($oObject);
|
|
|
+ $sTempId = session_id().'_'.$iTransactionId;
|
|
|
+ $sDeleteBtn = Dict::S('Attachments:DeleteBtn');
|
|
|
+ $oPage->add_script(
|
|
|
+<<<EOF
|
|
|
+ function RemoveNewAttachment(att_id)
|
|
|
+ {
|
|
|
+ $('#attachment_'+att_id).attr('name', 'removed_attachments[]');
|
|
|
+ $('#display_attachment_'+att_id).hide();
|
|
|
+ return false; // Do not submit the form !
|
|
|
+ }
|
|
|
+ function ajaxFileUpload()
|
|
|
+ {
|
|
|
+ //starting setting some animation when the ajax starts and completes
|
|
|
+ $("#loading").ajaxStart(function(){
|
|
|
+ $(this).show();
|
|
|
+ }).ajaxComplete(function(){
|
|
|
+ $(this).hide();
|
|
|
+ });
|
|
|
+
|
|
|
+ /*
|
|
|
+ prepareing ajax file upload
|
|
|
+ url: the url of script file handling the uploaded files
|
|
|
+ fileElementId: the file type of input element id and it will be the index of $_FILES Array()
|
|
|
+ dataType: it support json, xml
|
|
|
+ secureuri:use secure protocol
|
|
|
+ success: call back function when the ajax complete
|
|
|
+ error: callback function when the ajax failed
|
|
|
+
|
|
|
+ */
|
|
|
+ $.ajaxFileUpload
|
|
|
+ (
|
|
|
+ {
|
|
|
+ url: GetAbsoluteUrlAppRoot()+'modules/itop-attachments/ajax.attachment.php?obj_class={$sClass}&temp_id={$sTempId}&operation=add',
|
|
|
+ secureuri:false,
|
|
|
+ fileElementId:'file',
|
|
|
+ dataType: 'json',
|
|
|
+ success: function (data, status)
|
|
|
+ {
|
|
|
+ if(typeof(data.error) != 'undefined')
|
|
|
+ {
|
|
|
+ if(data.error != '')
|
|
|
+ {
|
|
|
+ alert(data.error);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var sDownloadLink = GetAbsoluteUrlAppRoot()+'pages/ajax.render.php/?operation=download_document&class=Attachment&id='+data.att_id+'&field=contents';
|
|
|
+ $('#attachments').append('<div class="attachment" id="display_attachment_'+data.att_id+'"><a href="'+sDownloadLink+'"><img src="'+data.icon+'"><br/>'+data.msg+'<input id="attachment_'+data.att_id+'" type="hidden" name="attachments[]" value="'+data.att_id+'"/></a><br/><input type="button" class="btn_hidden" value="{$sDeleteBtn}" onClick="RemoveNewAttachment('+data.att_id+');"/></div>');
|
|
|
+ if($sIsDeleteEnabled)
|
|
|
+ {
|
|
|
+ $('#display_attachment_'+data.att_id).hover( function() { $(this).children(':button').toggleClass('btn_hidden'); } );
|
|
|
+ }
|
|
|
+ //alert(data.msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: function (data, status, e)
|
|
|
+ {
|
|
|
+ alert(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ return false;
|
|
|
+
|
|
|
+ }
|
|
|
+EOF
|
|
|
+);
|
|
|
+ $oPage->add('<span id="attachments">');
|
|
|
+ while ($oAttachment = $oSet->Fetch())
|
|
|
+ {
|
|
|
+ $iAttId = $oAttachment->GetKey();
|
|
|
+ $oDoc = $oAttachment->Get('contents');
|
|
|
+ $sFileName = $oDoc->GetFileName();
|
|
|
+ $sIcon = utils::GetAbsoluteUrlAppRoot().AttachmentPlugIn::GetFileIcon($sFileName);
|
|
|
+ $sDownloadLink = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php/?operation=download_document&class=Attachment&id='.$iAttId.'&field=contents';
|
|
|
+ $oPage->add('<div class="attachment" id="attachment_'.$iAttId.'"><a href="'.$sDownloadLink.'"><img src="'.$sIcon.'"><br/>'.$sFileName.'<input type="hidden" name="attachments[]" value="'.$iAttId.'"/></a><br/> <input id="btn_remove_'.$iAttId.'" type="button" class="btn_hidden" value="Delete" onClick="$(\'#attachment_'.$iAttId.'\').remove();"/> </div>');
|
|
|
+ }
|
|
|
+ $oPage->add('</span>');
|
|
|
+ $oPage->add('<div style="clear:both"></div>');
|
|
|
+ $sMaxUpload = $this->GetMaxUpload();
|
|
|
+ $oPage->p(Dict::S('Attachments:AddAttachment').'<input type="file" name="file" id="file" onChange="ajaxFileUpload();"><span style="display:none;" id="loading"> <img src="../images/indicator.gif"></span> '.$sMaxUpload);
|
|
|
+ //$oPage->p('<input type="button" onClick="ajaxFileUpload();" value=" Upload !">');
|
|
|
+ $oPage->p('<span style="display:none;" id="loading">Loading, please wait...</span>');
|
|
|
+ $oPage->add('</fieldset>');
|
|
|
+ if ($this->m_bDeleteEnabled)
|
|
|
+ {
|
|
|
+ $oPage->add_ready_script('$(".attachment").hover( function() {$(this).children(":button").toggleClass("btn_hidden"); } );');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $oPage->add('<span id="attachments">');
|
|
|
+ while ($oAttachment = $oSet->Fetch())
|
|
|
+ {
|
|
|
+ $iAttId = $oAttachment->GetKey();
|
|
|
+ $oDoc = $oAttachment->Get('contents');
|
|
|
+ $sFileName = $oDoc->GetFileName();
|
|
|
+ $sIcon = utils::GetAbsoluteUrlAppRoot().AttachmentPlugIn::GetFileIcon($sFileName);
|
|
|
+ $sDownloadLink = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php/?operation=download_document&class=Attachment&id='.$iAttId.'&field=contents';
|
|
|
+ $oPage->add('<div class="attachment" id="attachment_'.$iAttId.'"><a href="'.$sDownloadLink.'"><img src="'.$sIcon.'"><br/>'.$sFileName.'</a><input type="hidden" name="attachments[]" value="'.$iAttId.'"/><br/> </div>');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
protected static function UpdateAttachments($oObject, $oChange = null)
|
|
|
{
|