Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup, fix various bugs. #1

Open
wants to merge 1 commit into
base: v7.x-3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 28 additions & 35 deletions reservations_project_suggestor.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
(function ($) {

Drupal.behaviors.reservationsProjectPopulate = {
attach: function (context, settings) {
Drupal.behaviors.reservationsProjectPopulate = {
attach: function (context, settings) {
$('.rps_pick', context).live('click', function() {
var project_button_id = $(this).attr('id').substring(16);
var project_title = $(this).attr('name');
var project_button_id = $(this).attr('id').substring(16);
var project_title = $(this).attr('name');

$("input[id^=edit-field-og-node1-und-0-admin-0-target-id]").each(function() {
$(this).focus();
$(this).val(project_title + " (" + project_button_id + ")");
$(this).blur();
});
});
}
};

Drupal.behaviors.reservationsProjectSuggestor = {
attach: function (context, settings) {
$('#rps_button', context).click(function() {
$('#project_suggestor_div').html("<h2>Loading...</h2>");

$("input[id^=edit-og-node1-und-0-admin-0-target-id]").
each(function() {
$("input[id^=edit-name]").each(function() {
if ($(this).attr('type') == 'text') {
var cm_agd_url = '/reservations_project_suggestor_detail/' + $(this).attr('value');

$(this).focus();
$(this).val(project_title+" ("+project_button_id+")");
$(this).blur();

});
});
}
};
Drupal.behaviors.reservationsProjectSuggestor = {
attach: function (context, settings) {
$('#rps_button', context).click(function() {
$('#project_suggestor_div').html("<h2>Loading...</h2>");
$("input[id^=edit-name]").each(function() {
if ($(this).attr('type') == 'text') {
var cm_agd_url =
'/reservations_project_suggestor_detail/'
+ $(this).attr('value')

$.getJSON(cm_agd_url, function(data){
$('#project_suggestor_div').html(data.projects);

});
}
});
});
}
};
$.getJSON(cm_agd_url, function(data){
$('#project_suggestor_div').html(data.projects);
});
}
});
});
}
};
}) (jQuery);

56 changes: 30 additions & 26 deletions reservations_project_suggestor.module
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,33 @@
/**
* @file
* Code for the Reservations Project Suggestor. This module will use AJAX to
populate a div of the user's projects upon selection fo the Admin project
field
* populate a div of the user's projects upon selection fo the Admin project
* field
*/

define('ORGANIC_GROUPS_ADMIN_PROJECT_FIELD_ID',
'edit-og-node1-und-0-admin-0-target-id');
define('ORGANIC_GROUPS_ADMIN_PROJECT_FIELD_ID', 'edit-og-node1-und-0-admin-0-target-id');

/**
* Implements hook_init().
*/
function reservations_project_suggestor_init() {
drupal_add_css(drupal_get_path('module', 'reservations_project_suggestor') .
'/reservations_project_suggestor.css');
$module_path = drupal_get_path('module', 'reservations_project_suggestor');
drupal_add_css($module_path . '/reservations_project_suggestor.css');
}

function reservations_project_suggestor_form_alter(&$form, &$form_state,
$form_id) {
/**
* Implements HOOK_form_alter().
*/
function reservations_project_suggestor_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'reservations_reservation_node_form') {
if (user_access('manage reservations')) {
$html = '<input type="button" id="rps_button" '.
'value="Suggest Projects">'.
'<div id="project_suggestor_div"></div>';


$html = '<input type="button" id="rps_button" class="form-submit" value="Suggest Projects">';
$html .= '<div id="project_suggestor_div"></div>';
$form['og_node1']['#prefix'] = $html;
}

}
}


/**
* Implements hook_menu()
*/
Expand All @@ -47,9 +43,15 @@ function reservations_project_suggestor_menu() {
return $items;
}

/**
* AJAX callback to produce the list of projects.
*/
function reservations_project_suggestor_ajax_callback($user_name) {
// Add js functionality.
$js_settings = drupal_add_js('sites/all/modules/contrib-cm/reservations_project_suggestor.js');


// Initialize the output.
$html = '';

$user = user_load_by_name($user_name);
if ($user) {
Expand All @@ -65,20 +67,18 @@ function reservations_project_suggestor_ajax_callback($user_name) {

$has_results = FALSE;
while ($result = $results->fetchObject()) {
$has_results = TRUE;
$gid = $result->gid;
$project = node_load($gid);
$status = $project->group_group[LANGUAGE_NONE][0]['value'];
$inactive_reason =
$project->field_reason_not_active[LANGUAGE_NONE][0]['tid'];

if ($project && $status && !$inactive_reason) {
$html .= '<input type="button" id="rps_proj_button_'.$gid.'" '.
'class="rps_pick" value="Pick" name="'.$project->title.'"> ';
$html .= "<strong>".$project->title." ($gid) </strong><br/><br/>";
if($project && $status) {
$has_results = TRUE;
$html .= '<input type="button" id="rps_proj_button_' . $gid . '" ' .
'class="rps_pick form-submit" value="Pick" name="' . $project->title . '"> ';
$html .= "<strong>" . $project->title . " ($gid) </strong><br/><br/>";
}
}

if ($has_results) {
$output = "<br/><h2>Projects for <strong>$user_name</strong></h2>";
$output .= $html;
Expand All @@ -89,5 +89,9 @@ function reservations_project_suggestor_ajax_callback($user_name) {
$output = "<br/>No projects found for <strong>$user_name</strong>";
}

return drupal_json_output(array('projects'=>$output));
}
return drupal_json_output(
array(
'projects' => $output,
)
);
}