From d99018d7400df4837047027c3c5e3ce5d38012a5 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Mon, 25 Jun 2012 10:20:04 +0200 Subject: [PATCH 1/2] resize collection pic 120 * 24 max --- lib/classes/appbox.class.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/classes/appbox.class.php b/lib/classes/appbox.class.php index bc0c019432..e324a42bb8 100644 --- a/lib/classes/appbox.class.php +++ b/lib/classes/appbox.class.php @@ -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'); From 8be60cf3c90e15fe2e35645a5fa3dbe16cc52b1e Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Mon, 25 Jun 2012 10:22:46 +0200 Subject: [PATCH 2/2] remove multi submit on move record action fix cs fix typo --- .../Controller/Prod/MoveCollection.php | 27 ++- lib/Alchemy/Phrasea/Helper/Record/Helper.php | 7 +- .../Phrasea/Helper/Record/MoveCollection.php | 58 +++--- .../web/prod/actions/collection_default.twig | 167 ++++++++++-------- .../web/prod/actions/collection_submit.twig | 22 --- 5 files changed, 149 insertions(+), 132 deletions(-) delete mode 100644 templates/web/prod/actions/collection_submit.twig diff --git a/lib/Alchemy/Phrasea/Controller/Prod/MoveCollection.php b/lib/Alchemy/Phrasea/Controller/Prod/MoveCollection.php index ef15245959..f58c70d678 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/MoveCollection.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/MoveCollection.php @@ -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; diff --git a/lib/Alchemy/Phrasea/Helper/Record/Helper.php b/lib/Alchemy/Phrasea/Helper/Record/Helper.php index d32be48f6f..542e92f736 100644 --- a/lib/Alchemy/Phrasea/Helper/Record/Helper.php +++ b/lib/Alchemy/Phrasea/Helper/Record/Helper.php @@ -77,9 +77,14 @@ class Helper extends \Alchemy\Phrasea\Helper\Helper /** * - * @var + * @var Symfony\Component\HttpFoundation\Request */ protected $request; + + /** + * + * @var boolean + */ protected $flatten_groupings = false; /** diff --git a/lib/Alchemy/Phrasea/Helper/Record/MoveCollection.php b/lib/Alchemy/Phrasea/Helper/Record/MoveCollection.php index 0d4b1b6edf..548598b741 100644 --- a/lib/Alchemy/Phrasea/Helper/Record/MoveCollection.php +++ b/lib/Alchemy/Phrasea/Helper/Record/MoveCollection.php @@ -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); diff --git a/templates/web/prod/actions/collection_default.twig b/templates/web/prod/actions/collection_default.twig index f1d3e9d5ed..eb358e36a2 100644 --- a/templates/web/prod/actions/collection_default.twig +++ b/templates/web/prod/actions/collection_default.twig @@ -1,100 +1,113 @@ -
-
- {% if action.has_many_sbas() %} +
+ + {% if action.has_many_sbas() %} {% trans 'prod::Les enregistrements ne provienent pas tous de la meme base et ne peuvent donc etre traites ensemble' %}
- +
- {% 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' %}
- +
- {% elseif action.is_possible() is empty %} + {% elseif action.is_possible() is empty %} {% trans 'erreur : Vous n\'avez pas les droits' %}
- +
- {% else %} -
- {% 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 %} -
+ {% else %} +
+ {% 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 %} +
+ {% if action.is_possible() %} - {% set countable = action.get_count_actionable() %} - {% trans %} - prod::collection {{countable}} documents a deplacer - {% endtrans %} -
-
- - -
-
-
- - {% if action.get_count_actionable_groupings() %} - - - - - -
- - {% trans 'prod::collection deplacer egalement les documents rattaches a ce(s) regroupement(s)' %} -
- {% endif %} - + {% set countable = action.get_count_actionable() %} + {% trans %} + prod::collection {{countable}} documents a deplacer + {% endtrans %} +
+
+ +
+
+
+ {% if action.get_count_actionable_groupings() %} + + + + + +
+ + {% trans 'prod::collection deplacer egalement les documents rattaches a ce(s) regroupement(s)' %} +
+ {% endif %} {% endif %} + + {% endif %} + +
- {% endif %} + + $.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); +}); + diff --git a/templates/web/prod/actions/collection_submit.twig b/templates/web/prod/actions/collection_submit.twig deleted file mode 100644 index 4dd00e329c..0000000000 --- a/templates/web/prod/actions/collection_submit.twig +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - -
{%trans 'boutton::fermer' %}
- - -