From 25f4984ab49891a31b5d88f12760596dffeca28a Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 21 Jul 2014 15:21:08 +0000 Subject: [PATCH] Import/Export fixes from trunk --- ...ss.addressbook_export_contacts_csv.inc.php | 8 ++- .../class.importexport_definitions_bo.inc.php | 19 ++++++- .../class.importexport_definitions_ui.inc.php | 25 ++++++++-- .../inc/class.importexport_export_ui.inc.php | 3 ++ .../class.importexport_widget_filter.inc.php | 2 +- importexport/js/app.js | 49 +++++++++++++++++-- .../templates/default/definition_index.xet | 6 +-- .../templates/default/export_dialog.xet | 4 +- .../default/wizard_chooseallowedusers.xet | 8 +-- 9 files changed, 101 insertions(+), 23 deletions(-) diff --git a/addressbook/inc/class.addressbook_export_contacts_csv.inc.php b/addressbook/inc/class.addressbook_export_contacts_csv.inc.php index 275aa4a5be..e675ad43b2 100644 --- a/addressbook/inc/class.addressbook_export_contacts_csv.inc.php +++ b/addressbook/inc/class.addressbook_export_contacts_csv.inc.php @@ -100,8 +100,8 @@ class addressbook_export_contacts_csv implements importexport_iface_export_plugi } continue; } - // Custom fields & listed are not filtered with contact_ prefix - if(strpos($field, '#') !== 0 && !in_array($field, array('tid'))) + // Custom fields & listed exceptions are not filtered with contact_ prefix + if(strpos($field, '#') !== 0 && !in_array($field, array('tid','owner'))) { $field = 'contact_'.$field; } @@ -119,6 +119,10 @@ class addressbook_export_contacts_csv implements importexport_iface_export_plugi { $selection = explode(',',$options['selection']); } + if(!is_array($selection)) + { + $selection = array(); + } $GLOBALS['egw_info']['flags']['currentapp'] = $old_app; if(bo_merge::hasExportLimit($export_limit) && !$limit_exception) { diff --git a/importexport/inc/class.importexport_definitions_bo.inc.php b/importexport/inc/class.importexport_definitions_bo.inc.php index 15864e6cc2..8e31aa04f9 100644 --- a/importexport/inc/class.importexport_definitions_bo.inc.php +++ b/importexport/inc/class.importexport_definitions_bo.inc.php @@ -58,7 +58,24 @@ class importexport_definitions_bo { $sql .= ') OR owner = '.$GLOBALS['egw_info']['user']['account_id']; $query['col_filter'][] = $sql; } - + + // Handle allowed filter + if($query['col_filter']['allowed_users']) + { + $allowed = array(); + foreach((array)$query['col_filter']['allowed_users'] as $id) + { + $allowed[] = 'allowed_users '. + $GLOBALS['egw']->db->capabilities['case_insensitive_like'].' '. + $GLOBALS['egw']->db->quote('%,'.str_replace('_','\\_',$id) .',%'); + } + if($allowed) + { + unset($query['col_filter']['allowed_users']); + $query['col_filter'][] = '('.implode(' OR ', $allowed) . ')'; + } + } + $total = $this->so_sql->get_rows($query, $rows, $readonlys); $ro_count = 0; foreach($rows as &$row) { diff --git a/importexport/inc/class.importexport_definitions_ui.inc.php b/importexport/inc/class.importexport_definitions_ui.inc.php index fb8b716ffe..a9af27a3e1 100644 --- a/importexport/inc/class.importexport_definitions_ui.inc.php +++ b/importexport/inc/class.importexport_definitions_ui.inc.php @@ -170,11 +170,12 @@ class importexport_definitions_ui 'csv_fields' => false, // Disable CSV export, uses own export 'default_cols' => '!actions', // switch legacy actions column and row off by default 'row_id' => 'definition_id', - 'placeholder_actions' => array('add') + 'placeholder_actions' => array('add') ); if($_GET['application']) $content['nm']['col_filter']['application'] = $_GET['application']; } - if(egw_session::appsession('index', 'importexport')) { + if(egw_session::appsession('index', 'importexport')) + { $content['nm'] = array_merge($content['nm'], egw_session::appsession('index', 'importexport')); } $content['nm']['actions'] = $this->get_actions(); @@ -183,7 +184,10 @@ class importexport_definitions_ui 'import' => lang('import'), 'export' => lang('export'), ), - 'allowed_users' => array(null => lang('Private'), 'all' => lang('all')) + 'allowed_users' => array( + array('value' => 'private', 'label' => lang('Private')), + array('value' => 'all', 'label' => lang('all')) + ) ); foreach ($this->plugins as $appname => $options) { @@ -435,6 +439,13 @@ class importexport_definitions_ui public function get_rows(&$query, &$rows, &$readonlys) { $rows = array(); egw_session::appsession('index','importexport',$query); + + // Special handling for allowed users 'private' + if($query['col_filter']['allowed_users'] == 'private') + { + unset($query['col_filter']['allowed_users']); + $query['col_filter'][] = 'allowed_users = ' . $GLOBALS['egw']->db->quote(',,'); + } $bodefinitions = new importexport_definitions_bo($query['col_filter'], true); // We don't care about readonlys for the UI return $bodefinitions->get_rows($query, $rows, $discard); @@ -842,7 +853,7 @@ class importexport_definitions_ui // Set owner for non-admins $content['just_me'] = ((!$content['allowed_users'] || !$content['allowed_users'][0] && count($content['allowed_users']) ==1) && $content['owner']); $content['all_users'] = is_array($content['allowed_users']) && array_key_exists('0',$content['allowed_users']) && $content['allowed_users'][0] == 'all' || - $content['allowed_users'] == 'all'; + $content['allowed_users'] == 'all'; if(!$GLOBALS['egw']->acl->check('share_definition', EGW_ACL_READ, 'importexport') && !$GLOBALS['egw_info']['user']['apps']['admin']) { $content['allowed_users'] = array(); @@ -852,6 +863,12 @@ class importexport_definitions_ui $content['just_me'] = true; } + $sel_options = array( + 'allowed_users' => array( + array('value' => null, 'label' => lang('Just me')), + array('value' => 'all', 'label' => lang('all users')) + ) + ); // Hide 'just me' checkbox, users get confused by read-only if($readonlys['just_me'] || !$this->can_edit($content)) { diff --git a/importexport/inc/class.importexport_export_ui.inc.php b/importexport/inc/class.importexport_export_ui.inc.php index 02058de323..021626d580 100644 --- a/importexport/inc/class.importexport_export_ui.inc.php +++ b/importexport/inc/class.importexport_export_ui.inc.php @@ -224,6 +224,8 @@ class importexport_export_ui { $content['filter'][$field] = importexport_helper_functions::date_rel2abs($content['filter'][$field]); } } + // Filter is used twice in template, but can't have the same ID + $content['filter_html'] = $content['filter_tpl'] = $content['filter']; } } @@ -286,6 +288,7 @@ class importexport_export_ui { // Set filter // Note that because not all dates are DB dates, the plugin has to handle them $filter = array(); + $_content['filter'] = $_content['filter_html'] ? $_content['filter_html'] : $_content['filter_tpl']; if(is_array($_content['filter'])) { foreach($_content['filter'] as $key => $value) diff --git a/importexport/inc/class.importexport_widget_filter.inc.php b/importexport/inc/class.importexport_widget_filter.inc.php index 9792410e58..9014c5fd51 100644 --- a/importexport/inc/class.importexport_widget_filter.inc.php +++ b/importexport/inc/class.importexport_widget_filter.inc.php @@ -54,7 +54,7 @@ class importexport_widget_filter extends etemplate_widget_transformer error_log("$this has no fields"); self::$transformation = array( 'type' => 'label', - 'label' => 'No fields' + 'value' => 'No fields' ); return parent::beforeSendToClient($cname); } diff --git a/importexport/js/app.js b/importexport/js/app.js index d027ba0120..8b6e1b3635 100644 --- a/importexport/js/app.js +++ b/importexport/js/app.js @@ -88,9 +88,9 @@ app.classes.importexport = AppJS.extend( .show(100, jQuery.proxy(function() { widget.clicked = true; widget.getInstanceManager().submit(false, true); - widget.clicked = false; - $j(widget.getRoot().getWidgetById('preview_box').getDOMNode()) - .removeClass('loading'); + widget.clicked = false; + $j(widget.getRoot().getWidgetById('preview_box').getDOMNode()) + .removeClass('loading'); },this)); return false; }, @@ -114,5 +114,48 @@ app.classes.importexport = AppJS.extend( appname: data.application, definition: data.definition_id }), false, '850x440', app); + }, + + /** + * Allowed users widget has been changed, if 'All users' or 'Just me' + * was selected, turn off any other options. + */ + allowed_users_change: function(node, widget) + { + var value = widget.getValue(); + + // Only 1 selected, no checking needed + if(value.length <= 1) return; + + // Don't jump it to the top, it's weird + widget.selected_first = false; + + var index = null; + var specials = ['','all'] + for(var i = 0; i < specials.length; i++) + { + var special = specials[i]; + if((index = value.indexOf(special)) >= 0) + { + if(window.event.target.value == special) + { + // Just clicked all/private, clear the others + value = [special]; + } + else + { + // Just added another, clear special + value.splice(index,1); + } + + // A little highlight to call attention to the change + $j('input[value="'+special+'"]',node).parent().parent().effect('highlight',{},500); + break; + } + } + if(index >= 0) + { + widget.set_value(value); + } } }); \ No newline at end of file diff --git a/importexport/templates/default/definition_index.xet b/importexport/templates/default/definition_index.xet index 8515d4ff31..d44ced7a75 100644 --- a/importexport/templates/default/definition_index.xet +++ b/importexport/templates/default/definition_index.xet @@ -17,14 +17,14 @@ - - + + - + diff --git a/importexport/templates/default/export_dialog.xet b/importexport/templates/default/export_dialog.xet index b45fde4f9a..9a02a5cbbb 100644 --- a/importexport/templates/default/export_dialog.xet +++ b/importexport/templates/default/export_dialog.xet @@ -65,7 +65,7 @@ - + @@ -75,7 +75,7 @@