Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
vmichnowicz committed Feb 15, 2012
2 parents 9c11168 + 539a648 commit 515bafb
Show file tree
Hide file tree
Showing 21 changed files with 408 additions and 115 deletions.
12 changes: 7 additions & 5 deletions config/vwm_surveys.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
// Available question types
$config['vwm_surveys_question_types'] = array(
'checkboxes' => 'Checkboxes',
'radio_matrix' => 'Radio Matrix',
'radios' => 'Radios',
'text' => 'Text',
'textarea' => 'Textarea',
'date' => 'Date',
// 'time' => 'Time',
// 'datetime' => 'Datetime'
'radios' => 'Radios',
'radio_matrix' => 'Radio Matrix',
// 'rating' => 'Rating',
// 'rating_matrix' => 'Rating Matrix',
'text' => 'Text',
'textarea' => 'Textarea'
// 'time' => 'Time'
);

// Date formats for vwm_date question type
Expand Down
1 change: 1 addition & 0 deletions css/mcp.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Edit survey
position: relative;
background-color: #b2bec0;
border: 1px solid #999;
box-shadow: 1px 1px 0px #d2dee0 inset, -1px -1px 0px #d2dee0 inset;
border-radius: 5px;
padding: 10px;
margin: 15px 0px;
Expand Down
115 changes: 50 additions & 65 deletions helpers/vwm_date_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,84 +15,69 @@ function vwm_date_validate($id, $input, $options)
$later_than = $options['later_than'] != '' ? new DateTime( $options['later_than'] ) : NULL;
$earlier_than = $options['earlier_than'] != '' ? new DateTime( $options['earlier_than'] ) : NULL;

// Determine format conversion
switch ($format)
{
// Lots of people
case 'DD/MM/YYYY':
$string_format = 'd#m#Y';
$display_format = 'd-n-Y';
break;
// 'merica!
case 'MM/DD/YYYY':
$string_format = 'm#d#Y';
$display_format = 'n-d-Y';
break;
// Default to YYYY/MM/DD format cuz it is the most logical
default:
$string_format = 'Y#m#d';
$display_format = 'Y-n-d';
break;
}

// The only user input is from the sole date input
$data['date'] = trim($input);

// Split date string by slashes, dots, & hyphens
$date_array = preg_split('/[.,\/ -]/', $data['date']);

// We must have three segments for a valid date
if ( count($date_array) != 3 )

// Attempt to create date object from user provided input
try
{
$data['errors'][] = 'Invalid date provided.';
$date_obj = DateTime::createFromFormat($string_format, $data['date']);
}
// We have at least three segments
else
catch (Exception $e)
{
$date = $month = $year = NULL;
$data['errors'][] = 'Invalid date provided.';
}

switch ($format)
{
// Lots of people
case 'DD/MM/YYYY':
$year = $date_array[2];
$month = $date_array[1];
$day = $date_array[0];
$format_conversion = 'j-n-Y';
break;
// 'merica!
case 'MM/DD/YYYY':
$year = $date_array[2];
$month = $date_array[0];
$day = $date_array[1];
$format_conversion = 'n-j-Y';
break;
// Default to YYYY/MM/DD format cuz it is the most logical
default:
$year = $date_array[0];
$month = $date_array[1];
$day = $date_array[2];
$format_conversion = 'Y-j-n';
break;
}

// If this is a valid date
if ( $date_timestamp = mktime(0, 0, 0, $month, $day, $year) )
// If later_than date is set
if ($later_than)
{
// If date is less than later_than date
if( $date_obj < $later_than )
{
// If later_than date is set
if ($later_than)
{
// If date is less than later_than date
if( $date_timestamp < $later_than->getTimestamp() )
{
$data['errors'][] = 'Date must be later than ' . $later_than->format($format_conversion) . '.';
}
}

// If earlier_than date is set
if ($earlier_than)
{
// If date is less than later_than date
if( $date_timestamp > $earlier_than->getTimestamp() )
{
$data['errors'][] = 'Date must be earlier than ' . $earlier_than->format($format_conversion) . '.';
}
}

// If no error were encountered
if ( ! $data['errors'] )
{
// Store date in YYYY/MM/DD format
$data['date'] = $year . '-' . $month . '-' . $day;
}
$data['errors'][] = 'Date must be later than ' . $later_than->format($display_format) . '.';
}
// If this is not a valid date
else
}

// If earlier_than date is set
if ($earlier_than)
{
// If date is less than later_than date
if( $date_obj > $earlier_than )
{
$data['errors'][] = 'Invalid date provided.';
$data['errors'][] = 'Date must be earlier than ' . $earlier_than->format($display_format) . '.';
}
}

// If no error were encountered
if ( ! $data['errors'] )
{
// Store date in YYYY-MM-DD format
$data['date'] = $year . '-' . $month . '-' . $day;
}



return $data;
}

Expand Down
60 changes: 60 additions & 0 deletions helpers/vwm_rating_helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/**
* Validate rating input
*
* @param int Question ID
* @param text User-provided question data (in this case it is the date from the text input)
* @param array Question options
* @return array
*/
function vwm_rating_validate($id, $input, $options)
{
// Rating options
$max = isset($options['max']) ? (int)$options['max'] : 0;
$type = $options['type'];

// The only user input is from the sole date input
$data['rating'] = trim($input);

// Check to make sure this is a number
if ( is_numeric($data['rating']) )
{
// If this is not an integer
if ( $data['rating'] !== (string)(int)$data['rating'] )
{
$data['errors'][] = 'Rating must be a whole number (integer).';
}
}
else
{
$data['errors'][] = 'Rating must be a number.';
}

return $data;
}

