Merge pull request #148 from nlegoff/fixes

Fixes
This commit is contained in:
Romain Neutron
2012-06-26 03:52:10 -07:00
6 changed files with 166 additions and 134 deletions

View File

@@ -15,6 +15,7 @@ use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Alchemy\Phrasea\Helper\Record as RecordHelper;
/**
@@ -42,16 +43,26 @@ class MoveCollection implements ControllerProviderInterface
}
);
$controllers->post('/apply/', function(Application $app) {
$request = $app['request'];
$move = new RecordHelper\MoveCollection($app['Core'], $app['request']);
$move->execute($request);
$template = 'prod/actions/collection_submit.twig';
$controllers->post('/apply/', function(Application $app, Request $request) {
$move = new RecordHelper\MoveCollection($app['Core'], $request);
$success = false;
/* @var $twig \Twig_Environment */
$twig = $app['Core']->getTwig();
try {
$move->execute();
$success = true;
$msg = _('Records have been successfuly moved');
} catch (\Exception_Unauthorized $e) {
$msg = sprintf(_("You do not have the permission to move records to %s"), \phrasea::bas_names($move->getBaseIdDestination()));
} catch (\Exception $e) {
$msg = _('An error occured');
}
return $twig->render($template, array('action' => $move, 'message' => ''));
$datas = array(
'success' => $success,
'message' => $msg
);
return new JsonResponse($datas);
});
return $controllers;

View File

