| 267 |
} |
} |
| 268 |
} |
} |
| 269 |
|
|
| 270 |
|
if (!empty($form_values['del_cond_op'])) { |
| 271 |
|
unset($set['conditions'][($form_values['del_cond_op'] - 1)]); |
| 272 |
|
} |
| 273 |
|
|
| 274 |
|
if (!empty($form_values['del_action_op'])) { |
| 275 |
|
unset($set['actions'][($form_values['del_action_op'] - 1)]); |
| 276 |
|
} |
| 277 |
|
|
| 278 |
$form = _voting_actions_set_form($set); |
$form = _voting_actions_set_form($set); |
| 279 |
|
|
| 280 |
$form['conditions'] = _voting_actions_set_conditions_form($set); |
$form['conditions'] = _voting_actions_set_conditions_form($set); |
| 289 |
return $form; |
return $form; |
| 290 |
} |
} |
| 291 |
|
|
| 292 |
|
function voting_actions_set_form_validate($form_id, $form_values) { |
| 293 |
|
if ($form_values['op'] == t('Submit')) { |
| 294 |
|
} |
| 295 |
|
} |
| 296 |
|
|
| 297 |
|
function voting_actions_set_form_submit($form_id, $form_values) { |
| 298 |
|
if ($form_values['op'] == t('Submit')) { |
| 299 |
|
drupal_set_message('Form submitted.'); |
| 300 |
|
} |
| 301 |
|
} |
| 302 |
|
|
| 303 |
function _voting_actions_set_from_values($set = array(), $form_values = array()) { |
function _voting_actions_set_from_values($set = array(), $form_values = array()) { |
| 304 |
// Build an in-process set before going any further. |
// Build an in-process set before going any further. |
| 305 |
|
$set['name'] = $form_values['name']; |
| 306 |
|
$set['description'] = $form_values['description']; |
| 307 |
|
$set['parent'] = $form_values['parent']; |
| 308 |
|
$set['source'] = $form_values['source']; |
| 309 |
|
$set['required'] = $form_values['required']; |
| 310 |
|
$set['weight'] = $form_values['weight']; |
| 311 |
|
$set['condition_mask'] = $form_values['conditions']['condition_mask']; |
| 312 |
|
|
| 313 |
$set += array( |
$set += array( |
| 314 |
'conditions' => array(), |
'conditions' => array(), |
| 315 |
'actions' => array(), |
'actions' => array(), |
| 316 |
'subsets' => array(), |
'subsets' => array(), |
| 317 |
); |
); |
| 318 |
$set = array_merge($form_values, $set); |
|
| 319 |
|
if (!empty($form_values['conditions']['existing'])) { |
| 320 |
if (!empty($set['conditions']['existing'])) { |
$set['conditions'] = $form_values['conditions']['existing']; |
|
$set['conditions'] = $set['conditions']['existing']; |
|
| 321 |
} |
} |
| 322 |
if (!empty($set['actions']['existing'])) { |
if (!empty($form_values['actions']['existing'])) { |
| 323 |
$set['actions'] = $set['actions']['existing']; |
foreach($form_values['actions']['existing'] as $key => $element) { |
| 324 |
|
$set['actions'][] = $form_values['actions']['existing'][$key]['name']; |
| 325 |
|
} |
| 326 |
} |
} |
|
$set['condition_mask'] = $form_values['conditions']['condition_mask']; |
|
| 327 |
|
|
|
unset($set['op']); |
|
|
unset($set['submit']); |
|
|
unset($set['conditions']['condition_mask']); |
|
| 328 |
return $set; |
return $set; |
| 329 |
} |
} |
| 330 |
|
|
| 401 |
$options[$key] = $data['name']; |
$options[$key] = $data['name']; |
| 402 |
} |
} |
| 403 |
|
|
| 404 |
|
$c = 0; |
| 405 |
$form['existing']['#weight'] = 0; |
$form['existing']['#weight'] = 0; |
| 406 |
foreach($set['conditions'] as $condition) { |
foreach($set['conditions'] as $condition) { |
| 407 |
$form['conditions']['existing'][] = voting_actions_condition_form($condition); |
$form['existing'][$c++] = voting_actions_condition_form($condition, $c, count($set['conditions'])); |
| 408 |
} |
} |
| 409 |
|
|
| 410 |
$form['add'] = array( |
$form['add'] = array( |
| 433 |
'#description' => t('If the conditions above pass, this list of actions will execute.'), |
'#description' => t('If the conditions above pass, this list of actions will execute.'), |
| 434 |
); |
); |
| 435 |
|
|
| 436 |
|
$a = 0; |
| 437 |
$form['existing']['#weight'] = 0; |
$form['existing']['#weight'] = 0; |
| 438 |
foreach($set['actions'] as $action) { |
foreach($set['actions'] as $action) { |
| 439 |
$form['existing'][] = voting_actions_action_form($action); |
$form['existing'][$a++] = voting_actions_action_form($action, $a, count($set['actions'])); |
| 440 |
} |
} |
| 441 |
|
|
| 442 |
$form['add'] = array( |
$form['add'] = array( |
| 456 |
return $form; |
return $form; |
| 457 |
} |
} |
| 458 |
|
|
| 459 |
function voting_actions_condition_form($condition) { |
function voting_actions_condition_form($condition, $c, $count) { |
| 460 |
$form = array(); |
$form = array(); |
| 461 |
$conditions = voting_actions_get_conditions(); |
$conditions = voting_actions_get_conditions(); |
| 462 |
if ($condition_info = $conditions[$condition['name']]) { |
if ($condition_info = $conditions[$condition['name']]) { |
| 489 |
if (($function = $condition_info['edit_handler']) && function_exists($function)) { |
if (($function = $condition_info['edit_handler']) && function_exists($function)) { |
| 490 |
$form['data'] = $function($condition['data']); |
$form['data'] = $function($condition['data']); |
| 491 |
} |
} |
| 492 |
|
|
| 493 |
|
|
| 494 |
|
/* Baby steps. Let's handle reordering later. |
| 495 |
|
if ($c > 1) { |
| 496 |
|
$form['up'] = array( |
| 497 |
|
'#type' => 'imagebutton', |
| 498 |
|
'#name' => 'up_cond_op', |
| 499 |
|
'#default_value' => $c, |
| 500 |
|
'#title' => t('Move up'), |
| 501 |
|
'#image' => drupal_get_path('module', 'voting_actions') .'/icons/go-up.png', |
| 502 |
|
); |
| 503 |
|
} |
| 504 |
|
|
| 505 |
|
if ($c < $count) { |
| 506 |
|
$form['down'] = array( |
| 507 |
|
'#type' => 'imagebutton', |
| 508 |
|
'#name' => 'down_cond_op', |
| 509 |
|
'#default_value' => $c, |
| 510 |
|
'#title' => t('Move down'), |
| 511 |
|
'#image' => drupal_get_path('module', 'voting_actions') .'/icons/go-down.png', |
| 512 |
|
); |
| 513 |
|
} |
| 514 |
|
*/ |
| 515 |
|
$form['del'] = array( |
| 516 |
|
'#type' => 'imagebutton', |
| 517 |
|
'#name' => 'del_cond_op', |
| 518 |
|
'#default_value' => $c, |
| 519 |
|
'#title' => t('Delete this criteria'), |
| 520 |
|
'#image' => drupal_get_path('module', 'voting_actions') .'/icons/edit-delete.png', |
| 521 |
|
); |
| 522 |
} |
} |
| 523 |
return $form; |
return $form; |
| 524 |
} |
} |
| 525 |
|
|
| 526 |
function voting_actions_action_form($action) { |
function voting_actions_action_form($action, $a, $count) { |
| 527 |
$form = array(); |
$form = array( |
| 528 |
|
'#theme' => 'voting_actions_inline_form', |
| 529 |
|
); |
| 530 |
|
|
| 531 |
$actions = actions_actions_map(actions_get_all_actions()); |
$actions = actions_actions_map(actions_get_all_actions()); |
| 532 |
|
|
| 533 |
$form['value'] = array( |
$form['name'] = array( |
| 534 |
'#type' => 'hidden', |
'#type' => 'hidden', |
| 535 |
'#value' => $action, |
'#value' => $action['name'], |
| 536 |
); |
); |
| 537 |
$form['description'] = array( |
$form['description'] = array( |
| 538 |
'#value' => $actions[$action]['description'], |
'#value' => $actions[$action['name']]['description'], |
| 539 |
); |
); |
| 540 |
$form['remove'] = array( |
|
| 541 |
'#type' => 'markup', |
$form['del'] = array( |
| 542 |
'#value' => '<br />', |
'#type' => 'imagebutton', |
| 543 |
|
'#name' => 'del_action_op', |
| 544 |
|
'#default_value' => $a, |
| 545 |
|
'#title' => t('Delete this criteria'), |
| 546 |
|
'#image' => drupal_get_path('module', 'voting_actions') .'/icons/edit-delete.png', |
| 547 |
); |
); |
| 548 |
|
|
| 549 |
return $form; |
return $form; |
| 550 |
} |
} |
| 551 |
|
|
| 565 |
* Custom form element to do nice image buttons. |
* Custom form element to do nice image buttons. |
| 566 |
*/ |
*/ |
| 567 |
function voting_actions_elements() { |
function voting_actions_elements() { |
| 568 |
$type['imagebutton'] = array('#input' => TRUE, '#button_type' => 'submit',); |
$type['imagebutton'] = array('#input' => TRUE, '#name' => 'op', '#button_type' => 'submit',); |
| 569 |
return $type; |
return $type; |
| 570 |
} |
} |
| 571 |
|
|
| 572 |
function theme_imagebutton($element) { |
function theme_imagebutton($element) { |
| 573 |
return '<input type="image" class="form-'. $element['#button_type'] .'" name="'. $element['#name'] .'" value="'. check_plain($element['#default_value']) .'" '. drupal_attributes($element['#attributes']) . ' src="' . $element['#image'] . '" alt="' . $element['#title'] . '" title="' . $element['#title'] . "\" />\n"; |
return '<input type="image" class="form-'. $element['#button_type'] .'" name="'. $element['#name'] .'" id="'. $element['#id'] .'" value="'. check_plain($element['#default_value']) .'" '. drupal_attributes($element['#attributes']) . ' src="/' . $element['#image'] . '" alt="' . $element['#title'] . '" title="' . $element['#title'] . "\" />\n"; |
| 574 |
} |
} |
| 575 |
|
|
| 576 |
function imagebutton_value() { |
function imagebutton_value() { |
| 577 |
// null function guarantees default_value doesn't get moved to #value. |
// Do-nothing function ensures default value doesn't migrate to #value |
| 578 |
} |
} |