Merge pull request #1960 from jygaulier/PHRAS-1192_quarantaine-by-filenames_4.0

PHRAS-1192_quarantaine-by-filenames_4.0
This commit is contained in:
Thibaud Fabre
2016-09-29 14:11:08 +02:00
committed by GitHub
17 changed files with 278 additions and 105 deletions

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Border\Checker;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Border\File; use Alchemy\Phrasea\Border\File;
use Alchemy\Phrasea\Model\Entities\LazaretFile;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Translation\TranslatorInterface;
@@ -51,6 +52,26 @@ class Filename extends AbstractChecker
return new Response($boolean, $this); return new Response($boolean, $this);
} }
/**
* @param Application $app
* @param LazaretFile $file
* @return \record_adapter[]
*/
public static function listConflicts(Application $app, LazaretFile $file)
{
return \record_adapter::get_records_by_originalname(
$file->getCollection($app)->get_databox(), $file->getOriginalName(), false, 0, 1000
);
}
/**
* {@inheritdoc}
*/
public static function getReason(TranslatorInterface $translator)
{
return $translator->trans('same filename');
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Border\Checker;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Border\File; use Alchemy\Phrasea\Border\File;
use Alchemy\Phrasea\Model\Entities\LazaretFile;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Translation\TranslatorInterface;
@@ -38,6 +39,26 @@ class Sha256 extends AbstractChecker
return new Response($boolean, $this); return new Response($boolean, $this);
} }
/**
* @param Application $app
* @param LazaretFile $file
* @return \record_adapter[]
*/
public static function listConflicts(Application $app, LazaretFile $file)
{
$databox = $file->getCollection($app)->get_databox();
return $databox->getRecordRepository()->findBySha256($file->getSha256());
}
/**
* {@inheritdoc}
*/
public static function getReason(TranslatorInterface $translator)
{
return $translator->trans('same checksum');
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Border\Checker;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Border\File; use Alchemy\Phrasea\Border\File;
use Alchemy\Phrasea\Model\Entities\LazaretFile;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Translation\TranslatorInterface;
@@ -37,6 +38,26 @@ class UUID extends AbstractChecker
return new Response($boolean, $this); return new Response($boolean, $this);
} }
/**
* @param Application $app
* @param LazaretFile $file
* @return \record_adapter[]
*/
public static function listConflicts(Application $app, LazaretFile $file)
{
$databox = $file->getCollection($app)->get_databox();
return $databox->getRecordRepository()->findByUuid($file->getUUID());
}
/**
* {@inheritdoc}
*/
public static function getReason(TranslatorInterface $translator)
{
return $translator->trans('same UUID');
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@@ -105,7 +105,7 @@ class RecordController extends Controller
'record' => $record, 'record' => $record,
]), ]),
"pos" => $record->getNumber(), "pos" => $record->getNumber(),
"title" => str_replace(array('[[em]]', '[[/em]]'), array('<em>', '</em>'), $record->get_title($query, $searchEngine)), "title" => $record->get_title(),
"databox_name" => $record->getDatabox()->get_dbname(), "databox_name" => $record->getDatabox()->get_dbname(),
"collection_name" => $record->getCollection()->get_name(), "collection_name" => $record->getCollection()->get_name(),
"collection_logo" => $record->getCollection()->getLogo($record->getBaseId(), $this->app), "collection_logo" => $record->getCollection()->getLogo($record->getBaseId(), $this->app),

View File

@@ -10,7 +10,9 @@
namespace Alchemy\Phrasea\Model\Entities; namespace Alchemy\Phrasea\Model\Entities;
use Alchemy\Phrasea\Application;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Translation\TranslatorInterface;
/** /**
* @ORM\Table(name="LazaretChecks") * @ORM\Table(name="LazaretChecks")
@@ -91,4 +93,33 @@ class LazaretCheck
{ {
return $this->lazaretFile; return $this->lazaretFile;
} }
/**
* @param TranslatorInterface $translator
* @return string the reason why a record is in lazaret
*/
public function getReason(TranslatorInterface $translator)
{
$className = $this->getCheckClassname();
if (method_exists($className, "getReason")) {
return $className::getReason($translator);
} else {
return '';
}
}
/**
* @param Application $app
* @return \record_adapter[] the records conflicting with this check
*/
public function listConflicts(Application $app)
{
$className = $this->getCheckClassname();
if (method_exists($className, "listConflicts")) {
return $className::listConflicts($app, $this->lazaretFile);
} else {
return [];
}
}
} }

