Inline images in formatted case log & descriptions: beta version fixperms js The inline images are now no longer stored stored as Attachments but using a specific object InlineImage...

SVN:trunk[3926]
This commit is contained in:
Denis Flaven
2016-02-25 15:06:04 +00:00
parent 9c16b08e22
commit 608e94a613
107 changed files with 4676 additions and 196 deletions

View File

@@ -2216,6 +2216,8 @@ EOF
$sJsonFieldsMap = json_encode($aFieldsMap);
$sState = $this->GetState();
$sSessionStorageKey = $sClass.'_'.$iKey;
$sTempId = session_id().'_'.$iTransactionId;
$oPage->add_ready_script(InlineImage::EnableCKEditorImageUpload($this, $sTempId));
$oPage->add_script(
<<<EOF
@@ -3129,6 +3131,10 @@ EOF
$aFinalValues[$sAttCode] = $aValues[$sAttCode];
}
$this->UpdateObjectFromArray($aFinalValues);
if (!$this->IsNew()) // for new objects this is performed in DBInsertNoReload()
{
InlineImage::FinalizeInlineImages($this);
}
// Invoke extensions after the update of the object from the form
foreach (MetaModel::EnumPlugins('iApplicationUIExtension') as $oExtensionInstance)
@@ -3172,6 +3178,8 @@ EOF
{
$res = parent::DBInsertNoReload();
InlineImage::FinalizeInlineImages($this);
// Invoke extensions after insertion (the object must exist, have an id, etc.)
foreach (MetaModel::EnumPlugins('iApplicationObjectExtension') as $oExtensionInstance)
{

View File

@@ -1290,22 +1290,13 @@ class HistoryBlock extends DisplayBlock
{
$sHtml .= $this->GetHistoryTable($oPage, $oSet);
}
$sMaxWidth = MetaModel::GetModuleSetting('itop-attachment', 'inline_image_max_width', '450px');
$oPage->add_ready_script(InlineImage::FixImagesWidth());
$oPage->add_ready_script("$('.case-log-history-entry-toggle').on('click', function () { $(this).closest('.case-log-history-entry').toggleClass('expanded');});");
$oPage->add_ready_script(
<<<EOF
$('.history_entry').each(function() {
var jMe = $(this)
jMe.find('img[data-att-id]').each(function() {
if ('$sMaxWidth' != '')
{
$(this).css({'max-width': '$sMaxWidth', width: '', height: '', 'max-height': ''});
}
$(this).addClass('inline-image');
$(this).attr('href', $(this).attr('src'));
}).magnificPopup({type: 'image', closeOnContentClick: true });
var jMe = $(this);
var oContent = $(this).find('.history_html_content');
if (jMe.height() < oContent.height())
{
@@ -1345,7 +1336,7 @@ EOF
}
$aAttribs = array('date' => array('label' => Dict::S('UI:History:Date'), 'description' => Dict::S('UI:History:Date+')),
'userinfo' => array('label' => Dict::S('UI:History:User'), 'description' => Dict::S('UI:History:User+')),
'log' => array('label' => Dict::S('UI:History:Changes').'<span style="display:block;float:right">Expand All / Collapse All</span>', 'description' => Dict::S('UI:History:Changes+')),
'log' => array('label' => Dict::S('UI:History:Changes') , 'description' => Dict::S('UI:History:Changes+')),
);
$aValues = array();
foreach($aChanges as $aChange)

View File

@@ -54,6 +54,8 @@ class iTopWebPage extends NiceWebPage implements iTabbedPage
$this->add_linked_stylesheet("../css/jquery.autocomplete.css");
$this->add_linked_stylesheet("../css/fg.menu.css");
$this->add_linked_stylesheet("../css/jquery.multiselect.css");
$this->add_linked_stylesheet("../css/magnific-popup.css");
$this->add_linked_script('../js/jquery.layout.min.js');
$this->add_linked_script('../js/jquery.ba-bbq.min.js');
$this->add_linked_script("../js/jquery.treeview.js");
@@ -76,6 +78,8 @@ class iTopWebPage extends NiceWebPage implements iTabbedPage
$this->add_linked_script('../js/jquery.multiselect.js');
$this->add_linked_script('../js/ajaxfileupload.js');
$this->add_linked_script('../js/jquery.mousewheel.js');
$this->add_linked_script('../js/jquery.magnific-popup.min.js');
$sSearchAny = addslashes(Dict::S('UI:SearchValue:Any'));
$sSearchNbSelected = addslashes(Dict::S('UI:SearchValue:NbSelected'));
@@ -436,9 +440,9 @@ EOF
});
}
});
EOF
);
$this->add_ready_script(InlineImage::FixImagesWidth());
$sUserPrefs = appUserPreferences::GetAsJSON();
$this->add_script(
<<<EOF
@@ -513,7 +517,7 @@ EOF
}
EOF
);
}
}
public function AddToMenu($sHtml)
{

View File

@@ -34,7 +34,6 @@ define('ITOP_CONFIG_FILE', 'config-itop.php');
define('ITOP_DEFAULT_CONFIG_FILE', APPCONF.ITOP_DEFAULT_ENV.'/'.ITOP_CONFIG_FILE);
define('SERVER_NAME_PLACEHOLDER', '$SERVER_NAME$');
define('ATTACHMENT_DOWNLOAD_URL', 'pages/ajax.render.php?operation=download_document&class=Attachment&field=contents&id=');
class FileUploadException extends Exception
{
@@ -1169,34 +1168,4 @@ class utils
$sText = str_replace("\r", "\n", $sText);
return str_replace("\n", '</br>', htmlentities($sText, ENT_QUOTES, 'UTF-8'));
}
/**
* Parses the supplied HTML fragment to rebuild the attribute src="" for images
* that refer to an attachment (detected via the attribute data-att-id="") so that
* the URL is consistent with the current URL of the application.
* @param string $sHtml The HTML fragment to process
* @return string The modified HTML
*/
public static function FixInlineAttachments($sHtml)
{
$aNeedles = array();
$aReplacements = array();
// Find img tags with an attribute data-att-id
if (preg_match_all('/<img ([^>]*)data-att-id="([0-9]+)"([^>]*)>/i', $sHtml, $aMatches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE))
{
$sUrl = utils::GetAbsoluteUrlAppRoot().ATTACHMENT_DOWNLOAD_URL;
foreach($aMatches as $aImgInfo)
{
$sImgTag = $aImgInfo[0][0];
$sAttId = $aImgInfo[2][0];
$sNewImgTag = preg_replace('/src="[^"]+"/', 'src="'.$sUrl.$sAttId.'"', $sImgTag); // preserve other attributes
$aNeedles[] = $sImgTag;
$aReplacements[] = $sNewImgTag;
}
$sHtml = str_replace($aNeedles, $aReplacements, $sHtml);
}
return $sHtml;
}
}