diff --git a/feeds_ui/feeds_ui.admin.inc b/feeds_ui/feeds_ui.admin.inc index 325115f0ae74a8ffa442ccb056faab170ff1ab40..6a7e8bf6bbdbe68a4e4f4b001feeff690a302045 100644 --- a/feeds_ui/feeds_ui.admin.inc +++ b/feeds_ui/feeds_ui.admin.inc @@ -150,8 +150,7 @@ function feeds_ui_overview_form_submit($form, &$form_state) { * of $from_importer. */ function feeds_ui_create_form($form, &$form_state, $from_importer = NULL) { - drupal_add_js(drupal_get_path('module', 'feeds_ui') . '/feeds_ui.js'); - $form = array(); + $form['#attached']['js'][] = drupal_get_path('module', 'feeds_ui') . '/feeds_ui.js'; $form['#from_importer'] = $from_importer; $form['name'] = array( '#type' => 'textfield', @@ -159,15 +158,14 @@ function feeds_ui_create_form($form, &$form_state, $from_importer = NULL) { '#description' => t('A natural name for this configuration. Example: RSS Feed. You can always change this name later.'), '#required' => TRUE, '#maxlength' => 128, - '#attributes' => array('class' => array('feed-name')), ); $form['id'] = array( - '#type' => 'textfield', - '#title' => t('Machine name'), - '#description' => t('A unique identifier for this configuration. Example: rss_feed. Must only contain lower case characters, numbers and underscores.'), + '#type' => 'machine_name', '#required' => TRUE, '#maxlength' => 128, - '#attributes' => array('class' => array('feed-id')), + '#machine_name' => array( + 'exists' => 'feeds_ui_importer_machine_name_exists', + ), ); $form['description'] = array( '#type' => 'textfield', @@ -181,15 +179,25 @@ function feeds_ui_create_form($form, &$form_state, $from_importer = NULL) { return $form; } +/** + * Validation callback for the importer machine name field. + */ +function feeds_ui_importer_machine_name_exists($id) { + if ($id == 'create') { + // Create is a reserved path for the add importer form. + return TRUE; + } + ctools_include('export'); + if (ctools_export_load_object('feeds_importer', 'conditions', array('id' => $id))) { + return TRUE; + } +} + /** * Validation handler for feeds_build_create_form(). */ function feeds_ui_create_form_validate($form, &$form_state) { - ctools_include('export'); $importer = feeds_importer($form_state['values']['id']); - if (ctools_export_load_object('feeds_importer', 'conditions', array('id' => $form_state['values']['id']))) { - form_set_error('id', t('Id is taken.')); - } $importer->configFormValidate($form_state['values']); } diff --git a/feeds_ui/feeds_ui.js b/feeds_ui/feeds_ui.js index b1c634a872679fb7f184d341ba04498aa9677973..f5e8b7b1a889084a76cd8a65722721cfb083c9a0 100644 --- a/feeds_ui/feeds_ui.js +++ b/feeds_ui/feeds_ui.js @@ -1,33 +1,6 @@ Drupal.behaviors.feeds = function() { - // Export form machine-readable JS - $('.feed-name:not(.processed)').each(function() { - $('.feed-name') - .addClass('processed') - .after(' <small class="feed-id-suffix"> </small>'); - if ($('.feed-id').val() === $('.feed-name').val().toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/_+/g, '_') || $('.feed-id').val() === '') { - $('.feed-id').parents('.form-item').hide(); - $('.feed-name').keyup(function() { - var machine = $(this).val().toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/_+/g, '_'); - if (machine !== '_' && machine !== '') { - $('.feed-id').val(machine); - $('.feed-id-suffix').empty().append(' Machine name: ' + machine + ' [').append($('<a href="#">'+ Drupal.t('Edit') +'</a>').click(function() { - $('.feed-id').parents('.form-item').show(); - $('.feed-id-suffix').hide(); - $('.feed-name').unbind('keyup'); - return false; - })).append(']'); - } - else { - $('.feed-id').val(machine); - $('.feed-id-suffix').text(''); - } - }); - $('.feed-name').keyup(); - } - }); - // Hide text in specific input fields. $('.hide-text-on-focus').focus(function() { $(this).val('');