Skip to content

Commit 0a33a83

Browse files
author
Mark
committed
new version of the module that is a generic version that should work with different stations
1 parent 77dc93a commit 0a33a83

28 files changed

+8396
-755
lines changed

cm_crew_connect.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,13 @@
1818
Display: none;
1919
}
2020

21+
div.cm-box {
22+
background-color: #F2F2F2;
23+
border: 1px solid #E3E3E3;
24+
border-radius: 6px 6px 6px 6px;
25+
margin: 1em 0;
26+
max-width: 100%;
27+
padding: .5em .5em 0;
28+
position: relative;
29+
}
2130

cm_crew_connect.info

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
name = "CMA Crew Connect"
1+
name = "CM Crew Connect"
22
description = "Provides helper files for managing crew connections. Relies on the Crew Request and Crew Application content types"
33

4+
scripts[] = cm_crew_connect.js
5+
6+
package = "Community Media"
7+
version = 7.x-2.1
8+
core = 7.x
9+
project_status_url = https://github.com/cm-advanced/cm_crew_connect
10+
411
files[] = includes/computed_field.inc
512
files[] = includes/civicrm.inc
613
files[] = includes/form_alter.inc
@@ -13,10 +20,17 @@ files[] = includes/postsave.inc
1320
files[] = includes/presave.inc
1421
files[] = includes/validate.inc
1522
files[] = includes/view_util.inc
23+
files[] = includes/rules_defaults.inc
24+
files[] = includes/crew_connect_opportunity_type.csv
25+
files[] = includes/crew_connect_position.csv
26+
files[] = includes/crew-connect-bundle-export.txt
1627

1728

18-
package = "Community Media Advanced"
19-
version = "7.x-1.2"
20-
core = "7.x"
21-
project = "cm_crew_connect"
22-
project_status_url = https://github.com/cm-advanced/cm_crew_connect
29+
dependencies[] = bundle_copy
30+
dependencies[] = civicrm
31+
dependencies[] = entity
32+
dependencies[] = entityreference
33+
dependencies[] = rules
34+
dependencies[] = views
35+
dependencies[] = views_php
36+

cm_crew_connect.install

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
3+
/**
4+
* Implements hook_install().
5+
*/
6+
function cm_crew_connect_install() {
7+
8+
// define path to includes dir because
9+
// some api commands do not return correct
10+
// values during an install
11+
//$logpath = "/var/www/crewconnect-testing.phillycam.org/sites/all/modules/custom/cm_crew_connect/install.log";
12+
// $path_to_drupal = drupal_realpath('cm_crew_connect.install');
13+
$path_to_module = dirname(__FILE__);
14+
$path_to_drupal = getcwd();
15+
//echo "\n";
16+
// $path_to_module = drupal_get_path('module', 'cm_crew_connect');
17+
// $path_to_includes = $path_to_drupal."/".$path_to_module."/includes/";
18+
$path_to_includes = $path_to_module."/includes/";
19+
// echo $path_to_includes;
20+
// create vocabularies
21+
// file_put_contents($logpath, "test: \n", FILE_APPEND);
22+
// file_put_contents($logpath, $path_to_includes."\n", FILE_APPEND);
23+
// file_put_contents($logpath, $path_to_drupal."\n", FILE_APPEND);
24+
// the module requires vocabularies with certain machine names
25+
// for the term reference fields
26+
// so these are hard coded
27+
//
28+
// but the terms can be anything so those are pulled
29+
// from a text file in the module directory
30+
// to allow for pre-install customization
31+
32+
// NOTE: this for now only works with flat vocabularies
33+
34+
cm_crew_connect_vocabulary_create("Crew Connect Position",
35+
"crew_connect_position",
36+
"CMA Crew Connect Module: position taxonomy"
37+
);
38+
39+
cm_crew_connect_vocabulary_create("Crew Connect Opportunity Type",
40+
"crew_connect_opportunity_type",
41+
"CMA Crew Connect Module: opportunity type taxonomy"
42+
);
43+
44+
// load file for Crew Connect Position terms
45+
$crew_connect_position = array_map('str_getcsv', file($path_to_includes.'crew_connect_position.csv'));
46+
// get vid
47+
$crew_connect_position_vid = cm_crew_connect_vid_get("crew_connect_position");
48+
// create terms
49+
foreach ($crew_connect_position as $term) {
50+
cm_crew_connect_term_create($crew_connect_position_vid,$term[0]);
51+
}
52+
$where = drupal_get_path('module', 'cm_crew_connect');
53+
// load file for Crew Connect Position terms
54+
$crew_connect_opportunity_type = array_map('str_getcsv', file($path_to_includes.'crew_connect_opportunity_type.csv'));
55+
56+
//dsm($crew_connect_opportunity_type);
57+
// get vid
58+
$crew_connect_opportunity_type_vid = cm_crew_connect_vid_get("crew_connect_opportunity_type");
59+
// create terms
60+
foreach ($crew_connect_opportunity_type as $term) {
61+
cm_crew_connect_term_create($crew_connect_opportunity_type_vid,$term[0]);
62+
}
63+
//flush caches after taxonomy and term creation
64+
// drupal_flush_all_caches();
65+
//get the contents of the bundle export content type definitions
66+
$bundles = file_get_contents($path_to_includes.'crew-connect-bundle-export.txt');
67+
// setup a form array and call the bundle import submit function
68+
// dsm($bundles);
69+
$form=array();
70+
$form_state=array();
71+
$form_state['values']['macro']=$bundles;
72+
bundle_copy_import_submit($form,$form_state);
73+
//flush caches after content type creation
74+
$result = db_truncate('cache_rules')->execute();
75+
drupal_flush_all_caches();
76+
cache_clear_all();
77+
}
78+
79+
80+
/**
81+
* other helper functions
82+
*/
83+
84+
// creates vocabulary
85+
function cm_crew_connect_vocabulary_create($name, $machine_name, $description) {
86+
// Create an empty flat vocabulary with default Drupal 7 fields.
87+
//
88+
$vocabulary = (object) array(
89+
'name' => $name,
90+
'machine_name' => $machine_name,
91+
'description' => $description,
92+
'hierarchy' => 1,
93+
'module' => 'taxonomy',
94+
'weight' => 0,
95+
);
96+
97+
$result = taxonomy_vocabulary_save($vocabulary);
98+
return $result;
99+
}
100+
101+
// returns vid from machine name
102+
function cm_crew_connect_vid_get($machine_name) {
103+
$vocab = taxonomy_vocabulary_machine_name_load($machine_name);
104+
$vid = $vocab->vid;
105+
return $vid;
106+
}
107+
108+
// creates new term
109+
function cm_crew_connect_term_create($vid,$term) {
110+
$newterm = new stdClass();
111+
$newterm->name = $term;
112+
$newterm->vid = $vid;
113+
$newterm->parent = 0; // This tells taxonomy that this is a top-level term
114+
$result = taxonomy_term_save($newterm);
115+
return $result;
116+
}
117+

