Plugin Directory

Changeset 511342


Ignore:
Timestamp:
02/27/2012 07:14:36 PM (14 years ago)
Author:
Strunker
Message:

Improvements on user experience, localization of javascript files added

Location:
polizeipresse/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • polizeipresse/trunk/admin.php

    r510077 r511342  
    178178                <tr valign="top">
    179179                    <th scope="row">
    180                         <label for="office_id"><?php _e('Police office', 'Polizeipresse'); ?></lable>
     180                        <label for="office_name"><?php _e('Police office', 'Polizeipresse'); ?></lable>
    181181                    </th>
    182182                    <td>
     
    185185                        <input name="office_name" id="office_name" size="50" value="<?php echo polizeipresse_get_option(POLIZEIPRESSE_OFFICE_NAME); ?>"
    186186                            type="text" class="regular-text" readonly="readonly" />
    187                         <button id="searchDialogButton" class="button-secondary" <?php echo (empty($api_key) ? ' disabled="disabled" ' : '') ?>>
     187                        <button id="searchOfficeDialogButton" class="button-secondary" <?php echo (empty($api_key) ? ' disabled="disabled" ' : '') ?>>
    188188                            <?php _e('Search for offices', 'Polizeipresse'); ?>
    189189                        </button>
     
    335335        </form>
    336336
    337         <div id="searchDialog" class="wp-dialog" style="display:none" title="<?php _e('Search for offices', 'Polizeipresse'); ?>">
     337        <div id="searchOfficeDialog" class="wp-dialog" style="display:none" title="<?php _e('Search for offices', 'Polizeipresse'); ?>">
    338338
    339339            <div class="adminHelpMessage">
     
    344344            <form>
    345345                <p>
    346                     <label for="office_search"><?php _e('Search terms', 'Polizeipresse'); ?>:</lable>
    347                     <input id="office_search_terms" size="30" type="text" class="regular-text"
    348                         value="<?php echo polizeipresse_get_option(POLIZEIPRESSE_OFFICE_NAME); ?>" />
     346                    <label for="searchOfficeTerms"><?php _e('Search terms', 'Polizeipresse'); ?>:</lable>
     347                    <input id="searchOfficeTerms" size="30" type="text" class="regular-text" />
     348                </p>
     349
     350                <p id="searchOfficeErrorMessage">
    349351                </p>
    350352
     
    404406    wp_enqueue_style ('wp-jquery-ui-dialog');
    405407
     408    wp_enqueue_style ('admin.css', plugin_dir_url(__FILE__) . 'css/admin.css');
    406409    wp_enqueue_script('admin.js', plugin_dir_url(__FILE__) . 'js/admin.js', null, null, true);
    407     wp_enqueue_style ('admin.css', plugin_dir_url(__FILE__) . 'css/admin.css');
     410    $locData = array ('error_no_result'             => __('No result from server.', 'Polizeipresse'),
     411                      'error_unknown'               => __('An error occurred', 'Polizeipresse'),
     412                      'validation_required_api_key' => __('Please enter API key', 'Polizeipresse'),
     413                      'validation_required_office'  => __('Please select police office', 'Polizeipresse')
     414                      );
     415    wp_localize_script('admin.js', 'polizeipresse', $locData );
    408416}
    409417add_action('admin_init', 'polizeipresse_admin_init');
     
    432440        $response = $pp->search_office($terms);
    433441
    434         if(!$response->error) {
     442        if((!$response->error) && ($response->offices)) {
    435443            foreach($response->offices AS $office) {
    436444                $result[] = array('name' => $office->name, 'id' => $office->id);
    437445            }
     446        }
     447        else {
     448            // Empty result
    438449        }
    439450    }
  • polizeipresse/trunk/css/admin.css

    r509518 r511342  
    6363}
    6464
    65 #searchDialog {
     65#searchOfficeDialog {
    6666    padding: .5em 1em;
    6767    text-decoration: none;
     
    7070}
    7171
    72 #searchDialog #officeSelector {
     72#searchOfficeDialog #officeSelector {
    7373    width: 300px;
    7474}
     75
     76#searchOfficeDialog #searchOfficeErrorMessage {
     77    display: none;
     78    text-align: center;
     79    color: #ff0000;
     80    font-weight: bold;
     81}
  • polizeipresse/trunk/i18n/Polizeipresse-de_DE.po

    r510077 r511342  
    33"Project-Id-Version: Polizeipresse\n"
    44"Report-Msgid-Bugs-To: \n"
    5 "POT-Creation-Date: 2012-02-24 20:29+0100\n"
    6 "PO-Revision-Date: 2012-02-24 20:29+0100\n"
     5"POT-Creation-Date: 2012-02-27 19:56+0100\n"
     6"PO-Revision-Date: 2012-02-27 20:01+0100\n"
    77"Last-Translator: Karsten Strunk <karsten@strunk.eu>\n"
    88"Language-Team: Karsten Strunk <karsten@strunk.eu>\n"
     
    150150msgstr "Sie können hier nach deutschen Polizeidienststellen suchen. Nach der Suche wählen sie eine Dienststelle aus und drücken 'übernehmen'."
    151151
    152 #: admin.php:345
     152#: admin.php:346
    153153msgid "Search terms"
    154154msgstr "Suche"
    155155
    156 #: admin.php:352
     156#: admin.php:355
    157157msgid "Search"
    158158msgstr "Suchen"
    159159
    160 #: admin.php:354
     160#: admin.php:357
    161161msgid "Cancel"
    162162msgstr "Abbrechen"
    163163
    164 #: admin.php:360
     164#: admin.php:364
    165165msgid "Search result"
    166166msgstr "Suchergebnis"
    167167
    168 #: admin.php:364
     168#: admin.php:368
    169169msgid "Apply"
    170170msgstr "Übernehmen"
     171
     172#: admin.php:410
     173msgid "No result from server."
     174msgstr "Keine Dienststelle gefunden."
     175
     176#: admin.php:411
     177msgid "An error occurred"
     178msgstr "Ein unbekannter Fehler ist aufgetreten."
     179
     180#: admin.php:412
     181msgid "Please enter API key"
     182msgstr "Bitte API-Schlüssel eingeben"
     183
     184#: admin.php:413
     185msgid "Please select police office"
     186msgstr "Bitte Dienststelle auswählen"
    171187
    172188#: Polizeipresse.php:294
     
    229245msgstr "Stunden"
    230246
    231 #~ msgid "API key is required"
    232 #~ msgstr "API-Schlüssel wird benötigt."
    233 
    234 #~ msgid "Office id is required and must be numerical"
    235 #~ msgstr "Numerisch Dienststellen-ID wird benötigt"
    236 
    237 #~ msgid "You will find the required office id on this site"
    238 #~ msgstr ""
    239 #~ "Die Dienststellen-ID für die gewünschte Dienststelle finden Sie auf "
    240 #~ "folgender Seite"
    241 
    242 #~ msgid "Office id"
    243 #~ msgstr "Dienststellen-ID"
  • polizeipresse/trunk/js/admin.js

    r510077 r511342  
    1616                required: true
    1717            },
    18             office_id: {
     18            office_name: {
    1919                required: true
    2020            }
     21        },
     22        messages: {
     23            api_key: polizeipresse.validation_required_api_key,
     24            office_name: polizeipresse.validation_required_office,
    2125        },
    2226        invalidHandler: function(form, validator) {
     
    6165
    6266    // Define button for opening the search dialog
    63     jQuery("#searchDialogButton").click(function(){
    64         api_key = jQuery('#api_key').val();
    65         if (api_key) {
    66             jQuery("#searchDialog").dialog({
    67                 closeOnEscape: true,
    68                 modal: true,
    69                 width: 500,
    70                 dialogClass: 'wp-dialog',
    71             });
    72         }
     67    jQuery("#searchOfficeDialogButton").click(function() {
     68        polizeipresse_admin_open_search_dialog();
    7369        return false;
    7470    });
    7571
    7672    // Enable search dialog button only if api_key is set
    77     jQuery("#api_key").keyup(function(){
     73    jQuery("#api_key").keyup(function() {
    7874        api_key = jQuery("#api_key").val();
    7975        if (api_key) {
    80             jQuery("#searchDialogButton").removeAttr("disabled");
     76            jQuery("#searchOfficeDialogButton").removeAttr("disabled");
    8177        }
    8278        else {
    83             jQuery("#searchDialogButton").attr("disabled", "disabled");
     79            jQuery("#searchOfficeDialogButton").attr("disabled", "disabled");
    8480        }
    8581        return true;
     
    8783
    8884    // Open search dialog on click on office name
    89     jQuery("#office_name").focus(function(){
    90         if(!jQuery("#searchDialogButton").attr("disabled")) {
    91             jQuery("#searchDialogButton").click();
     85    jQuery("#office_name").focus(function() {
     86        if(!jQuery("#searchOfficeDialogButton").attr("disabled")) {
     87            jQuery("#searchOfficeDialogButton").click();
    9288        }
    9389        return true;
     
    9591
    9692    // Init cancel button in serch dialog
    97     jQuery("#cancelSearchOfficeDialog").click(function(){
    98         jQuery("#searchDialog").dialog("close");
    99         return false;
    100     });
    101 
    102     // Initialize search for offices
    103     jQuery("#searchOfficeButton").click(function(){
    104 
    105         // Disable search button
    106         jQuery("#searchOfficeButton").attr("disabled", "disabled");
    107 
    108         // Hide result list
    109         jQuery("#searchOfficeResult").hide();
    110 
    111         jQuery.post(
    112             ajaxurl,
    113             {
    114                 action: 'polizeipresse_search_office',
    115                 terms: jQuery('#office_search_terms').val(),
    116                 api_key: jQuery('#api_key').val(),
    117             },
    118             polizeipresse_admin_handle_search_result
    119         );
    120         return false;
    121     });
    122 
    123     // Init apply button in serch dialog
    124     jQuery("#applySearchOfficeDialog").click(function(){
    125         // Copy selected office to admin form
    126 
    127         office_id = jQuery("#officeSelector option:selected").val();
    128         jQuery("#office_id").val(office_id);
    129 
    130         office_name = jQuery("#officeSelector option:selected").text();
    131         jQuery("#office_name").val(office_name);
    132 
    133         jQuery("#searchDialog").dialog("close");
    134 
    135         return false;
    136     });
    137 }
    138 
     93    jQuery("#cancelSearchOfficeDialog").click(function() {
     94        jQuery("#searchOfficeDialog").dialog("close");
     95        return false;
     96    });
     97
     98    // On button click start searching
     99    jQuery("#searchOfficeButton").click(function() {
     100        polizeipresse_admin_process_search();
     101        return false;
     102    });
     103
     104    // Init apply button in search dialog
     105    jQuery("#applySearchOfficeDialog").click(function() {
     106        polizeipresse_admin_apply_selected_office();
     107        return false;
     108    });
     109}
     110
     111/**
     112 * Opens the search dialog
     113 */
     114function polizeipresse_admin_open_search_dialog() {
     115    api_key = jQuery('#api_key').val();
     116    if (api_key) {
     117        jQuery("#searchOfficeDialog").dialog({
     118            closeOnEscape: true,
     119            modal: true,
     120            width: 500,
     121            dialogClass: 'wp-dialog',
     122            open: function(event, ui) {
     123                // Set initial search terms
     124                jQuery('#searchOfficeTerms').val(jQuery('#office_name').val());
     125
     126                // Enable search button
     127                jQuery("#searchOfficeButton").removeAttr("disabled");
     128
     129                // Hide result list
     130                jQuery("#searchOfficeResult").hide();
     131
     132                // Hide error message
     133                jQuery("#searchOfficeErrorMessage").hide();
     134            }
     135        });
     136    }
     137}
     138
     139/**
     140 * Processes the search for police offices.
     141 */
     142function polizeipresse_admin_process_search() {
     143    // Disable search button
     144    jQuery("#searchOfficeButton").attr("disabled", "disabled");
     145
     146    // Hide result list
     147    jQuery("#searchOfficeResult").hide();
     148
     149    // Hide error message
     150    jQuery("#searchOfficeErrorMessage").hide();
     151
     152    jQuery.post(
     153        ajaxurl,
     154        {
     155            action: 'polizeipresse_search_office',
     156            terms: jQuery('#searchOfficeTerms').val(),
     157            api_key: jQuery('#api_key').val(),
     158        },
     159        polizeipresse_admin_handle_search_result
     160    );
     161}
     162
     163/**
     164 * Handles the search result from AJAX-respone.
     165 */
    139166function polizeipresse_admin_handle_search_result(response, textStatus) {
    140     if (response && response.length > 0) {
    141         try {
    142             var offices = JSON.parse(response);
    143 
     167    try {
     168        var offices = JSON.parse(response);
     169
     170        if (offices && offices.length > 0) {
    144171            // Add offices to result list
    145172            jQuery("#officeSelector").empty();
    146173            jQuery.each(offices, function(index, office) {
    147                         jQuery("<option/>").val(office.id).text(office.name).appendTo("#officeSelector");
     174                jQuery("<option/>").val(office.id).text(office.name).appendTo("#officeSelector");
    148175            });
    149176            jQuery("#officeSelector option:first").attr("selected", "selected");
     
    152179            jQuery("#searchOfficeResult").show();
    153180        }
    154         catch(e) {
    155             // TODO Handle error
    156             alert("An error occurred: " + e);
    157         }
    158     }
    159     else {
    160         // TODO Handle error
    161         alert("No result from server. Please check api key and/or connection.");
     181        else {
     182            jQuery("#searchOfficeErrorMessage").text(polizeipresse.error_no_result);
     183            jQuery("#searchOfficeErrorMessage").show();
     184        }
     185
     186    } catch(e) {
     187        jQuery("#searchOfficeErrorMessage").text(polizeipresse.error_unknown + ": " + e);
     188        jQuery("#searchOfficeErrorMessage").show();
    162189    }
    163190
     
    165192    jQuery("#searchOfficeButton").removeAttr("disabled");
    166193}
     194
     195/**
     196 * When the user has chosen an office, this method applies the new office.
     197 */
     198function polizeipresse_admin_apply_selected_office() {
     199    // Copy selected office to admin form
     200
     201    office_id = jQuery("#officeSelector option:selected").val();
     202    jQuery("#office_id").val(office_id);
     203
     204    office_name = jQuery("#officeSelector option:selected").text();
     205    jQuery("#office_name").val(office_name);
     206
     207    jQuery("#searchOfficeDialog").dialog("close");
     208}
Note: See TracChangeset for help on using the changeset viewer.