Browse Source

added ajax callback to admin page, guaranteed collection object

pull/239/head
Alan Stanley 12 years ago
parent
commit
682254727e
  1. 2
      fedora_repository.api.php
  2. 89
      fedora_repository.module
  3. 85
      formClass.inc

2
fedora_repository.api.php

@ -26,7 +26,7 @@ function hook_islandora_tabs($content_models, $pid, $page_number) {
$tabset['A TAB'] = array(
'#type' => 'tabpage',
'#title' => t('A TITLE'),
'#content' => 'content')
'#content' => 'content'
);
return $tabset;

89
fedora_repository.module

@ -1,4 +1,5 @@
<?php
/**
* @file
* This file is the Drupal module file for fedora_repository.
@ -10,10 +11,10 @@
* Stores this info in the drupal variables table.
* the name and pid can also be passed as url parameters
*/
function fedora_repository_admin() {
function fedora_repository_admin(&$form_state) {
module_load_include('inc', 'fedora_repository', 'formClass');
$admin_form = new formClass();
return $admin_form->createAdminForm();
return $admin_form->createAdminForm(&$form_state);
}
/**
@ -1755,3 +1756,87 @@ function fedora_repository_fedora_repository_check_perm($op, $pid, $user) {
return NULL;
}
}
function update_fedora_url_div() {
$form = islandora_callback_prep();
$changed_elements = $form['fedora_ahah_wrapper'];
unset($changed_elements['#prefix'], $changed_elements['#suffix']);
$output = theme('status_messages') . drupal_render($changed_elements);
drupal_json(array(
'status' => TRUE,
'data' => $output,
));
}
function islandora_callback_prep() {
$form_state = array('storage' => NULL, 'submitted' => FALSE, 'rebuild' => TRUE);
$form_build_id = $_POST['form_build_id'];
$form = form_get_cache($form_build_id, $form_state);
$args = $form['#parameters'];
$form_id = array_shift($args);
$form_state['post'] = $form['#post'] = $_POST;
// Enable the submit/validate handlers to determine whether AHAH-submittted.
$form_state['ahah_submission'] = TRUE;
$form['#programmed'] = $form['#redirect'] = FALSE;
drupal_process_form($form_id, $form, $form_state);
$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
return $form;
}
function islandora_fedora_settings_form_submit($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
if ($form_state['ahah_submission'] == TRUE) {
$form_state['rebuild'] = TRUE;
return;
}
if ($form_state['clicked_button']['#id'] != 'edit-submit' && $op != t('Reset to defaults')) {
$form_state['rebuild'] = TRUE;
return;
}
// Exclude unnecessary elements.
unset($form_state['values']['submit'], $form_state['values']['reset'], $form_state['values']['form_id'], $form_state['values']['op'], $form_state['values']['form_token'], $form_state['values']['form_build_id']);
foreach ($form_state['values'] as $key => $value) {
if ($op == t('Reset to defaults')) {
variable_del($key);
}
else {
if (is_array($value) && isset($form_state['values']['array_filter'])) {
$value = array_keys(array_filter($value));
}
variable_set($key, $value);
}
}
//set elements previously defined in config code.
//the elements are left in to allow for third party modules.
if ($op != t('Reset to defaults')) {
$fedora_base = variable_get('fedora_base_url', 'http://localhost:8080/fedora');
variable_set('fedora_soap_url', $fedora_base . '/wsdl?api=API-A');
variable_set('fedora_soap_manage_url', $fedora_base . '/wsdl?api=API-M');
}
if ($op == t('Reset to defaults')) {
drupal_set_message(t('The configuration options have been reset to their default values.'));
}
else {
drupal_set_message(t('The Islandora configuration options have been saved.'));
}
$root = variable_get('fedora_repository_pid', 'islandora:root');
islandora_guarantee_root_collection($root);
cache_clear_all();
drupal_rebuild_theme_registry();
}
function islandora_guarantee_root_collection($pid){
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid);
if($item->exists()){
return;
}
$item = Fedora_item::ingest_new_item($pid, 'A', 'Islandora Root Collection', 'admin');
$item->add_relationship('hasModel', 'islandora:collectionCModel', FEDORA_MODEL_URI);
}

85
formClass.inc

@ -158,6 +158,13 @@ class formClass {
'access arguments' => array('administer site configuration'),
);
$items['islandora/fedora/url'] = array(
'page callback' => 'update_fedora_url_div',
'access arguments' => array('view fedora collection'),
'file' => 'fedora_repository.module',
'type' => MENU_CALLBACK,
);
return $items;
}
@ -165,14 +172,25 @@ class formClass {
* Create admin form
* @return array
*/
function createAdminForm() {
function createAdminForm(&$form_state) {
if (!user_access('administer site configuration')) {
drupal_set_message(t('You must be a site administrator to edit the Fedora collections list.'), 'error');
return;
}
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$fedora_path = isset($form_state['values']['fedora_base_url']) ? $form_state['values']['fedora_base_url'] : variable_get('fedora_base_url', 'http://localhost:8080/fedora');
$triplepath = "$fedora_path/risearch";
$response = do_curl_ext($fedora_path . '/describe');
$available = ($response != NULL) ? ($response[1] == 0) : FALSE;
$confirmation_message = ($available ? '<img src="' . url('misc/watchdog-ok.png') . '"/>'
. t('Successfully connected to Fedora server at @fedora_soap_url', array('@fedora_soap_url' => $fedora_path)) : '<img src="'
. url('misc/watchdog-error.png') . '"/> '
. t('Unable to connect to Fedora server at @fedora_soap_url', array('@fedora_soap_url' => $fedora_path)));
$form = array();
$form['fedora_repository_pid'] = array(
'#type' => 'textfield',
'#title' => t('Root Collection PID'),
@ -182,45 +200,41 @@ class formClass {
'#weight' => -18
);
$form['fedora_base_url'] = array(
'#type' => 'textfield',
'#title' => t('Fedora base URL'),
'#default_value' => variable_get('fedora_base_url', 'http://localhost:8080/fedora'),
'#description' => t('The URL to use for REST-type connections'),
'#required' => TRUE,
'#weight' => -16,
);
$form['fedora_repository_url'] = array(
'#type' => 'textfield',
'#title' => t('Fedora RISearch URL'),
'#default_value' => variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'),
'#description' => t('The url of the Fedora server'), '#required' => TRUE,
'#weight' => -14
// new ahah stuff
$form['fedora_ahah_wrapper'] = array(
'#prefix' => '<div id="islandora-fedora-url">',
'#suffix' => '</div>',
'#type' => 'markup',
);
$form['fedora_soap_url'] = array(
$form['fedora_ahah_wrapper']['fedora_base_url'] = array(
'#type' => 'textfield',
'#title' => t('Fedora SOAP Url'),
'#default_value' => variable_get('fedora_soap_url', 'http://localhost:8080/fedora/wsdl?api=API-A'),
'#description' => t('The URL to use for SOAP connections'),
'#required' => TRUE,
'#weight' => -12,
'#suffix' => '<p>' . (
fedora_available() ?
theme('image', 'misc/watchdog-ok.png') . t('Successfully connected to Fedora server at @fedora_soap_url', array('@fedora_soap_url' => variable_get('fedora_soap_url', ''))) :
theme('image', 'misc/watchdog-error.png') . t('Unable to connect to Fedora server at @fedora_soap_url', array('@fedora_soap_url' => variable_get('fedora_soap_url', '')))) . '</p>',
'#title' => t('Fedora base URL'),
'#default_value' => $fedora_path,
'#description' => t('The URL to use for REST-type connections'),
'#ahah' => array(
'path' => 'islandora/fedora/url',
'wrapper' => 'islandora-fedora-url',
'effect' => 'fade',
'event' => 'change'),
);
$form['fedora_soap_manage_url'] = array(
$form['fedora_ahah_wrapper']['infobox'] = array(
'#type' => 'item',
'#value' => $confirmation_message,
);
$form['fedora_ahah_wrapper']['fedora_repository_url'] = array(
'#type' => 'textfield',
'#title' => t('Fedora SOAP management URL'),
'#default_value' => variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/wsdl?api=API-M'), '#description' => t('The URL to use for SOAP API-M connections'),
'#title' => t('Fedora RISearch URL'),
'#default_value' => $triplepath,
'#description' => t('The url of the Fedora server\'s Triplestore. Change this only if you have set up an external triplestore'),
'#required' => TRUE,
'#weight' => -10
);
// will allow admin user to remove namepsace restrictions if not explicitly disallowed in settings.php
if (variable_get('allow_open_namespace', TRUE)) {
$form['fedora_namespace'] = array(
@ -365,9 +379,13 @@ class formClass {
);
$form['#attributes'] = array('enctype' => "multipart/form-data");
$form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save Configuration'));
$form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults'));
$form['#submit'][] = 'islandora_fedora_settings_form_submit';
$form['#theme'] = 'system_settings_form';
return ($form);
return system_settings_form($form);
// return system_settings_form($form);
}
/**
@ -422,8 +440,7 @@ class formClass {
}
// Save the title
if ( $label != null )
{
if ($label != null) {
$object = new Fedora_Item($form_values['pid']);
$object->modify_object($label);
}

Loading…
Cancel
Save