New data model integration...

Enhanced the display of blob attributes

SVN:trunk[502]
This commit is contained in:
Denis Flaven
2010-06-29 09:22:22 +00:00
parent 464479a6b2
commit 90069f6826
7 changed files with 140 additions and 138 deletions

View File

@@ -930,6 +930,7 @@ abstract class cmdbAbstractObject extends CMDBObject
case 'List':
// Not editable for now...
$sHTMLValue = '';
break;
case 'String':
@@ -963,7 +964,15 @@ abstract class cmdbAbstractObject extends CMDBObject
$sHTMLValue .= "<option value=\"0\">".Dict::S('UI:SelectOne')."</option>\n";
foreach($aAllowedValues as $key => $display_value)
{
if (count($aAllowedValues) == 1)
{
// When there is only once choice, select it by default
$sSelected = ' selected';
}
else
{
$sSelected = ($value == $key) ? ' selected' : '';
}
$sHTMLValue .= "<option value=\"$key\"$sSelected>$display_value</option>\n";
}
$sHTMLValue .= "</select>&nbsp;{$sValidationField}\n";
@@ -1380,6 +1389,13 @@ EOF
// Special display for the 'state' attribute itself
$sDisplayValue = $this->GetStateLabel();
}
else if ($oAttDef->GetEditClass() == 'Document')
{
$oDocument = $this->Get($sAttCode);
$sDisplayValue = $this->GetAsHTML($sAttCode);
$sDisplayValue .= "<br/>".Dict::Format('UI:OpenDocumentInNewWindow_', $oDocument->GetDisplayLink(get_class($this), $this->GetKey(), $sAttCode)).", \n";
$sDisplayValue .= "<br/>".Dict::Format('UI:DownloadDocument_', $oDocument->GetDisplayLink(get_class($this), $this->GetKey(), $sAttCode)).", \n";
}
else
{
$sDisplayValue = $this->GetAsHTML($sAttCode);
@@ -1389,5 +1405,51 @@ EOF
return $retVal;
}
/**
* Displays a blob document *inline* (if possible, depending on the type of the document)
* @return string
*/
public function DisplayDocumentInline(WebPage $oPage, $sAttCode)
{
$oDoc = $this->Get($sAttCode);
$sClass = get_class($this);
$Id = $this->GetKey();
switch ($oDoc->GetMainMimeType())
{
case 'text':
case 'html':
$data = $oDoc->GetData();
switch($oDoc->GetMimeType())
{
case 'text/html':
case 'text/xml':
$oPage->add("<iframe id='preview_$sAttCode' src=\"../pages/ajax.render.php?operation=display_document&class=$sClass&id=$Id&field=$sAttCode\" width=\"100%\" height=\"400\">Loading...</iframe>\n");
default:
$oPage->add("<pre>".htmlentities(MyHelpers::beautifulstr($data, 1000, true))."</pre>\n");
}
break;
case 'application':
switch($oDoc->GetMimeType())
{
case 'application/pdf':
$oPage->add("<iframe id='preview_$sAttCode' src=\"../pages/ajax.render.php?operation=display_document&class=$sClass&id=$Id&field=$sAttCode\" width=\"100%\" height=\"400\">Loading...</iframe>\n");
break;
default:
$oPage->add(Dict::S('UI:Document:NoPreview'));
}
break;
case 'image':
$oPage->add("<img src=\"../pages/ajax.render.php?operation=display_document&class=$sClass&id=$Id&field=$sAttCode\" />\n");
break;
default:
$oPage->add(Dict::S('UI:Document:NoPreview'));
}
}
}
?>

View File

@@ -304,6 +304,19 @@ class FileDoc extends Document
MetaModel::Init_SetZListItems('standard_search', array('name', 'description', 'type', 'status'));
MetaModel::Init_SetZListItems('list', array('type', 'status', 'contents'));
}
/**
* Overload the display of the properties to add a tab (the first one)
* with the preview of the document
*/
public function DisplayBareProperties(WebPage $oPage)
{
$oPage->SetCurrentTab(Dict::S('Class:Document:PreviewTab'));
$oPage->add($this->DisplayDocumentInline($oPage, 'contents'));
$oPage->SetCurrentTab(Dict::S('UI:PropertiesTab'));
parent::DisplayBareProperties($oPage);
}
}
class Licence extends cmdbAbstractObject
{

View File

@@ -310,9 +310,8 @@ class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute
$sAttName = $oAttDef->GetLabel();
$oPrevDoc = $this->Get('prevdata');
$sDocView = $oPrevDoc->GetAsHtml();
$sDocView .= "<br/>Open in New Window: ".$oPrevDoc->GetDisplayLink(get_class($this), $this->GetKey(), 'prevdata').", \n";
$sDocView .= "Download: ".$oPrevDoc->GetDownloadLink(get_class($this), $this->GetKey(), 'prevdata')."\n";
$sDocView .= "<br/>".Dict::Format('UI:OpenDocumentInNewWindow_',$oPrevDoc->GetDisplayLink(get_class($this), $this->GetKey(), 'prevdata')).", \n";
$sDocView .= Dict::Format('UI:DownloadDocument_', $oPrevDoc->GetDownloadLink(get_class($this), $this->GetKey(), 'prevdata'))."\n";
//$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
$sResult = "$sAttName changed, previous value: $sDocView";
}

