From 57d802eeb5684ef72e4840280c4015c6130c490c Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Wed, 12 Nov 2014 21:33:42 +0000 Subject: [PATCH] Home progress: - Fix changing position - Added a quick HTML note-to-self portlet --- home/inc/class.home_favorite_portlet.inc.php | 2 +- home/inc/class.home_note_portlet.inc.php | 166 +++++++++++++++++++ home/inc/class.home_ui.inc.php | 8 +- home/js/app.js | 46 ++++- home/templates/default/note.xet | 11 ++ 5 files changed, 229 insertions(+), 4 deletions(-) create mode 100644 home/inc/class.home_note_portlet.inc.php create mode 100644 home/templates/default/note.xet diff --git a/home/inc/class.home_favorite_portlet.inc.php b/home/inc/class.home_favorite_portlet.inc.php index cce4f99375..b3e7ff5f71 100644 --- a/home/inc/class.home_favorite_portlet.inc.php +++ b/home/inc/class.home_favorite_portlet.inc.php @@ -134,7 +134,7 @@ class home_favorite_portlet extends home_portlet return array( 'displayName'=> lang('Favorite'), 'title'=> $this->title, - 'description'=> lang('Show the entries from a favorite') + 'description'=> lang('Show all the entries using a favorite') ); } /** diff --git a/home/inc/class.home_note_portlet.inc.php b/home/inc/class.home_note_portlet.inc.php new file mode 100644 index 0000000000..8f19435c49 --- /dev/null +++ b/home/inc/class.home_note_portlet.inc.php @@ -0,0 +1,166 @@ + true + ); + + /** + * Context for this portlet + */ + public function __construct(Array &$context = array(), &$need_reload = false) + { + // Title not set for new widgets created via context menu + if(!$context['title']) + { + // Set initial size to 3x2, default is too small + $context['width'] = 3; + $context['height'] = 2; + + $need_reload = true; + } + $this->context = $context; + } + + /** + * Edit the note in a popup to accommodate CKEditor's CSP + * @param type $content + */ + public function edit($content = array()) + { + $id = $_GET['id'] ? $_GET['id'] : $content['id']; + $height = $_GET['height'] ? $_GET['height'] : $content['height']; + + $prefs = $GLOBALS['egw']->preferences->read_repository(); + $portlets = (array)$prefs['home']['portlets']; + + if($content['button']) + { + $portlets[$id]['note'] = $content['note']; + // Save updated preferences + $GLOBALS['egw']->preferences->add('home', 'portlets', $portlets); + $GLOBALS['egw']->preferences->save_repository(True); + // Yay for AJAX submit + egw_json_response::get()->apply('window.opener.app.home.refresh',array($id)); + + if(key($content['button'])=='save') + { + egw_json_response::get()->apply('window.close',array()); + } + } + $etemplate = new etemplate_new('home.note'); + + $content = array( + 'note' => $portlets[$id]['note'] + ); + $etemplate->setElementAttribute('note', 'width', '99%'); + $etemplate->setElementAttribute('note', 'height', $height); + $preserve = array( + 'id' => $id, + 'height' => $height, + ); + $etemplate->exec('home.home_note_portlet.edit',$content, array(),array('note'=>false,'save'=>false), $preserve); + } + + public function exec($id = null, etemplate_new &$etemplate = null) + { + // Allow to submit directly back here + if(is_array($id) && $id['id']) + { + $id = $id['id']; + } + if($etemplate == null) + { + $etemplate = new etemplate_new(); + } + $etemplate->read('home.note'); + + $etemplate->set_dom_id($id); + $content = $this->context; + + if(!$content['note']) + { + $content['note'] = ''; + } + + $etemplate->exec('home.home_note_portlet.exec',$content,array(),array('__ALL__'=>true),array('id' =>$id)); + } + + public function get_actions() + { + $actions = array( + 'edit' => array( + 'icon' => 'edit', + 'caption' => lang('edit'), + 'hideOnDisabled' => false, + 'onExecute' => 'javaScript:app.home.note_edit', + 'default' => true + ), + 'edit_settings' => array( + 'default' => false + ) + ); + return $actions; + } + + /** + * Return a list of settings to customize the portlet. + * + * Settings should be in the same style as for preferences. It is OK to return an empty array + * for no customizable settings. + * + * These should be already translated, no further translation will be done. + * + * @see preferences/inc/class.preferences_settings.inc.php + * @return Array of settings. Each setting should have the following keys: + * - name: Internal reference + * - type: Widget type for editing + * - label: Human name + * - help: Description of the setting, and what it does + * - default: Default value, for when it's not set yet + */ + public function get_properties() + { + $properties = parent::get_properties(); + + $properties[] = array( + 'name' => 'title', + 'type' => 'textbox', + 'label' => lang('Title'), + ); + // Internal - no type means it won't show in configure dialog + $properties[] = array( + 'name' => 'note' + ); + return $properties; + } + + public function get_description() + { + return array( + 'displayName'=> lang('Note'), + 'title'=> $this->context['title'], + 'description'=> lang('A quick note') + ); + } +} \ No newline at end of file diff --git a/home/inc/class.home_ui.inc.php b/home/inc/class.home_ui.inc.php index 82130a7fdb..a120199262 100644 --- a/home/inc/class.home_ui.inc.php +++ b/home/inc/class.home_ui.inc.php @@ -391,6 +391,11 @@ class home_ui { $prefs = $GLOBALS['egw']->preferences->read_repository(); $portlets = (array)$prefs['home']['portlets']; + if($values =='~reload~') + { + $full_exec = true; + $values = array(); + } if($values == '~remove~') { unset($portlets[$portlet_id]); @@ -408,8 +413,7 @@ class home_ui $add = true; $classname = substr($classname, 4); } - $full_exec = false; - $portlet = $this->get_portlet($portlet_id, $context, $content, $attributes); + $portlet = $this->get_portlet($portlet_id, $context, $content, $attributes, $full_exec); $context['class'] = get_class($portlet); foreach($portlet->get_properties() as $property) diff --git a/home/js/app.js b/home/js/app.js index 498bc73f26..9f96b3c757 100644 --- a/home/js/app.js +++ b/home/js/app.js @@ -249,6 +249,19 @@ app.classes.home = AppJS.extend( ); }, + /** + * Allow a refresh from anywhere by triggering an update with no changes + * + * @param {string} id + */ + refresh: function($id) { + var p = this.portlet_container.getWidgetById($id); + if(p) + { + p._process_edit(et2_dialog.OK_BUTTON, '~reload~'); + } + }, + /** * For link_portlet - opens the configured record when the user * double-clicks or chooses view from the context menu @@ -308,7 +321,7 @@ app.classes.home = AppJS.extend( */ serialize_params: function($w, grid) { return { - id: $w.children('.ui-widget-header').next().attr('id'), + id: $w.attr('id').replace(app.home.portlet_container.getInstanceManager().uniqueId+'_',''), row: grid.row, col: grid.col, width: grid.size_x, @@ -481,5 +494,36 @@ app.classes.home = AppJS.extend( portlet.options.settings.list.splice(row.index(), 1); portlet._process_edit(et2_dialog.OK_BUTTON,{list: portlet.options.settings.list || {}}); } + }, + + /** + * Functions for the note portlet + */ + /** + * Set up for editing a note + * CKEditor has CSP issues, so we need a popup + * + * @param {egwAction} action + * @param {egwActionObject[]} Selected + */ + note_edit: function(action, selected) { + var id = selected[0].id; + + // Aim to match the size + var portlet_dom = $j('[id$='+id+'][data-sizex]',this.portlet_container.getDOMNode); + var width = portlet_dom.attr('data-sizex') * this.GRID; + var height = portlet_dom.attr('data-sizey') * this.GRID; + + // CKEditor is impossible to use below a certain size + // Add 35px for the toolbar, 35px for the buttons + var window_width = Math.max(580, width+20); + var window_height = Math.max(350, height+70); + + // Open popup, but add 30 to the height for the toolbar + egw.open_link(egw.link('/index.php',{ + menuaction: 'home.home_note_portlet.edit', + id: selected[0].id, + height: window_height - 70 + }),action.id+selected[0].id, window_width+'x'+window_height,'home'); } }); diff --git a/home/templates/default/note.xet b/home/templates/default/note.xet new file mode 100644 index 0000000000..f11c030cad --- /dev/null +++ b/home/templates/default/note.xet @@ -0,0 +1,11 @@ + + + + \ No newline at end of file