Index: issue.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/issue.inc,v retrieving revision 1.172.2.17 diff --unified -r1.172.2.17 issue.inc --- issue.inc 9 Aug 2006 23:19:45 -0000 1.172.2.17 +++ issue.inc 21 Aug 2006 01:40:48 -0000 @@ -1,6 +1,5 @@ uid; default: - $project = project_project_retrieve(arg(2)); + $project = project_issue_build_form_url(arg(2)); if ($project->nid && node_access('view', $project)) { $query = new StdClass(); $query->projects = array($project->nid); @@ -62,6 +61,94 @@ } } +/** + * Sets up the javascript needed to avoid redirects on search form + * submits by changing the form's action based on the project chosen. + * + * @param $project_urls + * An array of project uri => id mappings + */ +function project_issue_setup_search_js($project_urls) { + + // set up the path that is the base of the form action + $site_base = dirname($_SERVER['PHP_SELF']); + $action_base = $site_base . (variable_get('clean_url', 0) ? '' : '?q=') .'project/issues/'; + + // add the path and the form id to the page + $js = "var projectIssue = {searchFormActionBase:'$action_base', + searchFormId:'project_issue_query_result_quick_search'}\n"; + + // setup the issue uri => nid array + array_walk($project_urls, create_function('&$v,$k', '$v = "{pid:$v,uri:\'$k\'}";')); + $js .= 'projectIssue.uriMap = ['. implode(',', $project_urls) ."]\n"; + + // add the js statements and include the project_issue js file + drupal_set_html_head(''); + drupal_add_js(drupal_get_path('module', 'project_issue') . '/project_issue.js'); +} + +/** + * Decides what to do with the request. + * + * - if this is not a POST, just returns project_project_retrieve + * - if this is a POST from a javascript-enabled form, returns + * project_project_retrieve + * - if this is a POST from a form without javascript, builds a + * url based on the value of the POST'ed search filters, and + * redirects the request to the new url + * + * @param $url_arg + * Value returned from arg(2) + */ +function project_issue_build_form_url($url_arg) { + + // if this isn't a POST, just return the project + if (empty($_POST)) { + return project_project_retrieve($url_arg); + } + + // if js is enabled in the browser, then $_POST['edit']['js'] == '1' + // and there's no need to redirect. 90% of the time, we end here + if (isset($_POST['edit']['js']) && $_POST['edit']['js'] == '1') { + foreach (array('states', 'categories', 'priorities') as $filter) { + if (isset($_POST['edit'][$filter])) { + $_REQUEST[$filter] = $_POST['edit'][$filter]; + if (isset($_GET[$filter])) { + unset($_GET[$filter]); + } + } + } + unset($_REQUEST['edit']); + + return project_project_retrieve($url_arg); + } + + // search is for all projects + if ($_POST['edit']['projects'] == 0) { + $destination = 'project/issues'; + } + else { + // try to find the project, and 404 if not found + if (!$project = project_project_retrieve($_POST['edit']['projects'])) { + drupal_not_found(); + exit; + } + $destination = 'project/issues/'. $project->uri; + } + + // catch anything else from the POST and put it in the url + $query_parts = array(); + foreach (array('states', 'categories', 'priorities') as $filter) { + if (isset($_POST['edit'][$filter])) { + $query_parts[] = $filter .'='. $_POST['edit'][$filter]; + } + } + $query_string = count($query_parts) ? '?'. implode('&', $query_parts) : ''; + + $_REQUEST['destination'] = $destination . $query_string; + drupal_goto(); +} + function project_issue_statistics($project = 0) { if ($project->nid) { $breadcrumb = array( @@ -304,7 +391,8 @@ $form['#suffix'] = ''; // Fetch a list of all projects to make swapping simpler - $projects = array(t('')) + project_projects_select_options(); + $uris = NULL; + $projects = array(t('')) + project_projects_select_options($uris); // Try to find the active project if (empty($node->pid) && $arg = arg(3)) { @@ -805,7 +893,8 @@ $versions = project_release_load($project, 0); } else { - $projects = project_projects_select_options(); + $uris = NULL; + $projects = project_projects_select_options($uris); } if (is_null($query)) { $query = new StdClass(); @@ -1145,11 +1234,12 @@ global $user; $query = project_issue_query_parse($query); // $query must have a real value now, or the rest of this function fails. - + $categories = array(0 => t('')) + project_issue_category(); $states = array(implode(',', array_keys(project_issue_state())) => t('')) + project_issue_state(); $priorities = array(0 => t('')) + project_issue_priority(); - $projects = array(0 => t('')) + project_projects_select_options(); + $project_urls = array(); + $projects = array(0 => t('')) + project_projects_select_options($project_urls); // Load active project if (count($query->projects) == 1) { @@ -1213,7 +1303,9 @@ $option[] = ${$field}[$value]; } $query->$field = implode(',', $query->$field); - ${$field}[$query->$field] = implode(',', $option); + if ($field != 'states') { + ${$field}[$query->$field] = implode(',', $option); + } } } @@ -1246,6 +1338,10 @@ '#type'=> 'hidden', '#value' => $query->users, ); + $form['js'] = array( + '#type'=> 'hidden', + '#value' => '0', + ); $form['submit'] = array( '#type' => 'button', '#value' => t('Search'), @@ -1300,7 +1396,7 @@ $rss = theme('feed_icon', url('project/issues/rss', project_issue_query_url($query))); $link = l(t('#'), 'project/issues', array('title' => t('Permalink to search query.')), project_issue_query_url($query)); - + if ($pager = theme('pager', NULL, 20, 0, $query)) { $rows[] = array(array('data' => $pager, 'colspan' => count($header))); } @@ -1309,6 +1405,11 @@ $rows[] = array(array('data' => t('No issues found.'), 'colspan'=> 8)); } + // setup the search form js + if ($format == 'html' && $search) { + project_issue_setup_search_js($project_urls); + } + $output = '
'; $output .= '