PHRAS-778 - deactivable documents type permalinks in tools modal

This commit is contained in:
Florian BLOUET
2015-10-21 10:46:35 +02:00
committed by Benoît Burnichon
parent a52cfd0d0c
commit 18f9542098
7 changed files with 183 additions and 12 deletions

View File

@@ -37,9 +37,22 @@ class ToolsController extends Controller
$metadata = false;
$record = null;
$recordAccessibleSubdefs = array();
if (count($records) == 1) {
$record = $records->first();
// fetch subdef list:
$subdefs = $record->get_subdefs();
foreach ($subdefs as $subdef) {
$permalink = $subdef->get_permalink();
$recordAccessibleSubdefs[] = array(
'name' => $subdef->get_name(),
'state' => $permalink->get_is_activated()
);
}
if (!$record->isStory()) {
try {
$metadata = $this->getExifToolReader()
@@ -56,6 +69,7 @@ class ToolsController extends Controller
return $this->render('prod/actions/Tools/index.html.twig', [
'records' => $records,
'record' => $record,
'recordSubdefs' => $recordAccessibleSubdefs,
'metadatas' => $metadata,
]);
}
@@ -268,6 +282,44 @@ class ToolsController extends Controller
return $this->app->json($return);
}
/**
* Edit a record share state
* @param Application $app
* @param Request $request
* @param $base_id
* @param $record_id
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function editRecordSharing(Request $request, $base_id, $record_id)
{
$record = new \record_adapter($this->app, \phrasea::sbasFromBas($this->app, $base_id), $record_id);
$subdefName = (string)$request->request->get('name');
$state = $request->request->get('state') == 'true' ? true : false;
$return = ['success' => false, 'message' => 'document type not found'];
$acl = $this->getAclForUser();
if (!$acl->has_access_to_subdef($record, $subdefName) || !$acl->is_admin()) {
$this->app->abort(403);
}
$subdefs = $record->get_subdefs();
foreach ($subdefs as $subdef) {
if ($subdef->get_name($subdefName) === $subdefName) {
$permalink = $subdef->get_permalink();
try {
$permalink->set_is_activated($state);
$return = ['success' => true, 'state' => $permalink->get_is_activated()];
} catch (\Exception $e) {
$return = ['success' => false, 'state' => $permalink->get_is_activated()];
}
}
}
return $this->app->json($return);
}
/**
* @return Reader
*/

View File

@@ -66,6 +66,8 @@ class Tools implements ControllerProviderInterface, ServiceProviderInterface
$controllers->post('/thumb-extractor/apply/', 'controller.prod.tools:applyThumbnailExtractionAction');
$controllers->post('/sharing-editor/{base_id}/{record_id}/', 'controller.prod.tools:editRecordSharing');
return $controllers;
}
}

View File

@@ -11,21 +11,20 @@
{% if url is not empty %}
<div id="share">
<div id="tweet" class="well-large">
<div>
<div class="well-large">
<p>
<a href="http://www.twitter.com/home/?status={{ pageurl }}" target="_blank">
<img src="/skins/icons/twitter.ico" title="share this on twitter" style="vertical-align:middle;padding:0 5px;"/>
{% trans %}Send to Twitter{% endtrans %}
</a>
</div>
<div>
</p>
<p>
<a href="http://www.facebook.com/sharer.php?u={{ pageurl }}" target="_blank">
<img src="/skins/icons/facebook.ico" title="share on facebook" style="vertical-align:middle;padding:0 5px;"/>
{% trans %}Send to Facebook{% endtrans %}
</a>
</div>
</div>
<div id="embed" class="well-large">
</p>
<form action="#">
<label>{% trans %}Resource URL{% endtrans %}</label>
<input class="input-block-level" readonly="readonly" type="text" value="{{ url }}" />

View File

