/[drupal]/contributions/modules/voting_actions/voting_actions_ui.inc
ViewVC logotype

Diff of /contributions/modules/voting_actions/voting_actions_ui.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.3, Thu Apr 19 21:20:43 2007 UTC revision 1.1.2.4, Fri Apr 20 13:56:54 2007 UTC
# Line 12  function voting_actions_admin_page() { Line 12  function voting_actions_admin_page() {
12      $links['voting_actions_edit'] = array(      $links['voting_actions_edit'] = array(
13         'title' => theme('image', drupal_get_path('module', 'voting_actions') . '/icons/gtk-edit.png'),         'title' => theme('image', drupal_get_path('module', 'voting_actions') . '/icons/gtk-edit.png'),
14         'html' => TRUE,         'html' => TRUE,
15         'href' => "admin/settings/voting_actions/edit/$vasid",         'href' => "admin/settings/voting_actions/edit/$name",
16         'attributes' => array('title' => t('Edit this set')),         'attributes' => array('title' => t('Edit this set')),
17      );      );
18      $links['voting_actions_export'] = array(      $links['voting_actions_export'] = array(
19         'title' => theme('image', drupal_get_path('module', 'voting_actions') . '/icons/document-save.png'),         'title' => theme('image', drupal_get_path('module', 'voting_actions') . '/icons/document-save.png'),
20         'html' => TRUE,         'html' => TRUE,
21         'href' => "admin/settings/voting_actions/export/$name/db",         'href' => "admin/settings/voting_actions/export/$name",
22         'attributes' => array('title' => t('Export this set')),         'attributes' => array('title' => t('Export this set')),
23      );      );
24      $links['voting_actions_delete'] = array(      $links['voting_actions_delete'] = array(
# Line 58  function voting_actions_admin_page() { Line 58  function voting_actions_admin_page() {
58      }      }
59      else {      else {
60        $links['voting_actions_add'] = array(        $links['voting_actions_add'] = array(
61           'title' => theme('image', drupal_get_path('module', 'voting_actions') . '/icons/edit-paste.png'),         'title' => theme('image', drupal_get_path('module', 'voting_actions') . '/icons/gtk-edit.png'),
62           'html' => TRUE,         'html' => TRUE,
63           'href' => "admin/settings/voting_actions/add/$name",         'href' => "admin/settings/voting_actions/edit/$name",
64           'attributes' => array('title' => t('Clone this set')),         'attributes' => array('title' => t('Edit this set')),
65        );        );
66        $links['voting_actions_export'] = array(        $links['voting_actions_export'] = array(
67           'title' => theme('image', drupal_get_path('module', 'voting_actions') . '/icons/document-save.png'),           'title' => theme('image', drupal_get_path('module', 'voting_actions') . '/icons/document-save.png'),
# Line 210  function voting_actions_admin_delete_pag Line 210  function voting_actions_admin_delete_pag
210  function voting_actions_admin_delete_page_submit($formid, $form) {  function voting_actions_admin_delete_page_submit($formid, $form) {
211    $name = $form['set'];    $name = $form['set'];
212    $sets = _voting_actions_load_sets_from_db();    $sets = _voting_actions_load_sets_from_db();
213    if ($sets[$name]) {    if ($set = $sets[$name]) {
214      _voting_actions_delete_set($name, $set[$name]);      _voting_actions_delete_set($set);
215    }    }
216    return 'admin/settings/voting_actions';    return 'admin/settings/voting_actions';
217  }  }
# Line 228  function voting_actions_admin_disable_pa Line 228  function voting_actions_admin_disable_pa
228    drupal_goto('admin/settings/voting_actions');    drupal_goto('admin/settings/voting_actions');
229  }  }
230    
231    function voting_actions_admin_edit_page($name = '') {
232  function voting_actions_admin_add_page($name = NULL) {    $sets = voting_actions_get_sets();
233    $set = _voting_actions_populate_set_defaults();    $set = empty($sets[$name]) ? _voting_actions_populate_set_defaults() : $sets[$name];
   return drupal_get_form('voting_actions_set_form', $set);  
 }  
   
 function voting_actions_admin_edit_page($name = NULL, $db_or_module = 'db') {  
   if ($db_or_module == 'db') {  
     $sets = _voting_actions_load_sets_from_db();  
   }  
   else {  
     $sets = module_invoke_all('voting_actions_sets');  
   }  
   
   if (!empty($name) && !empty($sets[$name])) {  
     $set = $sets[$name];  
   }  
   else {  
     $set = array();  
   }  
   
   $set += _voting_actions_populate_set_defaults();  
234    return drupal_get_form('voting_actions_set_form', $set);    return drupal_get_form('voting_actions_set_form', $set);
235  }  }
236    
# Line 263  function voting_actions_set_form($set, $ Line 244  function voting_actions_set_form($set, $
244      }      }
245    
246      if ($form_values['op'] == t('Add action')) {      if ($form_values['op'] == t('Add action')) {
247        $set['actions'][] = array('name' => $form_values['actions']['add']['action_type']);        $set['actions'][] = $form_values['actions']['add']['action_type'];
248        }
249    
250        if (!empty($form_values['del_cond_op'])) {
251          unset($set['conditions'][($form_values['del_cond_op'] - 1)]);
252      }      }
   }  