cm_crew_connect.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
(function ($) {
2+
Drupal.behaviors.crewConnectPositions = {
3+
attach: function (context, settings) {
4+
////////////////////////////////////////////////////////////////////////
5+
//ON READY FUNCTION
6+
$(document).ready(function() {
7+
var should_filter =
8+
$('input[name=crew_connect_filter_positions]').val();
9+
10+
if (should_filter == 'yes') {
11+
cmCrewConnectConditionalSelects();
12+
}
13+
});
14+
////////////////////////////////////////////////////////////////////////
15+
//CHANGE FUNCTION FOR VOLUNTEER TYPE FIELD
16+
$("select[id$='edit-field-crew-opportunity-type-und']", context).
17+
change(function() {
18+
var should_filter =
19+
$('input[name=crew_connect_filter_positions]').val();
20+
21+
if (should_filter == 'yes') {
22+
cmCrewConnectConditionalSelects();
23+
}
24+
});
25+
26+
////////////////////////////////////////////////////////////////////////
27+
//FUNCTION WILL HANDLE INTERACTIONS BETWEEN POSITION AND OPPORTUNITY TYPE
28+
function cmCrewConnectConditionalSelects() {
29+
var $pos_select = $('#edit-field-crew-position-taxonomy-und');
30+
var opp_type = $('#edit-field-crew-opportunity-type-und').val();
31+
var position = $('#edit-field-crew-position-taxonomy-und').val();
32+
33+
console.log('OPP TYPE: ' + opp_type);
34+
console.log('POSITION: ' + position);
35+
36+
if (opp_type == '_none') {
37+
$('#edit-field-crew-position-taxonomy').hide();
38+
}
39+
else {
40+
var cm_url = '/admin/crew_connect/positions?opp_type=' + opp_type;
41+
console.log(cm_url);
42+
//REMOVE CURRENT OPTIONS, REPLACE WITH OPTIONS FROM AJAX CALL
43+
$pos_select.empty();
44+
if (position == '_none') {
45+
$pos_select.append($("<option></option>")
46+
.attr("value", '_none')
47+
.attr('selected', true)
48+
.text('- Select a value -'));
49+
50+
}
51+
52+
$.getJSON(cm_url, function(data){
53+
if (position && position != '_none') {
54+
var invalid_position = 1;
55+
$.each(data, function(i,item){
56+
if (item.id==position) {
57+
invalid_position = 0;
58+
}
59+
});
60+
console.log('invalid position: ' + invalid_position);
61+
if (invalid_position) {
62+
$pos_select.append($("<option></option>")
63+
.attr("value", '_none')
64+
.attr('selected', true)
65+
.text('- Select a value -'));
66+
67+
}
68+
}
69+
$.each(data, function(i,item){
70+
if (item.id==position) {
71+
$pos_select.append($("<option></option>")
72+
.attr("value", item.id)
73+
.attr('selected', true)
74+
.text(item.label));
75+
}
76+
else {
77+
$pos_select.append($("<option></option>")
78+
.attr("value", item.id)
79+
.text(item.label));
80+
}
81+
82+
});
83+
});
84+
85+
$('#edit-field-crew-position-taxonomy').show();
86+
}
87+
}
88+
}};
89+
}) (jQuery);
90+

0 commit comments

Comments
 (0)