@@ -77,9 +77,14 @@ class Helper extends \Alchemy\Phrasea\Helper\Helper
/**
*
* @var <type>
* @var Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
*
* @var boolean
*/
protected $flatten_groupings = false;
/**

View File

@@ -39,19 +39,44 @@ class MoveCollection extends RecordHelper
*/
protected $works_on_unique_sbas = true;
/**
* Destination collection id
*
* @var integer
*/
protected $baseIdDestination;
/**
*
* @param \Alchemy\Phrasea\Core $core
*
* @return MoveCollection
*/
public function __construct(Core $core, Request $Request)
public function __construct(Core $core, Request $request)
{
parent::__construct($core, $Request);
$this->baseIdDestination = $request->get('base_id');
if ($request->get("chg_coll_son") == "1") {
$this->flatten_groupings = true;
}
parent::__construct($core, $request);
$this->evaluate_destinations();
return $this;
}
/**
* Get destination collection id
*
* @return integer
*/
public function getBaseIdDestination()
{
return $this->baseIdDestination;
}
/**
* Check which collections can receive the documents
*
@@ -91,38 +116,23 @@ class MoveCollection extends RecordHelper
/**
*
* @param http_request $request
* @return action_move
*/
public function execute(Request $request)
public function execute()
{
$appbox = \appbox::get_instance($this->core);
$user = $this->getCore()->getAuthenticatedUser();
$baseId = $request->get('base_id');
$base_dest =
$user->ACL()->has_right_on_base($baseId, 'canaddrecord') ?
$request->get('base_id') : false;
$user->ACL()->has_right_on_base($this->baseIdDestination, 'canaddrecord') ?
$this->baseIdDestination : false;
if ( ! $user->ACL()->has_right_on_base($baseId, 'canaddrecord')) {
throw new \Exception_Unauthorized(sprintf("%s do not have the permission to move records to %s", $user->get_login()));
if ( ! $user->ACL()->has_right_on_base($this->baseIdDestination, 'canaddrecord')) {
throw new \Exception_Unauthorized(sprintf("user id %s does not have the permission to move records to %s", $user->get_id(), \phrasea::bas_names($this->baseIdDestination)));
}
if ( ! $this->is_possible())
throw new Exception('This action is not possible');
if ($request->get("chg_coll_son") == "1") {
foreach ($this->selection as $record) {
if ( ! $record->is_grouping())
continue;
foreach ($record->get_children() as $child) {
if ( ! $user->ACL()->has_right_on_base(
$child->get_base_id(), 'candeleterecord'))
continue;
$this->selection->add_element($child);
}
}
if ( ! $this->is_possible()) {
throw new \Exception('This action is not possible');
}
$collection = \collection::get_from_base_id($base_dest);

View File

@@ -10,6 +10,7 @@
*/
use Symfony\Component\HttpFoundation\File\File as SymfoFile;
use MediaAlchemyst\Specification\Image as ImageSpecification;
/**
*
@@ -101,6 +102,20 @@ class appbox extends base
if ( ! in_array(mb_strtolower($pathfile->getMimeType()), array('image/gif', 'image/png', 'image/jpeg', 'image/jpg', 'image/pjpeg'))) {
throw new \InvalidArgumentException('Invalid file format');
}
//resize collection logo
$imageSpec = new ImageSpecification();
$imageSpec->setResizeMode(ImageSpecification::RESIZE_MODE_INBOUND_FIXEDRATIO);
$imageSpec->setDimensions(120, 24);
try {
$core['media-alchemyst']
->open($pathfile->getPathname())
->turninto($pathfile->getPathname(), $imageSpec)
->close();
} catch (\MediaAlchemyst\Exception $e) {
}
}
switch ($pic_type) {
@@ -132,7 +147,7 @@ class appbox extends base
$core['file-system']->remove($target);
}
if (is_null($target)) {
if (null === $target || null === $pathfile) {
continue;
}
@@ -366,7 +381,7 @@ class appbox extends base
$upgrader->add_steps_complete(1);
if(version_compare($from_version, '3.1') < 0) {
if (version_compare($from_version, '3.1') < 0) {
$upgrader->addRecommendation(_('Your install requires data migration, please execute the following command'), 'bin/upgrader --from=3.1');
} elseif (version_compare($from_version, '3.5') < 0) {
$upgrader->addRecommendation(_('Your install requires data migration, please execute the following command'), 'bin/upgrader --from=3.5');

View File

@@ -1,100 +1,113 @@
<div style="text-align:center;margin:30px 0px;">
<form onsubmit="return false" action="/prod/records/movecollection/apply/" method="post">
{% if action.has_many_sbas() %}
<div style="text-align:center;margin:30px 0px;">
<form onsubmit="return false" action="/prod/records/movecollection/apply/" method="post">
{% if action.has_many_sbas() %}
{% trans 'prod::Les enregistrements ne provienent pas tous de la meme base et ne peuvent donc etre traites ensemble' %}
<div style="text-align:center;">
<button class="move_cancel">{% trans 'boutton::annuler' %}</button>
<button class="move_cancel">{% trans 'boutton::annuler' %}</button>
</div>
{% elseif action.get_count_actionable() == 0 %}
{% elseif action.get_count_actionable() == 0 %}
{% trans 'prod::Vous n\'avez le droit d\'effectuer l\'operation sur aucun document' %}
<div style="text-align:center;">
<button class="move_cancel">{% trans 'boutton::annuler' %}</button>
<button class="move_cancel">{% trans 'boutton::annuler' %}</button>
</div>
{% elseif action.is_possible() is empty %}
{% elseif action.is_possible() is empty %}
{% trans 'erreur : Vous n\'avez pas les droits' %}
<div style="text-align:center;">
<button class="move_cancel">{% trans 'boutton::annuler' %}</button>
<button class="move_cancel">{% trans 'boutton::annuler' %}</button>
</div>
{% else %}
<div>
{% if action.get_count_not_actionable() != 0 %}
{% set countable = action.get_count_not_actionable() %}
{% trans %}
prod::collection {{countable}} documents ne pouvant etres mofiies
{% endtrans %}
{% endif %}
</div>
{% else %}
<div>
{% if action.get_count_not_actionable() != 0 %}
{% set countable = action.get_count_not_actionable() %}
{% trans %}
prod::collection {{countable}} documents ne pouvant etres mofiies
{% endtrans %}
{% endif %}
</div>
{% if action.is_possible() %}
{% set countable = action.get_count_actionable() %}
{% trans %}
prod::collection {{countable}} documents a deplacer
{% endtrans %}
<br/>
<br/>
<select name="base_id">
{% for base_id in action.available_destination() %}
<option value="{{base_id}}">{{base_id|bas_names}}</option>
{% endfor %}
</select>
<br/>
<br/>
<br/>
{% if action.get_count_actionable_groupings() %}
<table style="border:#ff0000 1px solid;">
<tr>
<td style="width:25px;"><input type="checkbox" value="1" name="chg_coll_son"/>
</td>
<td style="width:250px; text-align:left">
{% trans 'prod::collection deplacer egalement les documents rattaches a ce(s) regroupement(s)' %}
</td>
</tr>
</table>
{% endif %}
{% set countable = action.get_count_actionable() %}
{% trans %}
prod::collection {{countable}} documents a deplacer
{% endtrans %}
<br/>
<br/>
<select name="base_id">
{% for base_id in action.available_destination() %}
<option value="{{base_id}}">{{base_id|bas_names}}</option>
{% endfor %}
</select>
<br/>
<br/>
<br/>
{% if action.get_count_actionable_groupings() %}
<table style="border:#ff0000 1px solid;">
<tr>
<td style="width:25px;"><input type="checkbox" value="1" name="chg_coll_son"/>
</td>
<td style="width:250px; text-align:left">
{% trans 'prod::collection deplacer egalement les documents rattaches a ce(s) regroupement(s)' %}
</td>
</tr>
</table>
{% endif %}
{% endif %}
<input type="hidden" name="act" value="WORK">
<input type="hidden" name="lst" value="{{ action.get_serialize_list() }}">
{% endif %}
</form>
</div>
{% endif %}
<script type="text/javascript">
</form>
</div>
$(document).ready(function(){
<script type="text/javascript">
$dialog = p4.Dialog.get(1);
$(document).ready(function(){
var $form = $dialog.getDomElement();
$dialog = p4.Dialog.get(1);
var buttons = {};
var $form = $dialog.getDomElement();
buttons[language.valider] = function(){
var buttons = {};
buttons[language.valider] = function(){
var coll_son = $('input[name="chg_coll_son"]:checked', $form).length > 0 ? '1' : '0';
var datas = {
lst:$('input[name="lst"]', $form).val(),
base_id:$('select[name="base_id"]', $form).val(),
chg_coll_son:coll_son
};
$.ajax({
type: "POST",
url: "/prod/records/movecollection/apply/",
data: datas,
success: function(data){
$dialog.Close();
}
});
return false;
var coll_son = $('input[name="chg_coll_son"]:checked', $form).length > 0 ? '1' : '0';
var datas = {
lst: $('input[name="lst"]', $form).val(),
base_id: $('select[name="base_id"]', $form).val(),
chg_coll_son: coll_son
};
$dialog.setOption('buttons', buttons);
var buttonPanel = $dialog.getDomElement()
.closest('.ui-dialog')
.find('.ui-dialog-buttonpane');
});
</script>
$.ajax({
type: "POST",
url: "/prod/records/movecollection/apply/",
dataType: 'json',
data: datas,
beforeSend: function() {
$(":button:contains('" + language.valider + "')", buttonPanel)
.attr("disabled", true).addClass("ui-state-disabled");
},
success: function(data){
$dialog.Close();
if(data.success) {
humane.info(data.message);
} else {
humane.error(data.message);
}
},
complete: function(){
$(":button:contains('" + language.valider + "')", buttonPanel)
.attr("disabled", false).removeClass("ui-state-disabled");
}
});
return false;
};
$dialog.setOption('buttons', buttons);
});
</script>

View File

@@ -1,22 +0,0 @@
<html lang="{{session.get_I18n()}}">
<head>
<link type="text/css" rel="stylesheet" href="/include/minify/f=skins/common/main.css,skins/prod/{{user.getPrefs('css')}}/prodcolor.css," />
<script type="text/javascript" src="/include/minify/f=include/jslibs/jquery-1.7.1.js,include/jquery.p4.modal.js"></script>
<script type="text/javascript" src="/include/jslibs/jquery-ui-1.8.17/js/jquery-ui-1.8.17.custom.min.js"></script>
</head>
<body id="body" class="bodyprofile" style="overflow:hidden; padding:0px; margin:0px;">
<div class="boxCloser" onclick="parent.hideDwnl();">{%trans 'boutton::fermer' %}</div>
<div id="tabs">
<ul>
<li><a href="#colls">{%trans 'prod::collection::Changer de collection' %}</a></li>
</ul>
<div id="colls" class="tabBox">
<div style="text-align:center;margin:30px 0px;">
{{message}}
<input class="input-button" type="button" value="{%trans 'boutton::fermer' %}" onclick="parent.hideDwnl();" />
</div>
</div>
</div>
</body>
</html>