253    
254    if (!empty($form_values['del_cond_op'])) {      if (!empty($form_values['del_action_op'])) {
255      unset($set['conditions'][($form_values['del_cond_op'] - 1)]);        unset($set['actions'][($form_values['del_action_op'] - 1)]);
256        }
257    }    }
258    
   if (!empty($form_values['del_action_op'])) {  
     unset($set['actions'][($form_values['del_action_op'] - 1)]);  
   }  
   
259    $form = _voting_actions_set_form($set);    $form = _voting_actions_set_form($set);
260    
261    $form['conditions'] =  _voting_actions_set_conditions_form($set);    $form['conditions'] =  _voting_actions_set_conditions_form($set);
# Line 286  function voting_actions_set_form($set, $ Line 267  function voting_actions_set_form($set, $
267      '#value' => t('Submit'),      '#value' => t('Submit'),
268    );    );
269    
270      if (!empty($set['vasid'])) {
271        $form['delete'] = array(
272          '#type' => 'submit',
273          '#value' => t('Delete'),
274        );
275      }
276    
277    return $form;    return $form;
278  }  }
279    
280  function voting_actions_set_form_validate($form_id, $form_values) {  function voting_actions_set_form_validate($form_id, $form_values) {
281    if ($form_values['op'] == t('Submit')) {    if ($form_values['op'] == t('Submit')) {
282    
283        if (empty($form_values['name'])) {
284          form_set_error('name', t('Action sets must be named.'));
285        }
286        elseif ($form_values['name'] != strtolower(form_clean_id($form_values['name']))) {
287          form_set_error('name', t('The set name must consist of lowercase letters with no spaces or special symbols -- use underscores or dashes instead of spaces.'));
288        }
289        elseif(empty($form_values['vasid'])) {
290          if (db_result(db_query("SELECT 1 FROM {voting_actions_set} WHERE name = '%s'", $form_values['name']))) {
291            form_set_error('name', t('A voting action set with the name @setname already exists. Choose a new name.', array('@setname' => $form_values['name'])));
292          }
293        }
294    
295        $set = _voting_actions_set_from_values(array(), $form_values);
296        $errors = _voting_actions_validate_set($set);
297        foreach ($errors as $error) {
298          form_set_error(NULL, $error);
299        }
300    }    }
301  }  }
302    
303  function voting_actions_set_form_submit($form_id, $form_values) {  function voting_actions_set_form_submit($form_id, $form_values) {
304    if ($form_values['op'] == t('Submit')) {    if ($form_values['op'] == t('Submit')) {
305      drupal_set_message('Form submitted.');      $set = _voting_actions_set_from_values(array(), $form_values);
306        if (empty($set['vasid'])) {
307          _voting_actions_insert_set($set);
308        }
309        else {
310          _voting_actions_update_set($set);
311        }
312    
313        drupal_set_message(t('Your voting action set was saved.'));
314        return 'admin/settings/voting_actions/';
315      }
316      elseif ($form_values['op'] == t('Delete')) {
317        return 'admin/settings/voting_actions/delete/'. $form_values['name'];
318      }
319      else {
320        return FALSE;
321    }    }
322  }  }
323    
# Line 321  function _voting_actions_set_from_values Line 342  function _voting_actions_set_from_values
342      }      }
343      if (!empty($form_values['actions']['existing'])) {      if (!empty($form_values['actions']['existing'])) {
344        foreach($form_values['actions']['existing'] as $key => $element) {        foreach($form_values['actions']['existing'] as $key => $element) {
345          $set['actions'][] = $form_values['actions']['existing'][$key]['name'];          $set['actions'][$key] = $form_values['actions']['existing'][$key]['name'];
346        }        }
347      }      }
348    
# Line 332  function _voting_actions_set_form($set) Line 353  function _voting_actions_set_form($set)
353    $form = array();    $form = array();
354    
355    $form['#multistep'] = TRUE;    $form['#multistep'] = TRUE;
   $form['#redirect'] = FALSE;  
