Changeset 511342
- Timestamp:
- 02/27/2012 07:14:36 PM (14 years ago)
- Location:
- polizeipresse/trunk
- Files:
-
- 5 edited
-
admin.php (modified) (6 diffs)
-
css/admin.css (modified) (2 diffs)
-
i18n/Polizeipresse-de_DE.mo (modified) (previous)
-
i18n/Polizeipresse-de_DE.po (modified) (3 diffs)
-
js/admin.js (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
polizeipresse/trunk/admin.php
r510077 r511342 178 178 <tr valign="top"> 179 179 <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> 181 181 </th> 182 182 <td> … … 185 185 <input name="office_name" id="office_name" size="50" value="<?php echo polizeipresse_get_option(POLIZEIPRESSE_OFFICE_NAME); ?>" 186 186 type="text" class="regular-text" readonly="readonly" /> 187 <button id="search DialogButton" class="button-secondary" <?php echo (empty($api_key) ? ' disabled="disabled" ' : '') ?>>187 <button id="searchOfficeDialogButton" class="button-secondary" <?php echo (empty($api_key) ? ' disabled="disabled" ' : '') ?>> 188 188 <?php _e('Search for offices', 'Polizeipresse'); ?> 189 189 </button> … … 335 335 </form> 336 336 337 <div id="search Dialog" 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'); ?>"> 338 338 339 339 <div class="adminHelpMessage"> … … 344 344 <form> 345 345 <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"> 349 351 </p> 350 352 … … 404 406 wp_enqueue_style ('wp-jquery-ui-dialog'); 405 407 408 wp_enqueue_style ('admin.css', plugin_dir_url(__FILE__) . 'css/admin.css'); 406 409 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 ); 408 416 } 409 417 add_action('admin_init', 'polizeipresse_admin_init'); … … 432 440 $response = $pp->search_office($terms); 433 441 434 if( !$response->error) {442 if((!$response->error) && ($response->offices)) { 435 443 foreach($response->offices AS $office) { 436 444 $result[] = array('name' => $office->name, 'id' => $office->id); 437 445 } 446 } 447 else { 448 // Empty result 438 449 } 439 450 } -
polizeipresse/trunk/css/admin.css
r509518 r511342 63 63 } 64 64 65 #search Dialog {65 #searchOfficeDialog { 66 66 padding: .5em 1em; 67 67 text-decoration: none; … … 70 70 } 71 71 72 #search Dialog #officeSelector {72 #searchOfficeDialog #officeSelector { 73 73 width: 300px; 74 74 } 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 3 3 "Project-Id-Version: Polizeipresse\n" 4 4 "Report-Msgid-Bugs-To: \n" 5 "POT-Creation-Date: 2012-02-2 4 20:29+0100\n"6 "PO-Revision-Date: 2012-02-2 4 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" 7 7 "Last-Translator: Karsten Strunk <karsten@strunk.eu>\n" 8 8 "Language-Team: Karsten Strunk <karsten@strunk.eu>\n" … … 150 150 msgstr "Sie können hier nach deutschen Polizeidienststellen suchen. Nach der Suche wählen sie eine Dienststelle aus und drücken 'übernehmen'." 151 151 152 #: admin.php:34 5152 #: admin.php:346 153 153 msgid "Search terms" 154 154 msgstr "Suche" 155 155 156 #: admin.php:35 2156 #: admin.php:355 157 157 msgid "Search" 158 158 msgstr "Suchen" 159 159 160 #: admin.php:35 4160 #: admin.php:357 161 161 msgid "Cancel" 162 162 msgstr "Abbrechen" 163 163 164 #: admin.php:36 0164 #: admin.php:364 165 165 msgid "Search result" 166 166 msgstr "Suchergebnis" 167 167 168 #: admin.php:36 4168 #: admin.php:368 169 169 msgid "Apply" 170 170 msgstr "Übernehmen" 171 172 #: admin.php:410 173 msgid "No result from server." 174 msgstr "Keine Dienststelle gefunden." 175 176 #: admin.php:411 177 msgid "An error occurred" 178 msgstr "Ein unbekannter Fehler ist aufgetreten." 179 180 #: admin.php:412 181 msgid "Please enter API key" 182 msgstr "Bitte API-Schlüssel eingeben" 183 184 #: admin.php:413 185 msgid "Please select police office" 186 msgstr "Bitte Dienststelle auswählen" 171 187 172 188 #: Polizeipresse.php:294 … … 229 245 msgstr "Stunden" 230 246 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 16 16 required: true 17 17 }, 18 office_ id: {18 office_name: { 19 19 required: true 20 20 } 21 }, 22 messages: { 23 api_key: polizeipresse.validation_required_api_key, 24 office_name: polizeipresse.validation_required_office, 21 25 }, 22 26 invalidHandler: function(form, validator) { … … 61 65 62 66 // 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(); 73 69 return false; 74 70 }); 75 71 76 72 // Enable search dialog button only if api_key is set 77 jQuery("#api_key").keyup(function() {73 jQuery("#api_key").keyup(function() { 78 74 api_key = jQuery("#api_key").val(); 79 75 if (api_key) { 80 jQuery("#search DialogButton").removeAttr("disabled");76 jQuery("#searchOfficeDialogButton").removeAttr("disabled"); 81 77 } 82 78 else { 83 jQuery("#search DialogButton").attr("disabled", "disabled");79 jQuery("#searchOfficeDialogButton").attr("disabled", "disabled"); 84 80 } 85 81 return true; … … 87 83 88 84 // Open search dialog on click on office name 89 jQuery("#office_name").focus(function() {90 if(!jQuery("#search DialogButton").attr("disabled")) {91 jQuery("#search DialogButton").click();85 jQuery("#office_name").focus(function() { 86 if(!jQuery("#searchOfficeDialogButton").attr("disabled")) { 87 jQuery("#searchOfficeDialogButton").click(); 92 88 } 93 89 return true; … … 95 91 96 92 // 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 */ 114 function 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 */ 142 function 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 */ 139 166 function 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) { 144 171 // Add offices to result list 145 172 jQuery("#officeSelector").empty(); 146 173 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"); 148 175 }); 149 176 jQuery("#officeSelector option:first").attr("selected", "selected"); … … 152 179 jQuery("#searchOfficeResult").show(); 153 180 } 154 catch(e){155 // TODO Handle error156 alert("An error occurred: " + e);157 } 158 } 159 else{160 // TODO Handle error161 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(); 162 189 } 163 190 … … 165 192 jQuery("#searchOfficeButton").removeAttr("disabled"); 166 193 } 194 195 /** 196 * When the user has chosen an office, this method applies the new office. 197 */ 198 function 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.