Skip to content

Commit

Permalink
new version of the module that is a generic version that should work …
Browse files Browse the repository at this point in the history
…with different stations
  • Loading branch information
Mark committed Jun 3, 2018
1 parent 77dc93a commit 0a33a83
Showing 28 changed files with 8,396 additions and 755 deletions.
9 changes: 9 additions & 0 deletions cm_crew_connect.css
Original file line number Diff line number Diff line change
@@ -18,4 +18,13 @@
Display: none;
}

div.cm-box {
background-color: #F2F2F2;
border: 1px solid #E3E3E3;
border-radius: 6px 6px 6px 6px;
margin: 1em 0;
max-width: 100%;
padding: .5em .5em 0;
position: relative;
}

26 changes: 20 additions & 6 deletions cm_crew_connect.info
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
name = "CMA Crew Connect"
name = "CM Crew Connect"
description = "Provides helper files for managing crew connections. Relies on the Crew Request and Crew Application content types"

scripts[] = cm_crew_connect.js

package = "Community Media"
version = 7.x-2.1
core = 7.x
project_status_url = https://github.com/cm-advanced/cm_crew_connect

files[] = includes/computed_field.inc
files[] = includes/civicrm.inc
files[] = includes/form_alter.inc
@@ -13,10 +20,17 @@ files[] = includes/postsave.inc
files[] = includes/presave.inc
files[] = includes/validate.inc
files[] = includes/view_util.inc
files[] = includes/rules_defaults.inc
files[] = includes/crew_connect_opportunity_type.csv
files[] = includes/crew_connect_position.csv
files[] = includes/crew-connect-bundle-export.txt


package = "Community Media Advanced"
version = "7.x-1.2"
core = "7.x"
project = "cm_crew_connect"
project_status_url = https://github.com/cm-advanced/cm_crew_connect
dependencies[] = bundle_copy
dependencies[] = civicrm
dependencies[] = entity
dependencies[] = entityreference
dependencies[] = rules
dependencies[] = views
dependencies[] = views_php

117 changes: 117 additions & 0 deletions cm_crew_connect.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php

/**
* Implements hook_install().
*/
function cm_crew_connect_install() {

// define path to includes dir because
// some api commands do not return correct
// values during an install
//$logpath = "/var/www/crewconnect-testing.phillycam.org/sites/all/modules/custom/cm_crew_connect/install.log";
// $path_to_drupal = drupal_realpath('cm_crew_connect.install');
$path_to_module = dirname(__FILE__);
$path_to_drupal = getcwd();
//echo "\n";
// $path_to_module = drupal_get_path('module', 'cm_crew_connect');
// $path_to_includes = $path_to_drupal."/".$path_to_module."/includes/";
$path_to_includes = $path_to_module."/includes/";
// echo $path_to_includes;
// create vocabularies
// file_put_contents($logpath, "test: \n", FILE_APPEND);
// file_put_contents($logpath, $path_to_includes."\n", FILE_APPEND);
// file_put_contents($logpath, $path_to_drupal."\n", FILE_APPEND);
// the module requires vocabularies with certain machine names
// for the term reference fields
// so these are hard coded
//
// but the terms can be anything so those are pulled
// from a text file in the module directory
// to allow for pre-install customization

// NOTE: this for now only works with flat vocabularies

cm_crew_connect_vocabulary_create("Crew Connect Position",
"crew_connect_position",
"CMA Crew Connect Module: position taxonomy"
);

cm_crew_connect_vocabulary_create("Crew Connect Opportunity Type",
"crew_connect_opportunity_type",
"CMA Crew Connect Module: opportunity type taxonomy"
);

// load file for Crew Connect Position terms
$crew_connect_position = array_map('str_getcsv', file($path_to_includes.'crew_connect_position.csv'));
// get vid
$crew_connect_position_vid = cm_crew_connect_vid_get("crew_connect_position");
// create terms
foreach ($crew_connect_position as $term) {
cm_crew_connect_term_create($crew_connect_position_vid,$term[0]);
}
$where = drupal_get_path('module', 'cm_crew_connect');
// load file for Crew Connect Position terms
$crew_connect_opportunity_type = array_map('str_getcsv', file($path_to_includes.'crew_connect_opportunity_type.csv'));

//dsm($crew_connect_opportunity_type);
// get vid
$crew_connect_opportunity_type_vid = cm_crew_connect_vid_get("crew_connect_opportunity_type");
// create terms
foreach ($crew_connect_opportunity_type as $term) {
cm_crew_connect_term_create($crew_connect_opportunity_type_vid,$term[0]);
}
//flush caches after taxonomy and term creation
// drupal_flush_all_caches();
//get the contents of the bundle export content type definitions
$bundles = file_get_contents($path_to_includes.'crew-connect-bundle-export.txt');
// setup a form array and call the bundle import submit function
// dsm($bundles);
$form=array();
$form_state=array();
$form_state['values']['macro']=$bundles;
bundle_copy_import_submit($form,$form_state);
//flush caches after content type creation
$result = db_truncate('cache_rules')->execute();
drupal_flush_all_caches();
cache_clear_all();
}


