Beispiel #1
0
 /**
  * Makes an Ajax In Place editor control.
  *
  * @param string $id DOM ID of input element
  * @param string $url Postback URL of saved data
  * @param array $options Array of options to control the editor, including ajaxOptions (see link).
  * @link          http://github.com/madrobby/scriptaculous/wikis/ajax-inplaceeditor
  * @link http://book.cakephp.org/1.3/en/The-Manual/Core-Helpers/AJAX.html#editor
  */
 function editor($id, $url, $options = array())
 {
     $url = $this->url($url);
     $options['ajaxOptions'] = $this->__optionsForAjax($options);
     foreach ($this->ajaxOptions as $opt) {
         if (isset($options[$opt])) {
             unset($options[$opt]);
         }
     }
     if (isset($options['callback'])) {
         $options['callback'] = 'function(form, value) {' . $options['callback'] . '}';
     }
     $type = 'InPlaceEditor';
     if (isset($options['collection']) && is_array($options['collection'])) {
         $options['collection'] = $this->Javascript->object($options['collection']);
         $type = 'InPlaceCollectionEditor';
     }
     $var = '';
     if (isset($options['var'])) {
         $var = 'var ' . $options['var'] . ' = ';
         unset($options['var']);
     }
     $options = $this->_optionsToString($options, array('okText', 'cancelText', 'savingText', 'formId', 'externalControl', 'highlightcolor', 'highlightendcolor', 'savingClassName', 'formClassName', 'loadTextURL', 'loadingText', 'clickToEditText', 'okControl', 'cancelControl'));
     $options = $this->_buildOptions($options, $this->editorOptions);
     $script = "{$var}new Ajax.{$type}('{$id}', '{$url}', {$options});";
     return $this->Javascript->codeBlock($script);
 }
Beispiel #2
0
/**
 * Makes a list or group of floated objects sortable.
 *
 * @param string $id DOM ID of parent
 * @param array $options Array of options to control sort.
 * @link          http://docs.jquery.com/UI/Sortable
 */
	function sortable($id, $options = array()) {
		if (isset($options['var'])) {
			$var = 'var ' . $options['var'] . ' = ';
			unset($options['var']);
		} else {
			$var = 'var ' . $id . ' = ';
		}
		if (!empty($options['url'])) {
			if (empty($options['with'])) {
			    $options['with'] = "$('#$id').sortable('serialize')";
			}
			$upd = '';
		    if (isset($options['update'])){
		        $upd = $options['update'];
		        unset($options['update']);
	        }
			$options['update'] = $this->remoteFunction($options) . '; ' . $upd;
		}
		$block = true;

		if (isset($options['block'])) {
			$block = $options['block'];
			unset($options['block']);
		}
		$strings = array(
			'appendTo', 'axis', 'cancel', 'connectWith', 'containment', 'cursor', 'cursorAt', 
			'handle', 'helper', 'items', 'placeholder', 'tolerance',
		);
		
		if (isset($options['grid']) && is_array($options['grid'])) {
			$options['grid'] = $this->Javascript->object($options['grid']);
		}
		
		$callbacks = array('start', 'sort', 'change', 'beforeStop', 'stop', 'update', 
		'receive', 'remove', 'over', 'out', 'activate', 'deactivate');

		$options = $this->_optionsToString($options, $strings);
		$options = array_merge($options, $this->_buildUICallbacks($options, $callbacks));
		$options = $this->_buildOptions($options, $this->sortOptions);
		$result = "{$var} $('#$id').sortable($options);";

		if (!$block) {
			return $result;
		}
		return $this->Javascript->codeBlock($result);
	}