View File

@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\Model\Entities;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo; use Gedmo\Mapping\Annotation as Gedmo;
use \record_adapter;
/** /**
* @ORM\Table(name="LazaretFiles") * @ORM\Table(name="LazaretFiles")
@@ -421,24 +422,32 @@ class LazaretFile
/** /**
* Get an array of records that can be substitued by the Lazaret file * Get an array of records that can be substitued by the Lazaret file
* *
* @return \record_adapter[] * @return record_adapter[]
*/ */
public function getRecordsToSubstitute(Application $app) public function getRecordsToSubstitute(Application $app, $includeReason = false)
{ {
$ret = []; $merged = [];
/** @var LazaretCheck $check */
$repository = $this->getCollection($app)->get_databox()->getRecordRepository(); foreach($this->getChecks() as $check) {
$shaRecords = $repository->findBySha256($this->getSha256()); /** @var record_adapter $record */
$uuidRecords = $repository->findByUuid($this->getUuid()); $conflicts = $check->listConflicts($app);
foreach ($conflicts as $record) {
$merged = array_merge($uuidRecords, $shaRecords); if($includeReason) {
if (!array_key_exists($record->getRecordId(), $merged)) {
foreach ($merged as $record) { $merged[$record->getRecordId()] = [
if ( ! in_array($record, $ret)) { 'record' => $record,
$ret[] = $record; 'reasons' => []
];
}
$merged[$record->getRecordId()]['reasons'][] = $check->getReason($app['translator']);
}
else {
$merged[$record->getRecordId()] = $record;
}
} }
} }
return $ret; return $merged;
} }
} }

View File