356    $form['#tree'] = TRUE;    $form['#tree'] = TRUE;
357    
358    $form['vasid'] = array(    $form['vasid'] = array(
# Line 418  function _voting_actions_set_conditions_ Line 438  function _voting_actions_set_conditions_
438      '#options' => $options,      '#options' => $options,
439    );    );
440    $form['add']['add_condition'] = array(    $form['add']['add_condition'] = array(
441      '#type' => 'button',      '#type' => 'submit',
442      '#value' => t('Add condition'),      '#value' => t('Add condition'),
443    );    );
444    return $form;    return $form;
# Line 450  function _voting_actions_set_actions_for Line 470  function _voting_actions_set_actions_for
470      '#options' => _voting_actions_list(),      '#options' => _voting_actions_list(),
471    );    );
472    $form['add']['add_action'] = array(    $form['add']['add_action'] = array(
473      '#type' => 'button',      '#type' => 'submit',
474      '#value' => t('Add action'),      '#value' => t('Add action'),
475    );    );
476    return $form;    return $form;
# Line 527  function voting_actions_action_form($act Line 547  function voting_actions_action_form($act
547    $form = array(    $form = array(
548      '#theme' => 'voting_actions_inline_form',      '#theme' => 'voting_actions_inline_form',
549    );    );
550    
551    $actions = actions_actions_map(actions_get_all_actions());    $actions = actions_get_all_actions();
552    
553    $form['name'] = array(    $form['name'] = array(
554      '#type' => 'hidden',      '#type' => 'hidden',
555      '#value' => $action['name'],      '#value' => $action,
556    );    );
557    $form['description'] = array(    $form['description'] = array(
558      '#value' => $actions[$action['name']]['description'],      '#value' => $actions[$action]['description'],
559    );    );
560    
561    $form['del'] = array(    $form['del'] = array(
562      '#type' => 'imagebutton',      '#type' => 'imagebutton',
563      '#name' => 'del_action_op',      '#name' => 'del_action_op',
564      '#default_value' => $a,      '#default_value' => $a,
565      '#title' => t('Delete this criteria'),      '#title' => t('Delete this action'),
566      '#image' => drupal_get_path('module', 'voting_actions') .'/icons/edit-delete.png',      '#image' => drupal_get_path('module', 'voting_actions') .'/icons/edit-delete.png',
567    );    );
568    
# Line 551  function voting_actions_action_form($act Line 571  function voting_actions_action_form($act
571    
572  function _voting_actions_list() {  function _voting_actions_list() {
573    $options = array();    $options = array();
574    foreach (actions_actions_map(actions_get_all_actions()) as $aid => $action) {    foreach (actions_get_all_actions() as $aid => $action) {
575      $options[$action['type']][$aid] = $action['description'];      $options[$action['type']][$aid] = $action['description'];
576    }    }
577    return $options;    return $options;

Legend:
Removed from v.1.1.2.3  
changed lines
  Added in v.1.1.2.4

  ViewVC Help
Powered by ViewVC 1.1.2