Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
507 lines (459 sloc) 14.4 KB
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>index</title>
<script src="../jquery-1.9.1.min.js"></script>
<script src="../baasbox.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
BaasBox.setEndPoint("http://localhost:9000");
BaasBox.appcode = "1234567890";
$("#login").click(function() {
BaasBox.login("bbb", "bbb")
.done(function (user) {
console.log("Logged in ", user);
})
.fail(function (err) {
console.log("error ", err);
})
});
$("#logout").click(function () {
BaasBox.logout()
.done(function (res) {
console.log(res);
})
.fail(function (error) {
console.log("error ", error);
})
});
$("#signup").click(function() {
BaasBox.signup("test", "test")
.done(function (res) {
console.log("signup ", res);
})
.fail(function (error) {
console.log("error ", error);
})
});
$("#signupWithParams").click(function() {
BaasBox.signup("test2", "test2", {"visibleByRegisteredUsers": {"email" : "test@test.com"}})
.done(function (res) {
console.log("signup ", res);
})
.fail(function (error) {
console.log("error ", error);
})
});
$("#loadCollection").click(function() {
BaasBox.loadCollection("test")
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#loadCollectionWithParams").click(function() {
BaasBox.loadCollectionWithParams("test", {where: "color='red'"})
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#loadObject").click(function() {
BaasBox.loadObject("test", "9e2921b0-cb60-4fc6-aa9b-28f4a8df4f0e")
.done(function(res) {
console.log("res ", res['data']);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#save").click(function () {
var o = new Object();
o.list = ["margherita", "capricciosa"];
o.address = "Prince Street 100, New York, NY";
BaasBox.save(o, "test")
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#update").click(function () {
BaasBox.loadCollection("test")
.done(function(res) {
objectId = res[0].id;
console.log("updating object with id ", objectId)
BaasBox.updateField(objectId, "test", "address", "new address")
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#delete").click(function () {
BaasBox.loadCollection("test")
.done(function(res) {
objectId = res[0].id;
console.log("deleting object with id ", objectId)
BaasBox.deleteObject(objectId, "test")
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#loadJSONAsset").click(function() {
BaasBox.loadAssetData("test")
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#getImageURI").click(function () {
BaasBox.getImageURI("testimage", {'resizeId' : 1})
.done(function(res) {
console.log("image URI is ", res['data']);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#fetchCurrentUser").click(function () {
BaasBox.fetchCurrentUser()
.done(function(res) {
console.log("res ", res['data']);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#fetchUser").click(function () {
BaasBox.fetchUserProfile("test2")
.done(function(res) {
console.log("res ", res['data']);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#fetchUsers").click(function () {
BaasBox.fetchUsers()
.done(function(res) {
console.log("res ", res['data']);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#fetchUsersWithParams").click(function () {
BaasBox.fetchUsers({"where": "user.name='test2'"})
.done(function(res) {
console.log("res ", res['data']);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#updateUserProfile").click(function () {
BaasBox.updateUserProfile({"visibleByTheUser": {"address" : "Prince St, NY"}})
.done(function(res) {
console.log("res ", res['data']);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#changePassword").click(function () {
BaasBox.changePassword("test", "newtest")
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#resetPassword").click(function () {
BaasBox.resetPassword()
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#followUser").click(function () {
BaasBox.followUser("test2")
.done(function(res) {
console.log("res ", res['data']);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#unfollowUser").click(function () {
BaasBox.unfollowUser("test2")
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#fetchFollowers").click(function () {
BaasBox.fetchFollowers("test2")
.done(function(res) {
console.log("res ", res['data']);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#fetchFollowing").click(function () {
BaasBox.fetchFollowing("test")
.done(function(res) {
console.log("res ", res['data']);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#fetchObjectsCount").click(function () {
BaasBox.fetchObjectsCount("test")
.done(function(res) {
console.log("res ", res['data']['count']);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#grantUserAccessToObject").click(function () {
BaasBox.grantUserAccessToObject("test", "f5136a59-83a6-4506-b25d-a0a2ab7d12a7", BaasBox.READ_PERMISSION, "test2")
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#revokeUserAccessToObject").click(function () {
BaasBox.revokeUserAccessToObject("test", "7a3ed177-f4e8-46ad-b857-75886228cc13", BaasBox.ALL_PERMISSION, "test2")
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#grantRoleAccessToObject").click(function () {
BaasBox.grantRoleAccessToObject("test", "7a3ed177-f4e8-46ad-b857-75886228cc13", BaasBox.READ_PERMISSION, BaasBox.REGISTERED_ROLE)
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#revokeRoleAccessToObject").click(function () {
BaasBox.revokeRoleAccessToObject("test", "7a3ed177-f4e8-46ad-b857-75886228cc13", BaasBox.READ_PERMISSION, BaasBox.REGISTERED_ROLE)
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#sendPush").click(function () {
// Assumes the app has been compiled with a sound file named 'sound.aiff' in the bundle
BaasBox.sendPushNotification({"message" : "hi there", "users" : ["john", "jane"], "badge" : 1, "sound" : "sound.aiff"})
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#createCollection").click(function () {
BaasBox.createCollection("ciao")
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#deleteCollection").click(function () {
BaasBox.deleteCollection("ciao")
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#uploadForm").submit(function(e) {
e.preventDefault();
var formObj = $(this);
var formData = new FormData(this);
BaasBox.uploadFile(formData)
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
});
$("#sub").click(function() {
$("#uploadForm").submit()
})
$("#fetchFile").click(function () {
BaasBox.fetchFile("0d7c2469-71e0-447b-a524-a8ecd0bf4a77")
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
})
$("#fetchFileDetails").click(function () {
BaasBox.fetchFileDetails("7491d26b-b730-40e7-9587-c0c3f58193c7")
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
})
$("#deleteFile").click(function () {
BaasBox.deleteFile("0d7c2469-71e0-447b-a524-a8ecd0bf4a77")
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
})
$("#grantUserAccessToFile").click(function () {
BaasBox.grantUserAccessToFile("7491d26b-b730-40e7-9587-c0c3f58193c7", BaasBox.READ_PERMISSION, "test2")
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
})
$("#revokeUserAccessToFile").click(function () {
BaasBox.revokeUserAccessToFile("7491d26b-b730-40e7-9587-c0c3f58193c7", BaasBox.READ_PERMISSION, "test2")
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
})
$("#grantRoleAccessToFile").click(function () {
BaasBox.grantRoleAccessToFile("7491d26b-b730-40e7-9587-c0c3f58193c7", BaasBox.READ_PERMISSION, BaasBox.REGISTERED_ROLE)
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
})
$("#revokeRoleAccessToFile").click(function () {
BaasBox.revokeRoleAccessToFile("7491d26b-b730-40e7-9587-c0c3f58193c7", BaasBox.READ_PERMISSION, BaasBox.REGISTERED_ROLE)
.done(function(res) {
console.log("res ", res);
})
.fail(function(error) {
console.log("error ", error);
})
})
// Assumes this plugin is installed on the server: https://gist.github.com/funkyboy/ecc754dbe0f89e4a4c56
$("#pluginGET").click(function () {
var url = BaasBox.endPoint + '/plugin/geo.bb';
var req = $.get(url, {"ip" : "8.8.8.8"})
.done(function (res) {
console.log("res is ", res.data);
})
.fail(function (error) {
console.log("error = ", error);
})
})
// Assumes this plugin is installed on the server: https://gist.github.com/funkyboy/ad3b25dfdbd53e27324f
$("#pluginPOST").click(function () {
var url = BaasBox.endPoint + '/plugin/addcar.bb';
var req = $.post(url, {"name" : "ferrari"})
.done(function (res) {
console.log("res is ", res.data);
})
.fail(function (error) {
console.log("error = ", error);
})
})
});
</script>
</head>
<body>
<a id="login" href="#">login</a> <br>
<a id="logout" href="#">logout</a><br>
<a id="signup" href="#">signup</a><br>
<a id="signupWithParams" href="#">signup with params</a><br>
<a id="fetchCurrentUser" href="#">fetch current user profile</a><br>
<a id="save" href="#">save</a><br>
<a id="createCollection" href="#">create a collection</a><br>
<a id="deleteCollection" href="#">delete a collection</a><br>
<a id="loadCollection" href="#">load collection</a> <br>
<a id="loadCollectionWithParams" href="#">load collection with params</a> <br>
<a id="loadObject" href="#">load object</a> <br>
<a id="fetchObjectsCount" href="#">fetch objects count</a> <br>
<a id="update" href="#">update field</a><br>
<a id="delete" href="#">delete object</a><br>
<a id="grantUserAccessToObject" href="#">grant access to user</a><br>
<a id="revokeUserAccessToObject" href="#">revoke access to user</a><br>
<a id="grantRoleAccessToObject" href="#">grant access to role</a><br>
<a id="revokeRoleAccessToObject" href="#">revoke access to role</a><br>
<a id="loadJSONAsset" href="#">load JSON asset</a> <br>
<a id="getImageURI" href="#">get image URI</a><br>
<a id="fetchUser" href="#">fetch user profile</a><br>
<a id="fetchUsers" href="#">fetch users</a><br>
<a id="fetchUsersWithParams" href="#">fetch user list with params</a><br>
<a id="updateUserProfile" href="#">update user profile</a><br>
<a id="changePassword" href="#">change password</a><br>
<a id="resetPassword" href="#">reset password</a><br>
<a id="followUser" href="#">follow user</a><br>
<a id="unfollowUser" href="#">unfollow user</a><br>
<a id="fetchFollowers" href="#">fetch followers</a><br>
<a id="fetchFollowing" href="#">fetch following</a><br>
<a id="sendPush" href="#">send push notification</a><br>
<a id="fetchFile" href="#">fetch file</a><br>
<a id="fetchFileDetails" href="#">fetch file details</a><br>
<a id="deleteFile" href="#">delete file</a><br>
<form id="uploadForm">
<input type="file" name="upload" /><br/>
</form>
<button id="sub">Upload</button><br/>
<a id="grantUserAccessToFile" href="#">grant user access to file</a><br>
<a id="revokeUserAccessToFile" href="#">revoke user access to file</a><br>
<a id="grantRoleAccessToFile" href="#">grant role access to file</a><br>
<a id="revokeRoleAccessToFile" href="#">revoke role access to file</a><br>
<a id="pluginGET" href="#">plugin GET</a><br>
<a id="pluginPOST" href="#">plugin POST</a><br>
</body>
</htm>