Skip to content

Commit

Permalink
updated info file
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark committed Jun 12, 2017
0 parents commit 4ade908
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 0 deletions.
Empty file.
12 changes: 12 additions & 0 deletions reservations_project_suggestor.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name = CMA Reservations Project Suggestor
description = This module will use AJAX to populate a dive of the user's projects upon selection of the Admin project field

dependencies[] = reservations

scripts[] = reservations_project_suggestor.js

package = "Community Media Advanced"
version = "7.x-3.x"
core = "7.x"
project = "reservations_project_suggestor"
project_status_url = https://github.com/cm-advanced/reservations_project_suggestor
41 changes: 41 additions & 0 deletions reservations_project_suggestor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(function ($) {

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');


$("input[id^=edit-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-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);

});
}
});
});
}
};
}) (jQuery);

93 changes: 93 additions & 0 deletions reservations_project_suggestor.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/**
* @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
*/

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');
}

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>';


$form['og_node1']['#prefix'] = $html;
}

}
}


/**
* Implements hook_menu()
*/
function reservations_project_suggestor_menu() {
$items['reservations_project_suggestor_detail/%'] = array(
'page callback' => 'reservations_project_suggestor_ajax_callback',
'page arguments' => array(1),
'access arguments' => array('create reservations_reservation content'),
'type' => MENU_CALLBACK,
);

return $items;
}

function reservations_project_suggestor_ajax_callback($user_name) {
$js_settings = drupal_add_js('sites/all/modules/contrib-cm/reservations_project_suggestor.js');


$user = user_load_by_name($user_name);
if ($user) {
$uid = $user->uid;
$sql = "SELECT gid
FROM {og_membership} m
INNER JOIN {node} n ON n.nid=m.gid
WHERE entity_type = 'user'
AND etid= :uid
ORDER BY n.title
";
$results = db_query($sql, array(':uid' => $uid));

$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 ($has_results) {
$output = "<br/><h2>Projects for <strong>$user_name</strong></h2>";
$output .= $html;
}
}

if (!isset($output)) {
$output = "<br/>No projects found for <strong>$user_name</strong>";
}

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

0 comments on commit 4ade908

Please sign in to comment.