Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ability to delete #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions assets/js/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ $(document).bind("mobileinit", function(){

/* end of filter code */

$(document).on("click", "#delete_carpool_button", function(){
if (confirm('Really Delete Your Carpool?')){
$.ajax({
type: "POST",
url: 'http://api.snowpool.org/pools/'+$("#pool_id").val() + '.js',
data: {
"_method" : 'delete',
"token" : users_token()
},
success: function(data) {
alert("Carpool has been deleted");
$.mobile.changePage("#country_pool_list");
}
});
}
});

$(document).on("click", "#send_message_button", function(){
$.ajax({
Expand Down Expand Up @@ -111,6 +127,7 @@ $(document).bind("mobileinit", function(){
window.localStorage.setItem("token" ,data.token);
window.localStorage.setItem("telephone" ,data.telephone);
window.localStorage.setItem("city" ,data.city);
window.localStorage.setItem("user_id" ,data.user_id);
window.localStorage.setItem("valid_login" ,"true");
$.mobile.changePage("#country_pool_list");
},
Expand Down Expand Up @@ -150,10 +167,14 @@ $(document).bind("mobileinit", function(){
$("#pool_details").append("<strong>Message</strong><br/>"+data.message+"<br/>");
}
if (user_is_valid()){
$("#pool_details").append("<br/><br/><strong>Send "+data.name+" a message</strong><br/>");
$("#pool_details").append("<textarea name=\"messageText\" id=\"pool_message\"></textarea>");
$("#pool_details").append("<input type=\"hidden\" id=\"pool_id\" value=\""+data.id+"\"></textarea>");
$("#pool_details").append('<button type="submit" data-theme="a" id="send_message_button">Send Message</button>');
if (is_own_carpool(data.user_id)){
$("#pool_details").append('<button type="submit" data-theme="a" id="delete_carpool_button">Delete Your Carpool</button>');
}else{
$("#pool_details").append("<br/><br/><strong>Send "+data.name+" a message</strong><br/>");
$("#pool_details").append("<textarea name=\"messageText\" id=\"pool_message\"></textarea>");
$("#pool_details").append('<button type="submit" data-theme="a" id="send_message_button">Send Message</button>');
}
}else{
$("#pool_details").append("<h4>If you <a href=\"#sign_in\">sign in</a>, then you can send the user a message.</h4>");
}
Expand Down Expand Up @@ -234,7 +255,12 @@ function empty_and_refresh_carpools(){
//setup all the local variables etc
function setup(){
if (user_is_valid()){
$(".login_button").hide();
if (user_id_unset()){
window.localStorage.setItem("valid_login" ,"false");
$(".add_carpool_button").hide();
}else{
$(".login_button").hide();
}
}else{
$(".add_carpool_button").hide();
}
Expand All @@ -248,6 +274,9 @@ function empty_and_refresh_carpools(){
function user_is_valid(){
return window.localStorage.getItem("valid_login") == "true";
}
function user_id_unset(){
return window.localStorage.getItem("user_id") === null;
}
function users_token(){
return window.localStorage.getItem("token");
}
Expand All @@ -257,6 +286,9 @@ function empty_and_refresh_carpools(){
function users_city(){
return window.localStorage.getItem("city");
}
function is_own_carpool(user_id){
return parseInt(window.localStorage.getItem("user_id"), 10) === user_id;
}
function users_fields(){
if ( window.localStorage.getItem("has_country_fields") == "true" ){
return JSON.parse(window.localStorage.getItem("country_fields"));
Expand Down
14 changes: 3 additions & 11 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.snowpool.mobileapp"
versionCode="150"
version = "2.0.4">
versionCode="160"
version = "2.1.0">

<name>Snowpool</name>

<preference name="phonegap-version" value="2.5.0" />
<description>
A mobile application for snowpool.org
</description>

<author href="http://snowpool.org"
email="[email protected]">
Snowpool
Expand All @@ -19,9 +18,6 @@
<gap:platforms>
<gap:platform name="android" minVersion="2.1" />
<gap:platform name="ios" />
<gap:platform name="webos" />
<gap:platform name="symbian.wrt" />
<gap:platform name="blackberry" project="widgets"/>
</gap:platforms>


Expand All @@ -44,11 +40,7 @@


<preference name="permissions" value="none"/>
<!-- sample preference specification -->
<!-- <preference name="autorotate" value="false" readonly="true"/> -->

<!-- with no phonegap version set, build complains we are using Phonegap 1.7.0 -->
<preference name="phonegap-version" value="2.7.0" />
<!-- only want to target phones -->
<preference name="target-device" value="handset" />
</widget>
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ <h1>Snowpool</h1>
</div> <!--end of settings page -->

<!-- pools page -->
<div data-role="page" id="country_pool_list">
<div data-role="page" id="country_pool_list">
<div data-role="header">
<a href="#refresh" rel="external" class="refresh_button" class="ui-btn-left" data-icon="refresh">Refresh</a>
<h1>Snowpool</h1>
Expand Down