Skip to content

Commit

Permalink
add widget 'dir' option and auto-browse to dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Agnano committed Jan 12, 2010
1 parent 6d8e899 commit 0f57c51
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
14 changes: 6 additions & 8 deletions README
Expand Up @@ -23,7 +23,7 @@ That means you insert 2 line of javascript and you browser your images, videos a
cd plugins
git clone git://github.com/vinyll/sfMediaBrowserPlugin.git

_If you don't have git install and don't want to install it, you can [download a sandbox version][19]_
_If you don't have git install and don't want to install it, you can [download a sandbox version](http://github.com/vinyll/sfMediaBrowserPlugin/downloads)

edit /config/ProjectConfiguration.class.php :

Expand All @@ -45,7 +45,7 @@ Open your browser, go to your app and run the url /sf\_media\_browser, and play

## How to enable moving and renaming ?

Download [ready to use jquery files](http://particul.es/blog/public/vince/sfmediabrowserplugin/js.zip).
[Download ready to use jquery files](http://particul.es/blog/public/vince/sfmediabrowserplugin/js.zip).
Copy the /js files into you /web/js folder.

Now edit /apps/_your\_app_/app.yml :
Expand Down Expand Up @@ -120,14 +120,12 @@ You can participate by many ways :

## TODO

- improve security and lock parent root folder browsing
- test sfValidatorMediaBrowserFile
- add another browsing view with folder tree and files seperated
- add file edition functionalities (move, rename)
- add image edition functionalities (resize and maybe rotate)
- add another browsing view with folder tree and files seperated ?
- add image edition functionalities (resize and maybe rotate ?)
- add permission managment (sfModularSecurity ?)
- add a jquery optional version (dom's filepicker. ajax view ? crop image ?)
- add sfDynamics packages managment
- finish the jquery optional version (dom's filepicker. ajax view ? crop image ?)
- add sfDynamics packages managment ?


## About
Expand Down
32 changes: 21 additions & 11 deletions lib/widget/sfWidgetFormInputMediaBrowser.class.php
Expand Up @@ -20,24 +20,29 @@ class sfWidgetFormInputMediaBrowser extends sfWidgetForm
{

protected $context;

/**
* Constructor.
*
* Available options:
*
* * type: The widget type (text by default)
*
* @param array $options An array of options
* @param array $options An array of options :
* - dir: The default directory to display if no value exists.
* The url is relative to app_sf_media_browser_root_dir
* @param array $attributes An array of default HTML attributes
*
* @see sfWidgetForm
*/
protected function configure($options = array(), $attributes = array())
{
$this->addOption('type', 'text');
$this->addOption('dir', null);

$this->setOption('is_hidden', false);
}


/**
* @param string $name The element name
Expand All @@ -55,20 +60,23 @@ public function render($name, $value = null, $attributes = array(), $errors = ar

$attributes = array_merge(array('type' => $this->getOption('type'), 'name' => $name, 'value' => $value), $attributes);
$attributes = $this->fixFormId($attributes);
$url = $this->context->getRouting()->generate('sf_media_browser_select');

$tag = $this->renderTag('input', $attributes);

$tag .= $this->includeView();
$tag .= $this->includeDelete();

// Get default dir for popup window
$dir = $value
? dirname($value)
: sfConfig::get('app_sf_media_browser_root_dir').'/'.$this->getOption('dir');

$url = $this->context->getRouting()->generate('sf_media_browser_select', array('dir' => $dir));

$tag = $this->renderTag('input', $attributes)
.$this->includeView()
.$this->includeDelete();

// Add javascripts and stylesheets upon app configuration
// Add javascripts and stylesheets as configure in app_sf_media_browser_assets_widget
sfMediaBrowserUtils::loadAssets(sfConfig::get('app_sf_media_browser_assets_widget'));
$tag .= $this->loadJavascript(array_merge($attributes, array('url' => $url)));

$tag = $this->wrapTag($tag);
return $tag;
return $this->wrapTag($tag);
}


Expand All @@ -95,7 +103,8 @@ protected function includeDelete()
$tag = '<a class="delete">delete</a>';
return $tag;
}



/**
* Includes a view tag
* @return string HTML formatted span class="view"
Expand All @@ -105,6 +114,7 @@ protected function includeView()
$tag = '<a class="view">view</a>';
return $tag;
}


/**
* Wraps a tag within a <span class="sf_media_browser_input_file"></span>
Expand Down

0 comments on commit 0f57c51

Please sign in to comment.