@@ -20,7 +20,7 @@
<div id='prod-tool-box' class="PNB10">
{# jquery Tabs #}
<div id="tool-tabs">
<div id="tool-tabs" class="tabs">
{# jquery menu #}
<div>
<ul>
@@ -59,6 +59,15 @@
</a>
</li>
{% endif %}
{% if selectionLength == 1%}
{% if recordSubdefs %}
<li>
<a href="#tools-sharing">
{{ "Document Type Sharing" | trans }}
</a>
</li>
{% endif %}
{% endif %}
</ul>
</div>
{# subdef section #}
@@ -299,6 +308,37 @@
</div>
{% endfor %}
{% endif %}
{% if selectionLength == 1%}
{% if recordSubdefs %}
<div id="tools-sharing" class="tabBox">
<div class="well-large">
{% for subdef in recordSubdefs %}
<div class="row-fluid">
<div class="span6">
<span class="status-marker {% if subdef.state %}status-active{% else %}status-inactive
{% endif %}"></span>{{ subdef.name }}
</div>
<div class="span6">
<p class="text-right">
{% if subdef.state %}
<button type="button"
class="stateChange_button btn btn-inverse text-right"
data-name="{{ subdef.name }}"
data-state="{{ subdef.state }}">{{ "Disable document type sharing" | trans }}</button>
{% else %}
<button type="button" class="stateChange_button btn btn-inverse text-right"
data-name="{{ subdef.name }}"
data-state="{{ subdef.state }}">{{ "Enable document type sharing" | trans }}</button>
{% endif %}
</p>
</div>
</div>
{% endfor %}
</div>
</div>
{% endif %}
{% endif %}
</div>
{# hidden iframe to handle upload #}
@@ -315,10 +355,9 @@
$(document).ready(function(){
var scope = $("#prod-tool-box");
var tabs = $("#tool-tabs", scope).tabs();
var width = 0;
$("#tool-tabs", scope).tabs();
$(".iframe_submiter", scope).bind("click", function(){
var form = $(this).closest("form");
form.submit();
@@ -585,5 +624,30 @@ $(document).ready(function(){
//not supported
$("#thumbExtractor").empty().append(language.browserFeatureSupport);
}
{% if selectionLength == 1%}
$('#tools-sharing .stateChange_button').bind('click',function(event){
var $btn = $(event.currentTarget),
state = true;
// inverse state
if( $btn.data('state') == 1) {
state = false;
}
// submit changes
$.post('tools/sharing-editor/{{record.get_base_id}}/{{record.get_record_id}}/', {
name: $btn.data('name'),
state: state
}).done(function(data) {
// self reload tab with current active tab:
var activeTab = tabs.tabs('option', 'active');
toolREFACTOR($dialog.getOption('contextArgs'), activeTab);
}).error(function(err) {
alert('forbidden action')
});
return false;
});
{% endif %}
});
</script>

View File

@@ -4997,3 +4997,27 @@ ui-dialog-titlebar {
width: 26px;
}
}
.status-marker {
line-height: 10px;
border-radius: 50%;
width: 7px;
height: 7px;
display: inline-block;
margin-right: 4px;
margin-bottom: 0px;
}
.status-marker.status-active{
background-color: #58d5b5;
box-shadow: 0 0 6px #69fcd6;
}
.status-marker.status-inactive {
background-color: #aaaaaa;
box-shadow: inset 1px 1px 2px 0px rgba(0,0,0,0.7);
}
.text-right {
text-align: right;
}

View File

@@ -4889,3 +4889,27 @@ ui-dialog-titlebar {
color: #fff;
background: #999;
}
.status-marker {
line-height: 10px;
border-radius: 50%;
width: 7px;
height: 7px;
display: inline-block;
margin-right: 4px;
margin-bottom: 0px;
}
.status-marker.status-active{
background-color: #58d5b5;
box-shadow: 0 0 6px #69fcd6;
}
.status-marker.status-inactive {
background-color: #aaaaaa;
box-shadow: inset 1px 1px 2px 0px rgba(0,0,0,0.7);
}
.text-right {
text-align: right;
}

View File

@@ -1875,7 +1875,7 @@ function feedbackThis(sstt_id, lst, story) {
});
}
function toolREFACTOR(datas) {
function toolREFACTOR(datas, activeTab) {
var dialog = p4.Dialog.Create({
size: 'Medium',
@@ -1887,10 +1887,16 @@ function toolREFACTOR(datas) {
, datas
, function (data) {
dialog.setContent(data);
dialog.setOption('contextArgs', datas);
var tabs = $('.tabs', dialog.getDomElement()).tabs();
// activate tab if exists:
if( activeTab !== undefined ) {
tabs.tabs('option', 'active', activeTab);
}
return;
}
);
}
function activeIcons() {