Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 221 lines (167 sloc) 6.102 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
<h2><?php echo _("Add a page to the catalog"); ?></h2>

<?php if($user["logged_in"]===true): ?>

<div class="ui-state-error ui-corner-all hidden" style="padding: 0 .7em; margin: 20px 0;" id="pt_alert">
<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
<strong><?php echo _("Alert"); ?>:</strong> <span class="alert_text"></span></p>
</div>

<form method="post" name="add_pt_form" id="add_pt_form">

<div style="float: left; width: 330px; padding-right: 20px;">

<label for="title"><?php echo _("Title"); ?></label> <small><?php echo _("In English."); ?></small><br />
<input type="text" value="" name="title" id="title" size="35" maxlength="255" />

<br /><br />

<label for="url"><?php echo _("Webpage"); ?></label> <small><?php echo _("Required.")." "._("Please try to add an English version of the page."); ?></small><br />
<input type="text" value="" name="url" id="url" size="35" maxlength="255" />

<br /><br />


<label for="city"><?php echo _("City"); ?></label><br />
<input type="text" value="" name="city" id="city" maxlength="80" />

<br /><br />

<label for="country"><?php echo _("Country"); ?></label> <small><?php echo _("Required."); ?></small><br />
<select id="country" name="country">
<option value=""><?php echo _("Select"); ?></option>
<?php list_countries("option", "name", false, false, true); ?>
</select> &nbsp; <img class="flag" alt="" src="" class="hidden" />

<br /><br />

</div>
<div style="float: left; width: 250px;">

<?php
// Types:
foreach(pt_types() as $type => $type_name) {
echo '<input type="checkbox" value="'.$type.'" name="type_'.$type.'" class="type" id="type_'.$type.'" /> <label for="type_'.$type.'">'.pt_type($type, 'icon_text').'</label><br />';
}
?>

<br />

</div>

<div style="float: left; width: 600px; padding: 20px 0;" class="clear">

<button id="btn_add_public_transport"><?php echo _("Add page"); ?></button>
<button id="btn_cancel_public_transport"><?php echo _("Cancel"); ?></button>
</div>

</form>

<script type="text/javascript">
$(function() {

// Country flag
$("#add_pt_form #country").change( function () {
var selected_country = $(this).val();
if(selected_country != "") {
$("#profile_form .flag").attr("src","<?= $settings["base_url"]; ?>/static/gfx/flags/png/"+selected_country.toLowerCase()+".png");
$("#profile_form .flag").show();
} else {
$("#profile_form .flag").hide();
}
});

// Autosuggest in Location
$(function() {
$("#add_pt_form input#city").autocomplete({
source: function(request, response) {
$.ajax({
url: "http://api.geonames.org/searchJSON",
dataType: "jsonp",
data: {
username: geonames_username,
featureClass: "P",
style: "full",
maxRows: 5,
name_startsWith: request.term
},
success: function(data) {
response($.map(data.geonames, function(item) {
return {
label: item.name + ", " + item.countryName,
value: item.name
//value: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName
}
}))
}
})
},
minLength: 2,
select: function(event, ui) {
$("#add_pt_form input#city").val(ui.item.label);
//$("#add_pt_form input#country").val(ui.item.countryCode);
/*
Todo: Select country when selecting a city from the suggestions list
*/
//$("#profile_form #country").val(ui.item.countryCode.toLowerCase());
},
open: function() {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function() {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
}
});
});


// Cancel btn
$("#btn_cancel_public_transport").button({
icons: {
primary: 'ui-icon-cancel'
}
}).click(function(e) {
e.preventDefault();
maps_debug("Cancel adding page");
open_page('public_transport');
});


// Add btn
$("#btn_add_public_transport").button({
icons: {
primary: 'ui-icon-plusthick'
}
}).click(function(e) {
e.preventDefault();
maps_debug("Adding page to the catalog. Requesting API.");
$("#pt_alert").hide();
if($("#add_pt_form #url").val() == "" || $(" #add_pt_form #country").val() == "") {
maps_debug("Some required fields missing...");
$("#pt_alert .alert_text").text("<?php echo _("Please fill all required fields!"); ?>");
$("#pt_alert").show();
} else {
show_loading_bar("<?php echo _("Adding..."); ?>");
$("#add_pt_form").hide();

// Call API
//"#add_pt_form input[name~='type_']"
var p_country = $("#add_pt_form #country").val();
var p_city = $("#add_pt_form #city").val();
var p_title = $("#add_pt_form #title").val();
var p_url = $("#add_pt_form #url").val();
// Seperate multiple types by ;
var p_type = '';
$("#add_pt_form input.type:checked").each(function(){
var this_type = $(this).val();
if(p_type=="") {
p_type = this_type;
}
else {
p_type = p_type+';'+this_type;
}
});
$.post('<?= $settings["base_url"]; ?>/api/?add_public_transport', {
country: p_country,
city: p_city,
title: p_title,
url: p_url,
user_id: <?php echo $user["id"]; ?>,
type: p_type
},
function(data) {
hide_loading_bar();
if(data.success==true) {
maps_debug("Page added.");
info_dialog("<?php echo _("Page added to the catalog."); ?>","<?php echo _("Thank you!"); ?>");
close_page();
} else {
maps_debug("Adding page failed. Error: "+data.error);
$("#add_pt_form").show();
$("#pt_alert .alert_text").text("<?php echo _("Error adding page to the catalog. Check required fields and try again."); ?> "+data.error);
$("#pt_alert").show();
}
}
,"json"); // post end
} // else end

});
});
</script>

<?php

// Logged in?
else:
error_sign(_("You must be logged in."), false);
endif;
?>
Something went wrong with that request. Please try again.