From: Michael J. Rubinsky Date: Fri, 23 Jul 2010 23:13:54 +0000 (-0400) Subject: First pass at adding Ajax editing to menmo's note block. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=0ec03ab2b173ac391bbbcda3a783b32af38de718;p=horde.git First pass at adding Ajax editing to menmo's note block. Can probably still tweak some things, but basic functionality is there. Just click any where on the note to activate the editor. --- diff --git a/horde/js/inplaceeditor.js b/horde/js/inplaceeditor.js index ca9fdc94b..8ae90968f 100644 --- a/horde/js/inplaceeditor.js +++ b/horde/js/inplaceeditor.js @@ -63,6 +63,7 @@ InPlaceEditor = Class.create( stripLoadedTextTags: false, submitOnBlur: false, width: null, + autoWidth: false, /** Default Callbacks **/ callback: function(form) @@ -191,8 +192,11 @@ InPlaceEditor = Class.create( fld.value = text; // No HTML breaks conversion anymore fld.className = 'editor_field'; if (this.options.width) { - fld.setStyle({ width: this.options.width + 'px' }); + var w = this.options.width + 'px'; + } else if (this.options.autoWidth) { + var w = this.element.up().getWidth() + 'px'; } + fld.setStyle({ width: w }); if (this.options.submitOnBlur) { fld.observe('blur', this._boundSubmitHandler); } diff --git a/mnemo/lib/Ajax/Imple/EditNote.php b/mnemo/lib/Ajax/Imple/EditNote.php new file mode 100644 index 000000000..bf15431e7 --- /dev/null +++ b/mnemo/lib/Ajax/Imple/EditNote.php @@ -0,0 +1,84 @@ + + * @package Mnemo + */ +class Mnemo_Ajax_Imple_EditNote extends Horde_Core_Ajax_Imple +{ + public function __construct($params) + { + /* Set up some defaults */ + if (empty($params['rows'])) { + $params['rows'] = 2; + } + if (empty($params['cols'])) { + $params['cols'] = 20; + } + parent::__construct($params); + } + + public function attach() + { + Horde::addScriptFile('effects.js', 'horde'); + Horde::addScriptFile('inplaceeditor.js', 'horde'); + + $params = array('input' => 'value', + 'id' => $this->_params['id']); + + $url = $this->_getUrl('EditNote', 'mnemo', $params); + $loadTextUrl = $this->_getUrl('EditNote', 'mnemo', array_merge($params, array('action' => 'load'))); + $js = array(); + + $js[] = "new InPlaceEditor('" . $this->_params['domid'] . "', '" . $url . "', {" + . " callback: function(form, value) {" + . " return 'value=' + encodeURIComponent(value);}," + . " loadTextURL: '". $loadTextUrl . "'," + . " rows: 4, " + . " autoWidth: true," + . " emptyText: '" . _("Click to add text...") . "'," + . " onComplete: function(ipe, opts) { ipe.checkEmpty() }," + . " cancelText: '" . _("Cancel") . "'," + . " okText: '" . _("Ok") . "'," + . " cancelClassName: ''" + . " });"; + + Horde::addInlineScript($js, 'dom'); + } + + public function handle($args, $post) + { + if ($GLOBALS['registry']->getAuth()) { + /* Are we requesting the unformatted text? */ + if (!empty($args['action']) && $args['action'] == 'load') { + $id = $args['id']; + $storage = Mnemo_Driver::singleton(); + $memo = $storage->getByUID($id); + return $memo['body']; + } + if (empty($args['input']) || + is_null($pref_value = Horde_Util::getPost($args['input'], null)) || + empty($args['id'])) { + + return ''; + } + + $storage = Mnemo_Driver::singleton(); + $memo = $storage->getByUID($args['id']); + $share = $GLOBALS['mnemo_shares']->getShare($memo['memolist_id']); + if (!$share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) { + throw new Horde_Exception_PermissionDenied(_("You do not have permission to edit this note.")); + } + + $storage->modify($memo['memo_id'], $memo['desc'], $pref_value); + return $GLOBALS['injector']->getInstance('Horde_Text_Filter')->filter( + $pref_value, + 'text2html', + array('parselevel' => Horde_Text_Filter_Text2html::MICRO)); + } + } + +} diff --git a/mnemo/lib/Block/note.php b/mnemo/lib/Block/note.php index 1a7d69340..7ce08ae2a 100644 --- a/mnemo/lib/Block/note.php +++ b/mnemo/lib/Block/note.php @@ -39,13 +39,16 @@ class Horde_Block_Mnemo_note extends Horde_Block protected function _content() { $memo = $this->_getNote(); - $html = '
'; + $html = '
'; $body = $GLOBALS['injector']->getInstance('Horde_Text_Filter')->filter($memo['body'], 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO)); try { $body = Horde::callHook('format_description', array($body), 'mnemo', $body); } catch (Horde_Exception_HookNotSet $e) {} $html .= $body . '
'; - + $GLOBALS['injector']->getInstance('Horde_Ajax_Imple')->getImple(array('mnemo', 'EditNote'), array( + 'domid' => "noteBody" . $memo['memo_id'], + 'id' => $this->_params['note_uid'] + )); return $html; }