Skip to content

Instantly share code, notes, and snippets.

@thephw
Created February 6, 2015 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thephw/67b1459f5d80eb466291 to your computer and use it in GitHub Desktop.
Save thephw/67b1459f5d80eb466291 to your computer and use it in GitHub Desktop.
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
jQuery =>
$('#navbar').scrollspy()
doWork = new ApiExample("do-work", "GET", "http://development.primeoncology.org/mobilerest.svc/dowork")
doWork.initialize()
getActivityById = new ApiExample("get-activity-by-id", "POST", "http://development.primeoncology.org/mobilerest.svc/GetActivityById")
getActivityById.initialize()
##{"id":"E63900EA-1F4D-4EFC-A43C-83F1DF1462FE"}
getAllAreasOfInterest = new ApiExample("get-all-areas-of-interest", "GET", "http://development.primeoncology.org/mobilerest.svc/GetAllAreasOfInterest")
getAllAreasOfInterest.initialize()
getAllPrimelineIssues = new ApiExample("get-all-primeline-issues", "GET", "http://development.primeoncology.org/mobilerest.svc/GetAllPrimelineIssues")
getAllPrimelineIssues.initialize()
getMobileActivities = new ApiExample("get-mobile-activities", "GET", "http://development.primeoncology.org/mobilerest.svc/GetMobileActivities")
getMobileActivities.initialize()
getMobileActivitiesByAreaOfInterest = new ApiExample("get-mobile-activities-by-area-of-interest", "POST", "http://development.primeoncology.org/mobilerest.svc/getmobileactivitiesbyareaofinterest")
getMobileActivitiesByAreaOfInterest.initialize()
## {"id": "00000000-0000-0000-0000-000000000000"}
getPollQuestion = new ApiExample("get-poll-question", "POST", "http://development.primeoncology.org/mobilerest.svc/getpollquestion")
getPollQuestion.initialize()
## {"pollId": "6125235"}
submitPollAnswerWithId = new ApiExample("submit-poll-answer-with-id", "POST", "http://development.primeoncology.org/mobilerest.svc/SubmitPollAnswerWithId")
submitPollAnswerWithId.initialize()
## {"pollId": "6125235", "awnserId":"27665247", "otherText":""}
register = new ApiExample("register", "POST", "http://development.primeoncology.org/mobilerest.svc/register")
register.initialize()
## {"registrationInfo":{"firstName": "Andrey","lastname": "Garmash","address":"my address","address2":"test address2","city":"city test","state":"test state","zip":"test zip","country":"test country","email":"1@1.1"}}
submitSupportRequest = new ApiExample("submit-support-request", "POST", "http://development.primeoncology.org/mobilerest.svc/SubmitSupportRequest")
submitSupportRequest.initialize()
## {"requestType":"1","message":"hello rest"}
class ApiExample
constructor: (@plural_name, @type, @url) ->
initialize: ->
#Add HTML at <div id="#{@plural_name}-example" class="row">
html = """
<h3>Example</h3>
<a href="##{@plural_name}-example" class="btn" id="#{@plural_name}-send-btn">Send Request</a>
<br><br>
<div class="row">
<div class="span5">
<h6>Data (If needed)</h6>
<textarea class="span5" id="#{@plural_name}-data" style="height:300px"></textarea>
</div>
<div class="span5">
<h6>Results</h6>
<textarea class="span5" id="#{@plural_name}-results" style="height:300px"></textarea>
</div>
</div>
</div>
"""
$("##{@plural_name}").children(".example").first().html(html)
#Send Handler
$("##{@plural_name}-send-btn").click =>
data_string = $("##{@plural_name}-data").val()
if data_string != ""
data = JSON.parse data_string
else
data = null
$.ajax
data: data
dataType: "json"
type: @type
url: @url
success: (data, status) =>
dataString = JSON.stringify(data, null, "\t")
$("##{@plural_name}-results").val(dataString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment