Author: uncleringo
Date: 2010-01-21 17:43:31 +0100 (Thu, 21 Jan 2010)
New Revision: 27009
Added:
plugins/sfDoctrineJQueryUISortablePlugin/branches/
plugins/sfDoctrineJQueryUISortablePlugin/tags/
plugins/sfDoctrineJQueryUISortablePlugin/trunk/
plugins/sfDoctrineJQueryUISortablePlugin/trunk/LICENSE
plugins/sfDoctrineJQueryUISortablePlugin/trunk/README
plugins/sfDoctrineJQueryUISortablePlugin/trunk/config/
plugins/sfDoctrineJQueryUISortablePlugin/trunk/config/routing.yml
plugins/sfDoctrineJQueryUISortablePlugin/trunk/lib/
plugins/sfDoctrineJQueryUISortablePlugin/trunk/lib/widget/
plugins/sfDoctrineJQueryUISortablePlugin/trunk/lib/widget/sfWidgetFormDoctrineJQueryUISortable.class.php
plugins/sfDoctrineJQueryUISortablePlugin/trunk/modules/
plugins/sfDoctrineJQueryUISortablePlugin/trunk/modules/sfDoctrineJQueryUISortable/
plugins/sfDoctrineJQueryUISortablePlugin/trunk/modules/sfDoctrineJQueryUISortable/actions/
plugins/sfDoctrineJQueryUISortablePlugin/trunk/modules/sfDoctrineJQueryUISortable/actions/actions.class.php
plugins/sfDoctrineJQueryUISortablePlugin/trunk/package.xml
Log:
First import
Added: plugins/sfDoctrineJQueryUISortablePlugin/trunk/LICENSE
===================================================================
--- plugins/sfDoctrineJQueryUISortablePlugin/trunk/LICENSE
(rev 0)
+++ plugins/sfDoctrineJQueryUISortablePlugin/trunk/LICENSE 2010-01-21
16:43:31 UTC (rev 27009)
@@ -0,0 +1,19 @@
+Copyright (c) 2008 Rich Birch
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
\ No newline at end of file
Added: plugins/sfDoctrineJQueryUISortablePlugin/trunk/README
===================================================================
--- plugins/sfDoctrineJQueryUISortablePlugin/trunk/README
(rev 0)
+++ plugins/sfDoctrineJQueryUISortablePlugin/trunk/README 2010-01-21
16:43:31 UTC (rev 27009)
@@ -0,0 +1,27 @@
+sfDoctrineJQueryUISortablePlugin
+==========================
+
+INTRO
+
+Installation
+------------
+
+To install the plugin for a symfony project, the usual process is to use the
+symfony command line:
+
+ php symfony plugin:install sfDoctrineJQueryUISortablePlugin
+
+If for some reason this fails then you can manually download the tgz file from
+
+
http://plugins.symfony-project.org/get/sfDoctrineJQueryUISortablePlugin/sfDoctrineJQueryUISortablePlugin-1.2.0.tgz
+
+
+Usage
+-----
+
+Documentation coming soon(ish)...
+
+
+Configuration
+-------------
+
Added: plugins/sfDoctrineJQueryUISortablePlugin/trunk/config/routing.yml
===================================================================
--- plugins/sfDoctrineJQueryUISortablePlugin/trunk/config/routing.yml
(rev 0)
+++ plugins/sfDoctrineJQueryUISortablePlugin/trunk/config/routing.yml
2010-01-21 16:43:31 UTC (rev 27009)
@@ -0,0 +1,3 @@
+sfDoctrineJQueryUISortable:
+ url:
/sfDoctrineJQueryUISortable/saveOrder/:model/:rank_field/:parent_model/:parent_id
+ param: { module: sfDoctrineJQueryUISortable, action: saveOrder }
\ No newline at end of file
Added:
plugins/sfDoctrineJQueryUISortablePlugin/trunk/lib/widget/sfWidgetFormDoctrineJQueryUISortable.class.php
===================================================================
---
plugins/sfDoctrineJQueryUISortablePlugin/trunk/lib/widget/sfWidgetFormDoctrineJQueryUISortable.class.php
(rev 0)
+++
plugins/sfDoctrineJQueryUISortablePlugin/trunk/lib/widget/sfWidgetFormDoctrineJQueryUISortable.class.php
2010-01-21 16:43:31 UTC (rev 27009)
@@ -0,0 +1,181 @@
+<?php
+/**
+ *
+ * @author Rich Birch <[email protected]>
+ */
+class sfWidgetFormDoctrineJQueryUISortable extends sfWidgetForm
+{
+ /**
+ * Constructor.
+ *
+ * Available options:
+ *
+ *
+ * @param array $options An array of options
+ * @param array $attributes An array of default HTML attributes
+ *
+ */
+ protected function configure($options = array(), $attributes = array())
+ {
+ parent::configure($options, $attributes);
+
+ $this->addRequiredOption('model');
+ $this->addRequiredOption('parent_object');
+
+ $this->addOption('method', '__toString');
+ $this->addOption('key_method', 'getPrimaryKey');
+ $this->addOption('parent_key_method', 'getPrimaryKey');
+ $this->addOption('order_by', null);
+ $this->addOption('query', null);
+ $this->addOption('table_method', null);
+ $this->addOption('grid', false);
+ $this->addOption('rank_field', 'rank');
+ }
+
+ /**
+ * @param string $name The element name
+ * @param string $value The value displayed in this widget
+ * @param array $attributes An array of HTML attributes to be merged with
the default HTML attributes
+ * @param array $errors An array of errors for the field
+ *
+ * @return string An HTML tag string
+ *
+ * @see sfWidgetForm
+ */
+ public function render($name, $value = null, $attributes = array(), $errors
= array())
+ {
+
+ if (is_null($this->getOption('table_method')))
+ {
+ $query = is_null($this->getOption('query')) ?
Doctrine::getTable($this->getOption('model'))->createQuery() :
$this->getOption('query');
+ if ($order = $this->getOption('order_by'))
+ {
+ $query->addOrderBy($order[0] . ' ' . $order[1]);
+ }
+ $objects = $query->execute();
+ }
+ else
+ {
+ $tableMethod = $this->getOption('table_method');
+
+ $results = is_array($tableMethod)
+ ?
call_user_func_array(array(Doctrine::getTable($this->getOption('model')),
$tableMethod[0]), $tableMethod[1])
+ : Doctrine::getTable($this->getOption('model'))->$tableMethod();
+
+ if ($results instanceof Doctrine_Query)
+ {
+ $objects = $results->execute();
+ }
+ else if ($results instanceof Doctrine_Collection)
+ {
+ $objects = $results;
+ }
+ else if ($results instanceof Doctrine_Record)
+ {
+ $objects = new Doctrine_Collection($this->getOption('model'));
+ $objects[] = $results;
+ }
+ else
+ {
+ $objects = array();
+ }
+ }
+
+ $method = $this->getOption('method');
+ $grid = $this->getOption('grid');
+
+ $sortables = array();
+
+ foreach ($objects as $object)
+ {
+ $item = ( $grid
+ ? ''
+ : '<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>') .
+ ( is_array($method)
+ ? call_user_func_array(array($object, $method[0]), $method[1])
+ : $object->$method());
+
+ $sortables[] =
+ '<li class="ui-state-default" id="' .
$this->getSortableContainerId($object) . '">' . $item . '</li>';
+ }
+
+ $html = '<table><tbody>%content%</tbody></table>';
+
+ $html = str_replace('%content%', empty($sortables) ? '' :
$this->getContent($sortables, $object), $html);
+
+ return $html;
+ }
+
+ private function getContent($sortables, $object)
+ {
+ return '<tr><td><ul id="' . $this->getSortableContainerId() . '">' .
+ implode('', $sortables) .
+ '</ul></td></tr>' .
+ $this->getJavascript($object) . $this->getCss();
+ }
+
+ private function getCss()
+ {
+ $containerId = $this->getSortableContainerId();
+
+ $css = $this->getOption('grid')
+ ? '<style type="text/css">
+ #' . $containerId . ' { margin: 0; padding: 0; }
+ #' . $containerId . ' li { list-style-type: none; margin: 3px 3px 3px 0;
padding: 1px; float: left; width: 100px; height: 90px; font-size: 4em;
text-align: center; }
+</style>'
+ : '<style type="text/css">
+ #' . $containerId . ' { margin: 0; padding: 0; }
+ #' . $containerId . ' li { list-style-type: none; margin: 0 3px 3px 3px;
padding: 0.4em; padding-left: 1.5em; }
+ #' . $containerId . ' li span { position: absolute; margin-left: -1.3em; }
+</style>';
+
+ return $css;
+ }
+
+ private function getJavascript()
+ {
+ $parentKeyMethod = $this->getOption('parent_key_method');
+ $routing = sfContext::getInstance()->getRouting();
+
+ $saveOrderUrl = $routing->generate(
+ 'sfDoctrineJQueryUISortable',
+ array(
+ 'action' => 'saveOrder',
+ 'model' => $this->getOption('model'),
+ 'rank_field' => $this->getOption('rank_field'),
+ 'parent_model' => get_class($this->getOption('parent_object')),
+ 'parent_id' => $this->getOption('parent_object')->$parentKeyMethod()
+ )
+ );
+
+ $js = '
+<script type="text/javascript">
+ $(function(){
+ $("#' . $this->getSortableContainerId() . '").sortable({
+ update : function () {
+ serial = $(this).sortable("serialize");
+ $.ajax({
+ url: "' . $saveOrderUrl . '",
+ type: "post",
+ data: serial,
+ error: function(){
+ alert("theres an error with AJAX");
+ }
+ });
+ }
+ });
+
+ });
+</script>
+';
+
+ return $js;
+ }
+
+ private function getSortableContainerId($object = null)
+ {
+ $keyMethod = $this->getOption('key_method');
+
+ return 'sfDoctrineJQueryUISortable' . $this->getOption('model') . ($object
? '-' . $object->$keyMethod() : '');
+ }
+}
\ No newline at end of file
Added:
plugins/sfDoctrineJQueryUISortablePlugin/trunk/modules/sfDoctrineJQueryUISortable/actions/actions.class.php
===================================================================
---
plugins/sfDoctrineJQueryUISortablePlugin/trunk/modules/sfDoctrineJQueryUISortable/actions/actions.class.php
(rev 0)
+++
plugins/sfDoctrineJQueryUISortablePlugin/trunk/modules/sfDoctrineJQueryUISortable/actions/actions.class.php
2010-01-21 16:43:31 UTC (rev 27009)
@@ -0,0 +1,36 @@
+<?php
+
+class sfDoctrineJQueryUISortableActions extends sfActions
+{
+ public function executeSaveOrder(sfWebRequest $request)
+ {
+ $model = $request->getParameter('model');
+ $order = 'sfDoctrineJQueryUISortable' . $model;
+ $parentModel = $request->getParameter('parent_model');
+ $parentId = $request->getParameter('parent_id');
+
+ if (empty($model) || empty($order) || empty($parentModel) ||
empty($parentId)
+ || !is_array($request->getParameter($order)))
+ {
+ return sfView::NONE;
+ }
+
+ foreach ($request->getParameter($order) as $rank => $objectId)
+ {
+ $query = Doctrine_Query::create()
+ ->from($model . ' m')
+ ->innerJoin('m.' . $parentModel . ' p')
+ ->where('m.id=? AND p.id=?', array($objectId, $parentId));
+
+ $object = $query->fetchOne();
+
+ if ($object instanceOf $model)
+ {
+ $object->setRank($rank);
+ $object->save();
+ }
+ }
+
+ return sfView::HEADER_ONLY;
+ }
+}
\ No newline at end of file
Added: plugins/sfDoctrineJQueryUISortablePlugin/trunk/package.xml
===================================================================
--- plugins/sfDoctrineJQueryUISortablePlugin/trunk/package.xml
(rev 0)
+++ plugins/sfDoctrineJQueryUISortablePlugin/trunk/package.xml 2010-01-21
16:43:31 UTC (rev 27009)
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.4.6" version="2.0"
xmlns="http://pear.php.net/dtd/package-2.0"
xmlns:tasks="http://pear.php.net/dtd/tasks-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0
http://pear.php.net/dtd/package-2.0.xsd">
+ <name>sfDoctrineJQueryUISortablePlugin</name>
+ <channel>plugins.symfony-project.org</channel>
+ <summary>JQueryUI Sortable lists integrated with doctrine</summary>
+ <description>Description coming soon(ish)...
+ </description>
+ <lead>
+ <name>Rich Birch</name>
+ <user>uncleringo</user>
+ <email>[email protected]</email>
+ <active>yes</active>
+ </lead>
+ <date>2010-01-21</date>
+ <time>13:02:00</time>
+ <version>
+ <release>1.0.0</release>
+ <api>1.0.0</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <license uri="http://www.symfony-project.org/license">MIT license</license>
+ <notes>-</notes>
+ <contents>
+ <dir name="/">
+ <file role="data" name="README" />
+ <file role="data" name="LICENSE" />
+ <dir name="config">
+ <file role="data" name="routing.yml" />
+ </dir>
+ <dir name="lib">
+ <dir name="widget">
+ <!-- widgets -->
+ <file role="data" name="sfWidgetFormDoctrineJQueryUISortable.class.php" />
+ </dir>
+ </dir>
+ <dir name="modules">
+ <dir name="sfDoctrineJQueryUISortable">
+ <dir name="actions">
+ <file role="data" name="actions.class.php" />
+ </dir>
+ </dir>
+ </dir>
+ </dir>
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>5.2.0</min>
+ </php>
+ <pearinstaller>
+ <min>1.4.1</min>
+ </pearinstaller>
+ <package>
+ <name>symfony</name>
+ <channel>pear.symfony-project.com</channel>
+ <min>1.2.0</min>
+ <max>2.0.0</max>
+ <exclude>2.0.0</exclude>
+ </package>
+ </required>
+ </dependencies>
+ <phprelease />
+ <changelog>
+ <release>
+ <version>
+ <release>1.0.0</release>
+ <api>1.0.0</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <license uri="http://www.symfony-project.org/license">MIT license</license>
+ <date>2010-01-21</date>
+ <notes>
+ First stable version of the package
+ </notes>
+ </release>
+ </changelog>
+</package>
\ No newline at end of file
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.