/**
* Compile date data
*
* @param int Survey ID
* @param int Survey submission ID
* @param array Question options
* @param array User-submitted question data
* @param array Current compiled question data
* @return array
*/
function vwm_rating_compile_results($survey_id, $submission_id, $question_options, $question_data, $compiled_data)
{
$total = isset($compiled_data['total']) ? (int)$compiled_data['total'] : 0;

if ( isset( $question_data['rating'] ) )
{
$compiled_data['total'] = $total + (int)$question_data['rating'];

}

return $compiled_data;
}

// EOF
67 changes: 56 additions & 11 deletions javascript/mcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ $('#vwm_surveys_pages .add_question a').live('click', function() {
var type = $(this).closest('div').find('select').val();

// Add a new question
$.get('index.php', {
D: 'cp',
$.get(EE.BASE, {
C: 'addons_modules',
M: 'show_module_cp',
module: 'vwm_surveys',
Expand Down Expand Up @@ -60,8 +59,7 @@ $('#vwm_surveys_pages .delete_question a').live('click', function() {
var hidden_inputs = $(question).find('.hidden_inputs');

// Delete the question
$.get('index.php', {
D: 'cp',
$.get(EE.BASE, {
C: 'addons_modules',
M: 'show_module_cp',
module: 'vwm_surveys',
Expand Down Expand Up @@ -89,8 +87,7 @@ $('.move_question a').live('click', function() {
var hidden_inputs = $(question).find('.hidden_inputs');
var move = $(this).attr('class');

$.get('index.php', {
D: 'cp',
$.get(EE.BASE, {
C: 'addons_modules',
M: 'show_module_cp',
module: 'vwm_surveys',
Expand Down Expand Up @@ -120,8 +117,7 @@ $('.delete_page a').live('click', function() {
var page_number = $(page).attr('id').substring(17);
var survey_id = $(this).closest('form').find('input[name="vwm_surveys_id"]').val();

$.get('index.php', {
D: 'cp',
$.get(EE.BASE, {
C: 'addons_modules',
M: 'show_module_cp',
module: 'vwm_surveys',
Expand All @@ -144,8 +140,7 @@ $('.add_page a').live('click', function() {
var title = $(this).siblings('input').val();

// Add a new page
$.get('index.php', {
D: 'cp',
$.get(EE.BASE, {
C: 'addons_modules',
M: 'show_module_cp',
module: 'vwm_surveys',
Expand All @@ -158,6 +153,18 @@ $('.add_page a').live('click', function() {
});
});

/**
* Whenever a user registers a kek up event on the add page text input we want
* to see if it was the "Enter" key. If it was then we want to trigger a click
* event for the "Add Page" link.
*/
$('form.edit_survey .add_page :input').live('keyup', function(e) {
// If the use pressed the "enter" key
if (e.which == 13) {
$(this).siblings('a').trigger('click');
}
});

/**
* Toggle
*/
Expand All @@ -180,6 +187,44 @@ $('.toggle > a').click(function() {
/**
* jQuery UI datepicker
*/
$('#vwm_survey_submissions_search .datepicker').datepicker({
$('.datepicker').datepicker({
altFormat: $.datepicker.W3C
});

/**
* Toggle select groups multiselect
*/
(function() {
var radios = $('input[name="vwm_surveys_allowed_groups"]');
var multiselect = $('select[name^="vwm_surveys_select_allowed_groups"]');

// On page load if group radio input is equal to "SELECT"
if ( $(radios).filter(':checked').val() === 'SELECT' ) {
$(multiselect).show();
}
// On page load if the group radio input is equal to either "A" or "NULL"
else {
$(multiselect).hide();
}

// Whenever the group radio input changes
$(radios).change(function() {
if ( $(this).val() === 'SELECT' ) {
$(multiselect).show();
}
else {
$(multiselect).hide();
}
});
})();

/**
* Whenever our survey edit form is submitted check to see if the current
* element with focus has the class "no_submit". If it does we will not submit
* the form.
*/
$('form.edit_survey').live('submit', function(e) {
if ( $(':focus').hasClass('no_submit') ) {
e.preventDefault();
}
});
11 changes: 11 additions & 0 deletions javascript/vwm_checkboxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@ $('.vwm_checkboxes input.remove').live('click', function() {
$('.vwm_checkboxes .all_checkboxes').sortable({
axis: 'y',
containment: 'parent'
});

/**
* On keyup inside new checkbox input
*/
$('.vwm_checkboxes .new_checkbox :input').live('keyup', function(e) {
// If the use pressed the "enter" key
if (e.which == 13) {
// Trigger a click event on the "Add Checkbox" button
$(this).closest('div').find('input[type="button"]').trigger('click');
}
});
11 changes: 11 additions & 0 deletions javascript/vwm_radios.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@ $('.vwm_radios input.remove').live('click', function() {
$('.vwm_radios .all_radios').sortable({
axis: 'y',
containment: 'parent'
});

/**
* On keyup inside new radio input
*/
$('.vwm_radios .new_radio :input').live('keyup', function(e) {
// If the use pressed the "enter" key
if (e.which == 13) {
// Trigger a click event on the "Add Radio" button
$(this).closest('div').find('input[type="button"]').trigger('click');
}
});
3 changes: 3 additions & 0 deletions javascript/vwm_textarea.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/**
* VWM Textarea
*/
Loading

0 comments on commit 515bafb

Please sign in to comment.