/**
* other helper functions
*/

// creates vocabulary
function cm_crew_connect_vocabulary_create($name, $machine_name, $description) {
// Create an empty flat vocabulary with default Drupal 7 fields.
//
$vocabulary = (object) array(
'name' => $name,
'machine_name' => $machine_name,
'description' => $description,
'hierarchy' => 1,
'module' => 'taxonomy',
'weight' => 0,
);

$result = taxonomy_vocabulary_save($vocabulary);
return $result;
}

// returns vid from machine name
function cm_crew_connect_vid_get($machine_name) {
$vocab = taxonomy_vocabulary_machine_name_load($machine_name);
$vid = $vocab->vid;
return $vid;
}

// creates new term
function cm_crew_connect_term_create($vid,$term) {
$newterm = new stdClass();
$newterm->name = $term;
$newterm->vid = $vid;
$newterm->parent = 0; // This tells taxonomy that this is a top-level term
$result = taxonomy_term_save($newterm);
return $result;
}

90 changes: 90 additions & 0 deletions cm_crew_connect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
(function ($) {
Drupal.behaviors.crewConnectPositions = {
attach: function (context, settings) {
////////////////////////////////////////////////////////////////////////
//ON READY FUNCTION
$(document).ready(function() {
var should_filter =
$('input[name=crew_connect_filter_positions]').val();

if (should_filter == 'yes') {
cmCrewConnectConditionalSelects();
}
});
////////////////////////////////////////////////////////////////////////
//CHANGE FUNCTION FOR VOLUNTEER TYPE FIELD
$("select[id$='edit-field-crew-opportunity-type-und']", context).
change(function() {
var should_filter =
$('input[name=crew_connect_filter_positions]').val();

if (should_filter == 'yes') {
cmCrewConnectConditionalSelects();
}
});

////////////////////////////////////////////////////////////////////////
//FUNCTION WILL HANDLE INTERACTIONS BETWEEN POSITION AND OPPORTUNITY TYPE
function cmCrewConnectConditionalSelects() {
var $pos_select = $('#edit-field-crew-position-taxonomy-und');
var opp_type = $('#edit-field-crew-opportunity-type-und').val();
var position = $('#edit-field-crew-position-taxonomy-und').val();

console.log('OPP TYPE: ' + opp_type);
console.log('POSITION: ' + position);

if (opp_type == '_none') {
$('#edit-field-crew-position-taxonomy').hide();
}
else {
var cm_url = '/admin/crew_connect/positions?opp_type=' + opp_type;
console.log(cm_url);
//REMOVE CURRENT OPTIONS, REPLACE WITH OPTIONS FROM AJAX CALL
$pos_select.empty();
if (position == '_none') {
$pos_select.append($("<option></option>")
.attr("value", '_none')
.attr('selected', true)
.text('- Select a value -'));

}

$.getJSON(cm_url, function(data){
if (position && position != '_none') {
var invalid_position = 1;
$.each(data, function(i,item){
if (item.id==position) {
invalid_position = 0;
}
});
console.log('invalid position: ' + invalid_position);
if (invalid_position) {
$pos_select.append($("<option></option>")
.attr("value", '_none')
.attr('selected', true)
.text('- Select a value -'));

}
}
$.each(data, function(i,item){
if (item.id==position) {
$pos_select.append($("<option></option>")
.attr("value", item.id)
.attr('selected', true)
.text(item.label));
}
else {
$pos_select.append($("<option></option>")
.attr("value", item.id)
.text(item.label));
}

});
});

$('#edit-field-crew-position-taxonomy').show();
}
}
}};
}) (jQuery);

Loading

0 comments on commit 0a33a83

Please sign in to comment.