View File

@@ -94,46 +94,11 @@ class ormDocument
else
{
$data = $this->GetData();
$sResult = $this->GetFileName().' [ '.$this->GetMimeType().', size: '.strlen($data).' byte(s) ]';
$sResult = $this->GetFileName().' [ '.$this->GetMimeType().', size: '.strlen($data).' byte(s) ]<br/>';
}
return $sResult;
}
/**
* Returns an HTML fragment that will display the document *inline* (if possible)
* @return string
*/
public function GetDisplayInline($sClass, $Id, $sAttCode)
{
switch ($this->GetMainMimeType())
{
case 'text':
case 'html':
$data = $this->GetData();
switch($this->GetMimeType())
{
case 'text/html':
case 'text/xml':
return "<iframe src=\"../pages/ajax.render.php?operation=display_document&class=$sClass&id=$Id&field=$sAttCode\" width=\"100%\" height=\"400\">Loading...</iframe>\n";
default:
return "<pre>".htmlentities(MyHelpers::beautifulstr($data, 1000, true))."</pre>\n";
}
break; // Not really needed, but...
case 'application':
switch($this->GetMimeType())
{
case 'application/pdf':
return "<iframe src=\"../pages/ajax.render.php?operation=display_document&class=$sClass&id=$Id&field=$sAttCode\" width=\"100%\" height=\"400\">Loading...</iframe>\n";
}
break;
case 'image':
return "<img src=\"../pages/ajax.render.php?operation=display_document&class=$sClass&id=$Id&field=$sAttCode\" />\n";
}
}
/**
* Returns an hyperlink to display the document *inline*
* @return string

View File

@@ -217,6 +217,7 @@ Dict::Add('EN US', 'English', 'English', array(
'Class:Document/Attribute:contract_list+' => 'Contracts refering to this document',
'Class:Document/Attribute:ticket_list' => 'Tickets',
'Class:Document/Attribute:ticket_list+' => 'Tickets refering to this document',
'Class:Document:PreviewTab' => 'Preview',
));
//

View File

@@ -881,6 +881,10 @@ When associated with a trigger, each action is given an "order" number, specifyi
'UI:iTopVersion:Short' => 'iTop version %1$s',
'UI:iTopVersion:Long' => 'iTop version %1$s-%2$s built on %3$s',
'UI:PropertiesTab' => 'Properties',
'UI:OpenDocumentInNewWindow_' => 'Open this document in a new window: %1$s',
'UI:DownloadDocument_' => 'Download this document: %1$s',
'UI:Document:NoPreview' => 'No preview is available for this type of document',
));

View File

@@ -350,6 +350,57 @@ function DeleteObjects(WebPage $oP, $sClass, $aObjects, $bDeleteConfirmed)
}
/**
* Updates an object from the POSTed parameters
*/
function UpdateObject(&$oObj)
{
foreach(MetaModel::ListAttributeDefs(get_class($oObj)) as $sAttCode=>$oAttDef)
{
if ($oAttDef->IsLinkSet())
{
// Link set, the data is a set of link objects, encoded in JSON
$aAttributes[$sAttCode] = trim(utils::ReadPostedParam("attr_$sAttCode", ''));
if (!empty($aAttributes[$sAttCode]))
{
$oLinkSet = WizardHelper::ParseJsonSet($oObj, $oAttDef->GetLinkedClass(), $oAttDef->GetExtKeyToMe(), $aAttributes[$sAttCode]);
$oObj->Set($sAttCode, $oLinkSet);
// TO DO: detect a real modification, for now always update !!
}
}
else if ($oAttDef->IsWritable())
{
$iFlags = $oObj->GetAttributeFlags($sAttCode);
if ($iFlags & (OPT_ATT_HIDDEN | OPT_ATT_READONLY))
{
// Non-visible, or read-only attribute, do nothing
}
else if ($oAttDef->GetEditClass() == 'Document')
{
// There should be an uploaded file with the named attr_<attCode>
$oDocument = utils::ReadPostedDocument('file_'.$sAttCode);
if (!$oDocument->IsEmpty())
{
// A new file has been uploaded
$oObj->Set($sAttCode, $oDocument);
}
}
else
{
$rawValue = utils::ReadPostedParam("attr_$sAttCode", null);
if (!is_null($rawValue))
{
$aAttributes[$sAttCode] = trim($rawValue);
$previousValue = $oObj->Get($sAttCode);
if ($previousValue !== $aAttributes[$sAttCode])
{
$oObj->Set($sAttCode, $aAttributes[$sAttCode]);
}
}
}
}
}
}
/***********************************************************************************
*
* Main user interface page, starts here
@@ -715,51 +766,9 @@ try
{
$oP->set_title(Dict::Format('UI:ModificationPageTitle_Object_Class', $oObj->GetName(), $sClassLabel));
$oP->add("<h1>".Dict::Format('UI:ModificationTitle_Class_Object', $sClassLabel, $oObj->GetName())."</h1>\n");
foreach(MetaModel::ListAttributeDefs(get_class($oObj)) as $sAttCode=>$oAttDef)
{
if ($oAttDef->IsLinkSet())
{
// Link set, the data is a set of link objects, encoded in JSON
$aAttributes[$sAttCode] = trim(utils::ReadPostedParam("attr_$sAttCode", ''));
if (!empty($aAttributes[$sAttCode]))
{
$oLinkSet = WizardHelper::ParseJsonSet($oObj, $oAttDef->GetLinkedClass(), $oAttDef->GetExtKeyToMe(), $aAttributes[$sAttCode]);
$oObj->Set($sAttCode, $oLinkSet);
// TO DO: detect a real modification, for now always update !!
}
}
else if (!$oAttDef->IsExternalField())
{
$rawValue = utils::ReadPostedParam("attr_$sAttCode", null);
if (!is_null($rawValue))
{
$aAttributes[$sAttCode] = trim($rawValue);
$previousValue = $oObj->Get($sAttCode);
if ($previousValue !== $aAttributes[$sAttCode])
{
$oObj->Set($sAttCode, $aAttributes[$sAttCode]);
}
}
}
else if ($oAttDef->IsWritable())
{
$iFlags = $oObj->GetAttributeFlags($sAttCode);
if ($iFlags & (OPT_ATT_HIDDEN | OPT_ATT_READONLY))
{
// Non-visible, or read-only attribute, do nothing
}
else if ($oAttDef->GetEditClass() == 'Document')
{
// There should be an uploaded file with the named attr_<attCode>
$oDocument = utils::ReadPostedDocument('file_'.$sAttCode);
if (!$oDocument->IsEmpty())
{
// A new file has been uploaded
$oObj->Set($sAttCode, $oDocument);
}
}
}
}
UpdateObject($oObj);
if (!$oObj->IsModified())
{
$oP->p(Dict::Format('UI:Class_Object_NotUpdated', MetaModel::GetName(get_class($oObj)), $oObj->GetName()));
@@ -884,14 +893,7 @@ try
$oMyChange->Set("userinfo", $sUserString);
$iChangeId = $oMyChange->DBInsert();
$sStateAttCode = MetaModel::GetStateAttributeCode(get_class($oObj));
foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode=>$oAttDef)
{
if ( ($oAttDef->IsWritable()) )
{
$value = utils::ReadPostedParam('attr_'.$sAttCode, '');
$oObj->Set($sAttCode, $value);
}
}
UpdateObject($oObj);
$oObj->DBCloneTracked($oMyChange);
$oP->set_title(Dict::S('UI:PageTitle:ObjectCreated'));
$oP->add("<h1>".Dict::Format('UI:Title:Object_Of_Class_Created', $oObj->GetName(), $sClassLabel)."</h1>\n");
@@ -915,51 +917,7 @@ try
else
{
$oObj = MetaModel::NewObject($sClass);
foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
{
if ($oAttDef->IsLinkSet())
{
// Link set, the data is a set of link objects, encoded in JSON
$aAttributes[$sAttCode] = trim(utils::ReadPostedParam("attr_$sAttCode", ''));
if (!empty($aAttributes[$sAttCode]))
{
$oLinkSet = WizardHelper::ParseJsonSet($oObj, $oAttDef->GetLinkedClass(), $oAttDef->GetExtKeyToMe(), $aAttributes[$sAttCode]);
$oObj->Set($sAttCode, $oLinkSet);
// TO DO: detect a real modification, for now always update !!
}
}
else if (!$oAttDef->IsExternalField())
{
$rawValue = utils::ReadPostedParam("attr_$sAttCode", null);
if (!is_null($rawValue))
{
$aAttributes[$sAttCode] = trim($rawValue);
$previousValue = $oObj->Get($sAttCode);
if ($previousValue !== $aAttributes[$sAttCode])
{
$oObj->Set($sAttCode, $aAttributes[$sAttCode]);
}
}
}
else if ($oAttDef->IsWritable())
{
$iFlags = $oObj->GetAttributeFlags($sAttCode);
if ($iFlags & (OPT_ATT_HIDDEN | OPT_ATT_READONLY))
{
// Non-visible, or read-only attribute, do nothing
}
else if ($oAttDef->GetEditClass() == 'Document')
{
// There should be an uploaded file with the named attr_<attCode>
$oDocument = utils::ReadPostedDocument('file_'.$sAttCode);
if (!$oDocument->IsEmpty())
{
// A new file has been uploaded
$oObj->Set($sAttCode, $oDocument);
}
}
}
}
UpdateObject($oObj);
}
if (isset($oObj) && is_object($oObj))
{