@@ -32,6 +32,8 @@ class PhraseanetExtension extends \Twig_Extension
return array( return array(
new \Twig_SimpleFunction('user_setting', array($this, 'getUserSetting')), new \Twig_SimpleFunction('user_setting', array($this, 'getUserSetting')),
new \Twig_SimpleFunction('record_thumbnail_url', array($this, 'getThumbnailUrl')), new \Twig_SimpleFunction('record_thumbnail_url', array($this, 'getThumbnailUrl')),
new \Twig_SimpleFunction('record_subdef_url', array($this, 'getSubdefUrl')),
new \Twig_SimpleFunction('record_subdef_size', array($this, 'getSubdefSize')),
new \Twig_SimpleFunction('record_doctype_icon', array($this, 'getDoctypeIcon'), array( new \Twig_SimpleFunction('record_doctype_icon', array($this, 'getDoctypeIcon'), array(
'is_safe' => array('html') 'is_safe' => array('html')
)), )),
@@ -292,6 +294,33 @@ class PhraseanetExtension extends \Twig_Extension
return $path; return $path;
} }
public function getSubdefSize(RecordInterface $record, $subdefName)
{
$ret = null;
if ($record instanceof ElasticsearchRecord) {
$subdefs = $record->getSubdefs();
if (isset($subdefs[$subdefName])) {
$subdef = $subdefs[$subdefName];
if (isset($subdef['width']) && $subdef['width'] !== null && isset($subdef['height']) && $subdef['height'] !== null) {
$ret = [
'width' => $subdef['width'],
'height' => $subdef['height']
];
}
}
} elseif ($record instanceof \record_adapter) {
if (null !== $subdef = $record->get_subdef($subdefName)) {
$ret = [
'width' => $subdef->get_width(),
'height' => $subdef->get_height()
];
}
}
return $ret;
}
public function getUserSetting($setting, $default = null) public function getUserSetting($setting, $default = null)
{ {
if (false === ($this->app->getAuthenticatedUser() instanceof User)) { if (false === ($this->app->getAuthenticatedUser() instanceof User)) {

View File

@@ -160,12 +160,11 @@ class caption_record implements cache_cacheableInterface
} }
/** /**
* @param string $highlight
* @param array $grep_fields * @param array $grep_fields
* @param bool $includeBusiness * @param bool $includeBusiness
* @return array * @return array
*/ */
public function get_highlight_fields($highlight = '', array $grep_fields = null, $includeBusiness = false) public function get_highlight_fields(array $grep_fields = null, $includeBusiness = false)
{ {
$fields = []; $fields = [];
@@ -177,11 +176,6 @@ class caption_record implements cache_cacheableInterface
'from_thesaurus' => false, 'from_thesaurus' => false,
'qjs' => null, 'qjs' => null,
]; ];
if ($highlight) {
$v->highlight_thesaurus();
$values[$metaId]['from_thesaurus'] = $v->isThesaurusValue();
$values[$metaId]['qjs'] = $v->getQjs();
}
} }
$fields[$field->get_name()] = [ $fields[$field->get_name()] = [
'values' => $values, 'values' => $values,

View File

@@ -416,16 +416,14 @@ class media_Permalink_Adapter implements cache_cacheableInterface
$data[] = [ $data[] = [
'subdef_id' => $media_subdef->get_subdef_id(), 'subdef_id' => $media_subdef->get_subdef_id(),
'token' => $generator->generateString(64, TokenManipulator::LETTERS_AND_NUMBERS), 'token' => $generator->generateString(64, TokenManipulator::LETTERS_AND_NUMBERS),
'label' => $records[$media_subdef->get_record_id()]->get_title(false, null, true), 'label' => $records[$media_subdef->get_record_id()]->get_title(['removeExtension' => true]),
]; ];
} }
try { try {
$databox->get_connection()->transactional(function (Connection $connection) use ($data) { $databox->get_connection()->transactional(function (Connection $connection) use ($data) {
$sql = <<<'SQL' $sql = "INSERT INTO permalinks (subdef_id, token, activated, created_on, last_modified, label)\n"
INSERT INTO permalinks (subdef_id, token, activated, created_on, last_modified, label) . " VALUES (:subdef_id, :token, 1, NOW(), NOW(), :label)";
VALUES (:subdef_id, :token, 1, NOW(), NOW(), :label)
SQL;
$statement = $connection->prepare($sql); $statement = $connection->prepare($sql);

View File

@@ -387,6 +387,14 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
return \collection::getByCollectionId($this->app, $this->getDatabox(), $this->collection_id); return \collection::getByCollectionId($this->app, $this->getDatabox(), $this->collection_id);
} }
/**
* @return string the name of the collection to which the record belongs to.
*/
public function getCollectionName()
{
return $this->getCollection()->get_name();
}
/** /**
* Returns record_id of the record * Returns record_id of the record
* *
@@ -795,15 +803,20 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
} }
/** /**
* @param bool $highlight * get the title (concat "thumbtitle" fields which match locale, with "-")
* @param SearchEngineInterface $searchEngine * fallback to the filename, possibly with extension removed
* @param null $removeExtension *
* @param SearchEngineOptions $options * @param string $locale
* @param $options[]
* 'removeExtension' : boolean
*
* @return string * @return string
*/ */
public function get_title($highlight = false, SearchEngineInterface $searchEngine = null, $removeExtension = null, SearchEngineOptions $options = null) public function getTitle($locale = null, Array $options = [])
{ {
$cache = !$highlight && !$searchEngine && !$removeExtension; $removeExtension = !!igorw\get_in($options, ['removeExtension'], false);
$cache = !$removeExtension;
if ($cache) { if ($cache) {
try { try {
@@ -820,13 +833,13 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
$fields_to_retrieve = []; $fields_to_retrieve = [];
foreach ($fields as $field) { foreach ($fields as $field) {
if (in_array($field->get_thumbtitle(), ['1', $this->app['locale']])) { if (in_array($field->get_thumbtitle(), ['1', $locale])) {
$fields_to_retrieve [] = $field->get_name(); $fields_to_retrieve [] = $field->get_name();
} }
} }
if (count($fields_to_retrieve) > 0) { if (count($fields_to_retrieve) > 0) {
$retrieved_fields = $this->get_caption()->get_highlight_fields($highlight, $fields_to_retrieve); $retrieved_fields = $this->get_caption()->get_highlight_fields($fields_to_retrieve);
$titles = []; $titles = [];
foreach ($retrieved_fields as $value) { foreach ($retrieved_fields as $value) {
foreach ($value['values'] as $v) { foreach ($value['values'] as $v) {
@@ -849,6 +862,16 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
return $title; return $title;
} }
/**
* @param Array $options
*
* @return string
*/
public function get_title(Array $options = [])
{
return $this->getTitle($this->app['locale'], $options);
}
/** /**
* @return media_subdef * @return media_subdef
*/ */
@@ -1524,12 +1547,12 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
* @param int $offset_start * @param int $offset_start
* @param int $how_many * @param int $how_many
* *
* @return array * @return record_adapter[]
*/ */
public static function get_records_by_originalname(databox $databox, $original_name, $caseSensitive = false, $offset_start = 0, $how_many = 10) public static function get_records_by_originalname(databox $databox, $original_name, $caseSensitive = false, $offset_start = 0, $how_many = 10)
{ {
$offset_start = (int)($offset_start < 0 ? 0 : $offset_start); $offset_start = max(0, (int)$offset_start);
$how_many = (int)(($how_many > 20 || $how_many < 1) ? 10 : $how_many); $how_many = max(1, (int)$how_many);
$sql = sprintf( $sql = sprintf(
'SELECT record_id FROM record WHERE originalname = :original_name COLLATE %s LIMIT %d, %d', 'SELECT record_id FROM record WHERE originalname = :original_name COLLATE %s LIMIT %d, %d',

View File

@@ -252,7 +252,7 @@ class record_preview extends record_adapter
* *
* @return String * @return String
*/ */
public function get_title($highlight = false, SearchEngineInterface $searchEngine = null, $removeExtension = null, SearchEngineOptions $options = null) public function get_title(Array $options = [])
{ {
if ($this->title) { if ($this->title) {
return $this->title; return $this->title;
@@ -264,14 +264,14 @@ class record_preview extends record_adapter
case "RESULT": case "RESULT":
$this->title .= $this->app->trans('resultat numero %number%', ['%number%' => '<span id="current_result_n">' . ($this->getNumber() + 1) . '</span> : ']); $this->title .= $this->app->trans('resultat numero %number%', ['%number%' => '<span id="current_result_n">' . ($this->getNumber() + 1) . '</span> : ']);
$this->title .= parent::get_title($highlight, $searchEngine); $this->title .= parent::get_title($options);
break; break;
case "BASK": case "BASK":
$this->title .= $this->name . ' - ' . parent::get_title($highlight, $searchEngine) $this->title .= $this->name . ' - ' . parent::get_title($options)
. ' (' . $this->getNumber() . '/' . $this->total . ') '; . ' (' . $this->getNumber() . '/' . $this->total . ') ';
break; break;
case "REG": case "REG":
$title = parent::get_title(); $title = parent::get_title($options);
if ($this->getNumber() == 0) { if ($this->getNumber() == 0) {
$this->title .= $title; $this->title .= $title;
} else { } else {
@@ -281,7 +281,7 @@ class record_preview extends record_adapter
} }
break; break;
default: default:
$this->title .= parent::get_title($highlight, $searchEngine); $this->title .= parent::get_title($options);
break; break;
} }

View File

@@ -130,7 +130,7 @@ class set_export extends set_abstract
$app, $app,
$child_basrec->getDataboxId(), $child_basrec->getDataboxId(),
$record_id, $record_id,
$record->get_title(null, null, true) . '_' . $n, $record->get_title(['removeExtension' => true]) . '_' . $n,
$remain_hd[$base_id] $remain_hd[$base_id]
); );
$this->add_element($current_element); $this->add_element($current_element);
@@ -256,18 +256,17 @@ class set_export extends set_abstract
$types['usr_id'] = PDO::PARAM_INT; $types['usr_id'] = PDO::PARAM_INT;
} }
$sql = <<<SQL $sql = "SELECT Users.id AS usr_id ,Users.login AS usr_login ,Users.email AS usr_mail, FtpCredential.*\n"
SELECT Users.id AS usr_id ,Users.login AS usr_login ,Users.email AS usr_mail, FtpCredential.* . "FROM (\n"
FROM ( . " FtpCredential INNER JOIN Users ON (FtpCredential.active = 1 AND FtpCredential.user_id = Users.id)\n"
FtpCredential INNER JOIN Users ON (FtpCredential.active = 1 AND FtpCredential.user_id = Users.id) . "INNER JOIN\n"
INNER JOIN basusr ON ( . " basusr\n"
Users.id=basusr.usr_id . "ON (Users.id=basusr.usr_id"
${userFilterSQL} . $userFilterSQL
AND (basusr.base_id IN (:baseIds)) . " AND (basusr.base_id IN (:baseIds)))\n"
) . ")\n"
) . "GROUP BY Users.id\n";
GROUP BY Users.id
SQL;
$params['baseIds'] = $lst_base_id; $params['baseIds'] = $lst_base_id;
$types['baseIds'] = Connection::PARAM_INT_ARRAY; $types['baseIds'] = Connection::PARAM_INT_ARRAY;
@@ -440,7 +439,7 @@ SQL;
substr($files[$id]['original_name'], 0 - strrpos($files[$id]['original_name'], '.')); substr($files[$id]['original_name'], 0 - strrpos($files[$id]['original_name'], '.'));
if ($rename_title) { if ($rename_title) {
$title = strip_tags($download_element->get_title(null, null, true)); $title = strip_tags($download_element->get_title(['removeExtension' => true]));
$files[$id]['export_name'] = $unicode->remove_nonazAZ09($title, true, true, true); $files[$id]['export_name'] = $unicode->remove_nonazAZ09($title, true, true, true);
} else { } else {
$files[$id]["export_name"] = $infos['filename']; $files[$id]["export_name"] = $infos['filename'];
@@ -458,11 +457,16 @@ SQL;
continue; continue;
} }
$subdef = null;
if (!in_array($name, ['caption', 'caption-yaml'])) {
try {
// get_subdef() can throw a 404
$subdef = $download_element->get_subdef($name); $subdef = $download_element->get_subdef($name);
}
if (!in_array($name, ['caption', 'caption-yaml']) && !isset($subdef)) { catch(\Exception $e) {
continue; continue;
} }
}
set_time_limit(100); set_time_limit(100);
$subdef_export = $subdef_alive = false; $subdef_export = $subdef_alive = false;
@@ -691,7 +695,7 @@ SQL;
public static function build_zip(Application $app, Token $token, array $list, $zipFile) public static function build_zip(Application $app, Token $token, array $list, $zipFile)
{ {
if (isset($list['complete']) && $list['complete'] === true) { if (isset($list['complete']) && $list['complete'] === true) {
return; return $zipFile;
} }
$files = $list['files']; $files = $list['files'];
@@ -786,9 +790,7 @@ SQL;
$list_base = array_unique(array_keys($tmplog)); $list_base = array_unique(array_keys($tmplog));
if (!$anonymous && null !== $app->getAuthenticatedUser()) { if (!$anonymous && null !== $app->getAuthenticatedUser()) {
$sql = "UPDATE basusr $sql = "UPDATE basusr SET remain_dwnld = :remain_dl WHERE base_id = :base_id AND usr_id = :usr_id";
SET remain_dwnld = :remain_dl
WHERE base_id = :base_id AND usr_id = :usr_id";
$stmt = $app->getApplicationBox()->get_connection()->prepare($sql); $stmt = $app->getApplicationBox()->get_connection()->prepare($sql);

View File

@@ -103,7 +103,7 @@
{% endmacro %} {% endmacro %}
{% macro format_caption(record, highlight, search_engine, include_business, bounceable, technical_data) %} {% macro format_caption(record, highlight, search_engine, include_business, bounceable, technical_data) %}
{% for field in record.get_caption().get_highlight_fields(highlight, null, include_business) %} {% for field in record.get_caption().get_highlight_fields(null, include_business) %}
{% set extra_classes = ['pair'] %} {% set extra_classes = ['pair'] %}
{% if loop.index is odd %} {% if loop.index is odd %}
{% set extra_classes = ['impair'] %} {% set extra_classes = ['impair'] %}

View File

@@ -4,13 +4,13 @@
{% set thumb_w = 256 %} {% set thumb_w = 256 %}
{% set thumb_h = 256 %} {% set thumb_h = 256 %}
{% set thumbnail = record.subdefs.thumbnail|default(null) %} {% set thumbnailSize = record_subdef_size(record, "thumbnail") %}
{% if thumbnail is not none %} {% if thumbnailSize is not null %}
{% set thumb_w = thumbnail.width %} {% set thumb_w = thumbnailSize.width %}
{% set thumb_h = thumbnail.height %} {% set thumb_h = thumbnailSize.height %}
{% endif %} {% endif %}
{% set url = record_thumbnail_url(record) %} {% set url = record_subdef_url(record, "thumbnail") %}
{% set box_w = box_w|round %} {% set box_w = box_w|round %}
{% set box_h = box_h|default(box_w)|round %} {% set box_h = box_h|default(box_w)|round %}

View File

@@ -5,11 +5,11 @@
sbas="{{ record.databoxId }}" sbas="{{ record.databoxId }}"
id="{{ prefix|default('IMGT') }}_{{ record.id }}" id="{{ prefix|default('IMGT') }}_{{ record.id }}"
class="IMGT diapo {% if record.story %}grouping{% endif %} type-{{ record.type }}" class="IMGT diapo {% if record.story %}grouping{% endif %} type-{{ record.type }}"
onDblClick="openPreview(this, '{{ record.story ? 'REG' : 'RESULT' }}', '{{ record.position|default(0) }}', '{{ record.id }}');"> {% if settings.handle_dblclick %}onDblClick="openPreview(this, '{{ record.story ? 'REG' : 'RESULT' }}', '{{ record.position|default(0) }}', '{{ record.id }}');"{% endif %}>
<div style="padding: 4px;"> <div style="padding: 4px;">
<div style="height:40px; position: relative; z-index: 95;margin-bottom:0;border-bottom:none;"> <div style="height:40px; position: relative; z-index: 95;margin-bottom:0;border-bottom:none;">
<div class="title" style="max-height:100%" title="{{ record.title(app.locale) }}"> <div class="title" style="max-height:100%" title="{{ record.getTitle(app.locale) }}">
{{ record.title(app.locale)|highlight }} {{ record.getTitle(app.locale)|highlight }}
</div> </div>
<div class="status"> <div class="status">
{% for flag in record_flags(record) %} {% for flag in record_flags(record) %}
@@ -73,7 +73,7 @@
<td style="text-align:right;width:{{l_width}}px;" valign="bottom"> <td style="text-align:right;width:{{l_width}}px;" valign="bottom">
{% if settings.rollover_thumbnail == 'caption' %} {% if settings.rollover_thumbnail == 'caption' %}
{% if record.subdefs.preview is defined and has_access_subdef(record, 'preview') %} {% if record_subdef_url(record, 'preview') is not null and has_access_subdef(record, 'preview') %}
<span class="icon-stack previewTips" tooltipsrc="{{ path('prod_tooltip_preview', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId }) }}"> <span class="icon-stack previewTips" tooltipsrc="{{ path('prod_tooltip_preview', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId }) }}">
<i class="icon-circle icon-stack-base"></i> <i class="icon-circle icon-stack-base"></i>
<i class="icon-search icon-light"></i> <i class="icon-search icon-light"></i>
@@ -94,6 +94,7 @@
</span> </span>
{% endif %} {% endif %}
{% if settings.show_context_menu %}
<span class="icon-stack contextMenuTrigger" id="contextTrigger_{{record.id}}" <span class="icon-stack contextMenuTrigger" id="contextTrigger_{{record.id}}"
tooltipsrc="{{ path('prod_tooltip_technical_data', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId }) }}"> tooltipsrc="{{ path('prod_tooltip_technical_data', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId }) }}">
<i class="icon-circle icon-stack-base"></i> <i class="icon-circle icon-stack-base"></i>
@@ -143,6 +144,7 @@
</tr> </tr>
</tbody> </tbody>
</table> </table>
{% endif %}
</td> </td>
</tr> </tr>
</table> </table>

View File

@@ -28,7 +28,9 @@
'images_size': images_size, 'images_size': images_size,
'technical_display': technical_display, 'technical_display': technical_display,
'rollover_thumbnail': rollover_thumbnail, 'rollover_thumbnail': rollover_thumbnail,
'doctype_display': doctype_display 'doctype_display': doctype_display,
'handle_dblclick' : true,
'show_context_menu': true
} }
} %} } %}
{% endblock %} {% endblock %}

View File

@@ -92,13 +92,16 @@
} }
} }
$(".records-subititution", scope).bind('click', function(){ $(".records-subititution .diapo", scope)
$(this).closest('.lazaret-proposals').find('.records-subititution').removeClass("thumb-selected"); .bind('click', function(e){
$(this).closest('.lazaret-proposals').find('.thumbnail').css({'border-color': 'white'}) $(this).closest('.lazaret-proposals').find('.diapo').removeClass('selected');
$(this).find('.thumbnail').css({'border-color': 'blue'}); $(this).addClass('selected');
$(this).addClass("thumb-selected"); }
}); );
$(".records-subititution .captionTips", scope).tooltip();
$(".records-subititution .infoTips", scope).tooltip();
$(".records-subititution .previewTips", scope).tooltip();
var emptying = false; // true=emptying, set to false to stop var emptying = false; // true=emptying, set to false to stop
@@ -198,14 +201,14 @@
var html = _.template($("#alert_error_tpl").html(), { var html = _.template($("#alert_error_tpl").html(), {
content:data.message content:data.message
}); });
that.closest(".thumbnail").append(html); that.closest(".diapo").append(html);
} }
}, },
error: function(){ error: function(){
var html = _.template($("#alert_error_tpl").html(), { var html = _.template($("#alert_error_tpl").html(), {
content:language.errorAjaxRequest content:language.errorAjaxRequest
}); });
that.closest(".thumbnail").append(html); that.closest(".diapo").append(html);
}, },
complete: function(){ complete: function(){
stopAjax(that); stopAjax(that);
@@ -233,14 +236,14 @@
var html = _.template($("#alert_error_tpl").html(), { var html = _.template($("#alert_error_tpl").html(), {
content:data.message content:data.message
}); });
that.closest(".thumbnail").append(html); that.closest(".diapo").append(html);
} }
}, },
error: function(){ error: function(){
var html = _.template($("#alert_error_tpl").html(), { var html = _.template($("#alert_error_tpl").html(), {
content:language.errorAjaxRequest content:language.errorAjaxRequest
}); });
that.closest(".thumbnail").append(html); that.closest(".diapo").append(html);
}, },
complete: function(){ complete: function(){
stopAjax(that); stopAjax(that);
@@ -253,14 +256,18 @@
$("button.subtitute-lazaret", scope).bind('click', function(){ $("button.subtitute-lazaret", scope).bind('click', function(){
var that = $(this); var that = $(this);
var lazaretId = getLazaretId(that); var lazaretId = getLazaretId(that);
var nbProposals = $('.records-subititution', $(this).closest('.wrapper-item')).length; var container = $(this).closest('.wrapper-item');
var nbProposals = $('.records-subititution', container).length;
var elements = [];
var nbElement = 0;
if(nbProposals > 1){ // we got more than one proposals if(nbProposals > 1){ // we got more than one proposals
var elements = $(".thumb-selected", $(this).closest('.wrapper-item')); elements = $(".selected", container);
var nbElement = elements.length; nbElement = elements.length;
}else if(nbProposals == 1){ }else if(nbProposals == 1){
var elements = $(this).closest('.wrapper-item').find(".records-subititution"); elements = container.find(".records-subititution");
var nbElement = 1 nbElement = 1
} }
else{ else{
return false; return false;
@@ -274,8 +281,7 @@
return false; return false;
} }
var recorThumb = elements.first().find('.record-thumb'); var recordId = elements.first().attr("data-record_id");
var recordId = recorThumb.find('input[name=record_id]').val();
$.ajax({ $.ajax({
type : 'POST', type : 'POST',
@@ -294,14 +300,14 @@
var html = _.template($("#alert_error_tpl").html(), { var html = _.template($("#alert_error_tpl").html(), {
content:data.message content:data.message
}); });
that.closest(".thumbnail").append(html); that.closest(".diapo").append(html);
} }
}, },
error: function(){ error: function(){
var html = _.template($("#alert_error_tpl").html(), { var html = _.template($("#alert_error_tpl").html(), {
content:language.errorAjaxRequest content:language.errorAjaxRequest
}); });
that.closest(".thumbnail").append(html); that.closest(".diapo").append(html);
}, },
complete: function(){ complete: function(){
stopAjax(that); stopAjax(that);
@@ -311,10 +317,15 @@
}); });
}); });
</script> </script>
<style>
.lazaret-proposals .diapo {
float:none;
}
</style>
{% macro lazaretElement(app, file) %} {% macro lazaretElement(app, file) %}
{% import "common/thumbnail.html.twig" as thumb %} {% import "common/thumbnail.html.twig" as thumb %}
{% set records = file.getRecordsToSubstitute(app) %} {% set records = file.getRecordsToSubstitute(app, true) %}
<div class="lazaret-file span4"> <div class="lazaret-file span4">
<h5>{{ "Last uploaded version" | trans }}</h5> <h5>{{ "Last uploaded version" | trans }}</h5>
<ul class="thumbnails"> <ul class="thumbnails">
@@ -370,17 +381,26 @@
</h5> </h5>
<ul class="thumbnails"> <ul class="thumbnails">
{% for record in records %} {% for record in records %}
{% set reasons = record['reasons'] %}
{% set record = record['record'] %}
{% if app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(record.get_base_id(), "canaddrecord") {% if app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(record.get_base_id(), "canaddrecord")
and app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(record.get_base_id(), "candeleterecord") %} and app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(record.get_base_id(), "candeleterecord") %}
<li class="records-subititution span3"> <li class="records-subititution span3" style="width:210px">
<div class="thumbnail"> {% include 'prod/results/record.html.twig' with {
<div class="record-thumb" style="text-align:center;"> 'record': record,
{{ thumb.format(record.get_thumbnail(), 169, 180, "", false, false) }} 'settings': {
<input name="record_id" value="{{ record.get_record_id() }}" type="hidden"/> 'images_size': 169,
</div> 'technical_display': '1',
'rollover_thumbnail': 'caption',
'doctype_display': '1',
'handle_dblclick' : false,
'show_context_menu': false
}
} %}
<div class="caption"> <div class="caption">
<p><b>{{ record.get_title() }}</b></p> {% for reason in reasons %}
</div> <p>{{ reason }}</p>
{% endfor %}
</div> </div>
</li> </li>
{% endif %} {% endif %}