Skip to content

Commit

Permalink
the jquery-ui autocomplete prototype for reassign actions.
Browse files Browse the repository at this point in the history
jquery-ui is pretty easy to use!
  • Loading branch information
seanchen committed Jan 27, 2013
1 parent f1a6a3f commit 1110cf7
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 6 deletions.
24 changes: 24 additions & 0 deletions wp-trac-client/ajax.php
@@ -1,5 +1,29 @@
<?php

/**
*
*/
add_action('wp_ajax_nopriv_wptc_username_autocomplete', 'wptc_username_suggestion_cb');
add_action('wp_ajax_wptc_username_autocomplete', 'wptc_username_suggestion_cb');
function wptc_username_suggestion_cb() {

$searchTerm = $_POST['term'];
// query wp_users table for the given term.
$users = array("abc", "cde");

$suggestions = array();
foreach($users as $user) {
$suggestion = array();
$suggestion['label'] = 'Display Name - Email';
$suggestion['value'] = 'user_login';
$suggestions[] = $suggestion;
}

$response = $_GET["callback"] . "(" . json_encode($suggestions) . ")";
echo $response;
exit;
}

/**
* the ajax wrappers for the trac functions
* The _cb suffix stands for Call Back
Expand Down
5 changes: 5 additions & 0 deletions wp-trac-client/css/trac_ticket.css
Expand Up @@ -388,3 +388,8 @@ h1 span, h2 span { color: gray; font-size: 90%;}
font-size: 80%;
margin-top: 14px;
}

/* auto complete loading */
.ui-autocomplete-loading {
background: white url('../images/ui-anim_basic_16x16.gif') right center no-repeat;
}
Binary file added wp-trac-client/images/ui-anim_basic_16x16.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 17 additions & 1 deletion wp-trac-client/js/trac-wikitoolbar.js
@@ -1,6 +1,7 @@

(function($){


// trac wiki toolbar
window.addWikiFormattingToolbar = function(textarea) {
if ((document.selection == undefined)
&& (textarea.setSelectionRange == undefined)) {
Expand Down Expand Up @@ -124,6 +125,21 @@ jQuery(document).ready(function($) {
// attach folding function to foldable class.
$(".foldable").enableFolding(false, true);

// username auto complete for re-assign action.
var wptc_username_ac = "wptc_username_autocomplete"
$("#action_reassign_reassign_owner").autocomplete({
source: function(request, response) {
$.getJSON(WptcAjaxObj.url + "?callback=?&action=" +
wptc_username_ac, request, response);
},
minLength: 2,
select: function(event, ui) {
// selected value could get from ui param.
// ui.item.id, ui.item.value.
alert (ui.item.value);
}
});

// only enable control elements for
// the currently selected action
var actions = $("#action input[name='action']");
Expand Down
4 changes: 4 additions & 0 deletions wp-trac-client/templates/page-ticket-details.php
Expand Up @@ -3,9 +3,13 @@
* Template Name: Trac Ticket Details
* Description: a page to show the details for a ticket.
*/
wp_enqueue_script('jquery-ui-autocomplete');
// enqueue styles and scripts for trac project.
wp_enqueue_style('wptc-trac-ticket');
wp_enqueue_script('wptc-trac-wikitoolbar');
wp_localize_script('wptc-trac-wikitoolbar', 'WptcAjaxObj',
array('url' => admin_url('admin-ajax.php')));
wp_enqueue_style('jquery-ui');

// you may not need the following section if you
// don't have tiny-mce comments plugin installed.
Expand Down
7 changes: 3 additions & 4 deletions wp-trac-client/widgets.php
Expand Up @@ -469,14 +469,13 @@ function wptc_widget_action_resolve($action) {
function wptc_widget_action_reassign($action) {

$fields = $action[3][0];
$options = wptc_widget_options_html($fields[2], $fields[1]);
//$options = wptc_widget_options_html($fields[2], $fields[1]);
// the resolve is a select element.
// it will be disabled untile the radio button is selected.
$select = <<<EOT
to
<select name="{$fields[0]}" id="{$fields[0]}" disabled="">
{$options}
</select>
<input name="action_reassign_reassign_owner" id="action_reassign_reassign_owner" disabled="">
{$options}
EOT;

return apply_filters('wptc_widget_action_reassign', $select);
Expand Down
5 changes: 4 additions & 1 deletion wp-trac-client/wp-trac-client.php
Expand Up @@ -87,7 +87,10 @@ function register_resources() {
// using wp_enqueue_style to load this css.
// jquery ui dialog style seens not automatically loaded.
wp_register_style('jquery-ui',
'https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css');
'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css');
// javascript for autocomplete.
wp_register_script('wptc-autocomplete',
plugins_url('wt-trac-client/js/wptc-autocomplete.js'));
}

function get_wptc_client() {
Expand Down

0 comments on commit 1110cf7

Please sign in to comment.