diff --git views_savedsearches.info views_savedsearches.info index aba78ad..18820d4 100644 --- views_savedsearches.info +++ views_savedsearches.info @@ -3,10 +3,14 @@ name = Saved searches description = Allows users to save their current configuration of exposed filters for later use. dependencies[] = views package = Views -core = 6.x +core = 7.x + +files[] = views_savedsearches.install +files[] = views_savedsearches.module + ; Information added by drupal.org packaging script on 2010-01-18 -version = "6.x-1.0-beta3" -core = "6.x" +version = "7.x-1.0-dev" +core = "7.x" project = "views_savedsearches" datestamp = "1263825607" diff --git views_savedsearches.install views_savedsearches.install index 005596b..5722967 100644 --- views_savedsearches.install +++ views_savedsearches.install @@ -2,13 +2,21 @@ // $Id: views_savedsearches.install,v 1.4 2010/01/14 13:48:24 aronnovak Exp $ /** + * @file + * This module allows you to save your current configuration of exposed + * filters for later use. This can be especially useful for Views with a lot + * of exposed filters. + * + */ + +/** * Implementation of hook_schema(). */ function views_savedsearches_schema() { $schema['views_savedsearches'] = array( 'fields' => array( 'sid' => array( - 'type' => 'int', + 'type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, ), @@ -22,6 +30,12 @@ function views_savedsearches_schema() { 'unsigned' => TRUE, 'not null' => TRUE, ), + 'view_name' => array( + 'type' => 'varchar', + 'length' => '32', + 'default' => '', + 'not null' => FALSE, + ), 'display' => array( 'type' => 'varchar', 'length' => '32', @@ -53,7 +67,7 @@ function views_savedsearches_update_6101() { * Implementation of hook_install(). */ function views_savedsearches_install() { - drupal_install_schema('views_savedsearches'); + // drupal_install_schema('views_savedsearches'); } /** diff --git views_savedsearches.js views_savedsearches.js index 0280fc2..7485f4a 100644 --- views_savedsearches.js +++ views_savedsearches.js @@ -1,90 +1,94 @@ // $Id: views_savedsearches.js,v 1.5 2009/12/18 15:28:45 aronnovak Exp $ -var ViewsSavedSearches = ViewsSavedSearches || {}; +(function ($) { + var ViewsSavedSearches = ViewsSavedSearches || {}; -ViewsSavedSearches.baseContext = function() { - var $baseContext; + ViewsSavedSearches.baseContext = function() { + var $baseContext; - if (undefined === $baseContext) { - $baseContext = $("div.views-savedsearches-container"); - } - return $baseContext; -}; + if (undefined === $baseContext) { + $baseContext = $("div.views-savedsearches-container"); + } + return $baseContext; + }; -ViewsSavedSearches.attachBindings = function() { - var view_name; - var i; + ViewsSavedSearches.attachBindings = function() { + var view_name; + var i; - for (i = 0; i < Drupal.settings.views_savedsearches.view_names.length; i++) { - view_name = Drupal.settings.views_savedsearches.view_names[i]; + for (i = 0; i < Drupal.settings.views_savedsearches.view_names.length; i++) { + view_name = Drupal.settings.views_savedsearches.view_names[i]; - // Attach the bindings. - ViewsSavedSearches.bindings(view_name); - } -} - -ViewsSavedSearches.bindings = function(view_name) { - function ahahDeleteBeforeSubmit(formData, jqForm, options) { - // Validate checkboxes: at least one must be checked. - if ($('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-list-ahah form:first :checkbox[@checked]').length == 0) { - alert("You must select at least one saved search to be deleted!"); - return false; + // Attach the bindings. + ViewsSavedSearches.bindings(view_name); } - - // The form is validated, it will be submitted. Now let's add the form - // data of the views filters form, to be able to check if we should - // display the save form. - formData.push({ name: 'views_filters_form', value: $('form#views-filters').formSerialize() }); - - return true; } - function ahahSaveBeforeSubmit(formData, jqForm, options) { - var $name = $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-save-ahah form:first input#edit-name'); + ViewsSavedSearches.bindings = function(view_name) { + function ahahDeleteBeforeSubmit(formData, jqForm, options) { + // Validate checkboxes: at least one must be checked. + if ($('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-list-ahah form:first :checkbox[@checked]').length == 0) { + alert(Drupal.t("You must select at least one saved search to be deleted!")); + return false; + } - // Validate the name field. - if ($name.fieldValue()[0].length == 0 || $name.fieldValue()[0].length > 30 ) { - alert("You must enter a name for this saved search (maximum 30 characters)!"); - return false; + // The form is validated, it will be submitted. Now let's add the form + // data of the views filters form, to be able to check if we should + // display the save form. + formData.push({ name: 'views_filters_form', value: $('form#views-filters').formSerialize() }); + + return true; } - // The form is validated, it will be submitted. Now let's add the form - // data of the views filters form, to save it. - formData.push({ name: 'views_filters_form', value: $('.view-'+ view_name+ ' .view-filters form').formSerialize() }); + function ahahSaveBeforeSubmit(formData, jqForm, options) { + var $name = $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-save-ahah form:first input#edit-name'); - return true; - } + // Validate the name field. + if ($name.fieldValue()[0].length == 0 || $name.fieldValue()[0].length > 30 ) { + alert(Drupal.t("You must enter a name for this saved search (maximum 30 characters)!")); + return false; + } - // The target container that will receive the updated filter.. - var container = $('div#view-'+ view_name +'-savedsearches-container').get(0); + // The form is validated, it will be submitted. Now let's add the form + // data of the views filters form, to save it. + formData.push({ name: 'views_filters_form', value: $('.view-'+ view_name+ ' .view-filters form').formSerialize() }); - // List (with delete saved search form). - var deleteOptions = { - url: Drupal.settings.views_savedsearches.paths.deletePath, - beforeSubmit: ahahDeleteBeforeSubmit, - target: container, - success: function(response, status) { - Drupal.attachBehaviors(container); + return true; } - }; - $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-list-ahah form:first', ViewsSavedSearches.baseContext) - .ajaxForm(deleteOptions); + // The target container that will receive the updated filter.. + var container = $('div#view-'+ view_name +'-savedsearches-container').get(0); + + // List (with delete saved search form). + var deleteOptions = { + url: Drupal.settings.views_savedsearches.paths.deletePath, + beforeSubmit: ahahDeleteBeforeSubmit, + target: container, + success: function(response, status) { + Drupal.attachBehaviors(container); + } + }; + + $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-list-ahah form:first', ViewsSavedSearches.baseContext) + .ajaxForm(deleteOptions); + + // Save search form. + var saveOptions = { + url: Drupal.settings.views_savedsearches.paths.savePath, + beforeSubmit: ahahSaveBeforeSubmit, + target: container, + success: function(response, status) { + Drupal.attachBehaviors(container); + } + }; + var saveForm = $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-save-ahah form:first', ViewsSavedSearches.baseContext); + $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-save-ahah form:first', ViewsSavedSearches.baseContext) + .ajaxForm(saveOptions); + } - // Save search form. - var saveOptions = { - url: Drupal.settings.views_savedsearches.paths.savePath, - beforeSubmit: ahahSaveBeforeSubmit, - target: container, - success: function(response, status) { - Drupal.attachBehaviors(container); + Drupal.behaviors.viewsSavedSearches = { + attach: function(context) { + ViewsSavedSearches.attachBindings(); } - }; - var saveForm = $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-save-ahah form:first', ViewsSavedSearches.baseContext); - $('div#view-'+ view_name +'-savedsearches-container div.views-savedsearches-save-ahah form:first', ViewsSavedSearches.baseContext) - .ajaxForm(saveOptions); -} - -Drupal.behaviors.viewsSavedSearches = function(context) { - ViewsSavedSearches.attachBindings(); -} + } +})(jQuery); \ No newline at end of file diff --git views_savedsearches.module views_savedsearches.module index 6ed2fc8..cd3535d 100644 --- views_savedsearches.module +++ views_savedsearches.module @@ -34,10 +34,10 @@ function views_savedsearches_help($path, $arg) { switch ($path) { case 'admin/help#views_savedsearches': - $output = '
'. t("The Views Saved Searches module allows users to save their current configuration of exposed filters for later use.") .'
'; + $output = '' . t("The Views Saved Searches module allows users to save their current configuration of exposed filters for later use.") . '
'; break; case 'admin/build/views/tools/saved-searches': - $output = ''. t('Note: Apologies for the bizarre location of this settings form. We\'re working to place the options for saving exposed filter searches in the main view configuration screen.') .'
'; + $output = '' . t('Note: Apologies for the bizarre location of this settings form. We\'re working to place the options for saving exposed filter searches in the main view configuration screen.') . '
'; break; } @@ -61,9 +61,9 @@ function views_savedsearches_menu() { 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); - $items['admin/build/views/tools/saved-searches'] = array( - 'title' => t('Saved Searches'), - 'description' => t('Configure which views support the saved searches functionality.'), + $items['admin/structure/views/saved-searches'] = array( + 'title' => 'Saved Searches', + 'description' => 'Configure which views support the saved searches functionality.', 'page callback' => 'drupal_get_form', 'page arguments' => array('views_savedsearches_settings'), 'access arguments' => array('administer site configuration'), @@ -91,8 +91,17 @@ function views_savedsearches_theme() { /** * Implementation of hook_perm(). */ -function views_savedsearches_perm() { - return array('use views savedsearch'); +function views_savedsearches_permission() { + return array( + 'use views savedsearch' => array( + 'title' => t('Use views saved searches'), + 'description' => t('User is allowed to use saved searches.'), + ), + 'use all savedsearches' => array( + 'title' => t('Use all saved searches'), + 'description' => t('User is allowed to use and see other users\' saved searches'), + ), + ); } /** @@ -141,7 +150,7 @@ function views_savedsearches_settings() { /** * Implementation of hook_form_alter(). */ -function views_savedsearches_form_alter(&$form, $form_state, $form_id) { +function views_savedsearches_form_alter(&$form, &$form_state, $form_id) { // Delete all saved searches whenever an edited View is saved. if ($form_id == 'views_edit_view') { $form['#submit'] = '_views_savedsearches_views_edit_form_submit'; @@ -149,44 +158,49 @@ function views_savedsearches_form_alter(&$form, $form_state, $form_id) { } /** - * Implementation of hook_block(). +* Implements hook_block_info(). +*/ +function views_savedsearches_block_info() { + // List blocks. + $blocks = array(); + $blocks['views-savedsearches-per-user'] = array( + 'info' => t('My views saved searches'), + ); + + return $blocks; +} + +/** + * Implementation of hook_block_view(). */ -function views_savedsearches_block($op = 'list', $delta = 0, $edit = array()) { +function views_savedsearches_block_view($delta = '') { global $user; + $block = array(); - if ('list' == $op) { - $blocks = array(); - $blocks['views-savedsearches-per-user'] = array( - 'info' => t('My views saved searches'), - ); - return $blocks; - } - elseif ('view' == $op) { - $block = array(); - switch ($delta) { - case 'views-savedsearches-per-user': - $uid = (arg(0) == 'user' && is_numeric(arg(1))) ? arg(1) : $user->uid; - $saved_searches = views_savedsearches_load_multiple($uid, 1); - foreach ($saved_searches as $sid => $saved_search) { - if (!empty($saved_search->display)) { - $query = _views_savedsearches_filters_to_params($saved_search->filters); - $view = views_get_view($saved_search->vid); - if (isset($view->display[$saved_search->display]->display_options['path'])) { - $path = $view->display[$saved_search->display]->display_options['path']; - if (!empty($path)) { - $items[] = l($saved_search->name, $path, array('query' => $query)); - } + switch ($delta) { + case 'views-savedsearches-per-user': + $uid = (arg(0) == 'user' && is_numeric(arg(1))) ? arg(1) : $user->uid; + $saved_searches = views_savedsearches_load_multiple($uid, 1); + $items = array(); + foreach ($saved_searches as $sid => $saved_search) { + if (!empty($saved_search->display)) { + $query = _views_savedsearches_filters_to_params($saved_search->filters); + $view = views_get_view($saved_search->vid); + if (isset($view->display[$saved_search->display]->display_options['path'])) { + $path = $view->display[$saved_search->display]->display_options['path']; + if (!empty($path)) { + $items[] = l($saved_search->name, $path, array('query' => $query)); } } } - if (count($items) > 0) { - $block = array('subject' => 'My saved searches', 'content' => theme('item_list', $items)); - } + } + if (count($items) > 0) { + $block = array('subject' => 'My saved searches', 'content' => theme('item_list', $items)); + } - break; - } - return $block; + break; } + return $block; } //---------------------------------------------------------------------------- @@ -203,8 +217,8 @@ function views_savedsearches_views_pre_view(&$view) { } $output = ''; - $output .= ''. t('No saved searches found for this view.') .'
'; + $output .= '' . t('No saved searches found for this view.') . '
'; } return $output;