Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: ICTatRTI/pomegranate
base: 452dd175b7
...
head fork: ICTatRTI/pomegranate
compare: 2ad006e62f
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
17 android_app/AndroidManifest.xml
@@ -29,6 +29,9 @@
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+
+
<application android:icon="@drawable/icon" android:label="@string/app_name"
@@ -42,6 +45,20 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+
+ <!-- For background service -->
+ <service android:name="org.rti.pomegranate.MyService">
+ <intent-filter>
+ <action android:name="org.rti.pomegranate.MyService"/>
+ </intent-filter>
+ </service>
+
+ <receiver android:name="com.red_folder.phonegap.plugin.backgroundservice.BootReceiver">
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED"></action>
+ </intent-filter>
+ </receiver>
+
</application>
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="17"/>
View
1  android_app/assets/www/index.html
@@ -77,6 +77,7 @@
<script type="text/javascript" src="js/lib/moment.min.js"></script>
<script type="text/javascript" src="js/lib/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/lib/bootbox.min.js"></script>
+ <script type="text/javascript" src="js/lib/backgroundService-2.9.0.js"></script>
<script type="text/javascript" src="js/pomegranate.js"></script>
</body>
View
13 android_app/assets/www/js/pomegranate.coffee
@@ -145,6 +145,17 @@ P.config =
P.boot = ->
+ # Run in background
+ console.log "Starting service"
+
+ cordova.define 'cordova/plugin/myService', (require,exports,module) ->
+ CreateBackgroundService('org.rti.pomegranate.MyService', require, exports, module)
+
+ (cordova.require('cordova/plugin/myService')).startService( (r) -> console.log "Started #{JSON.stringify r}", (r) -> console.log "Failed to start #{JSON.stringify r}")
+ console.log "Service started"
+
+
+
P.sender = cordova.require('cordova/plugin/smssendingplugin')
P.sender.isSupported (supported) ->
@@ -175,8 +186,6 @@ P.boot = ->
console.log "Trying to load config from database"
P.db.get 'config',
(error,doc) ->
- U.log JSON.stringify doc
- U.log doc?
if doc?
console.log "Found a config: #{JSON.stringify doc}"
P.config = doc
View
12 android_app/assets/www/js/pomegranate.js
@@ -173,6 +173,16 @@ P.config = {
P.boot = function() {
var e;
+ console.log("Starting service");
+ cordova.define('cordova/plugin/myService', function(require, exports, module) {
+ return CreateBackgroundService('org.rti.pomegranate.MyService', require, exports, module);
+ });
+ (cordova.require('cordova/plugin/myService')).startService(function(r) {
+ return console.log("Started " + (JSON.stringify(r)), function(r) {
+ return console.log("Failed to start " + (JSON.stringify(r)));
+ });
+ });
+ console.log("Service started");
P.sender = cordova.require('cordova/plugin/smssendingplugin');
P.sender.isSupported(function(supported) {
if (!supported) {
@@ -211,8 +221,6 @@ P.boot = function() {
$.extend(P.db, _db);
console.log("Trying to load config from database");
return P.db.get('config', function(error, doc) {
- U.log(JSON.stringify(doc));
- U.log(doc != null);
if (doc != null) {
console.log("Found a config: " + (JSON.stringify(doc)));
P.config = doc;
View
1  android_app/res/xml/config.xml
@@ -75,5 +75,6 @@
<plugins>
<plugin name="SmsSendingPlugin" value="org.apache.cordova.plugin.SmsSendingPlugin" />
<plugin name="ReadSms" value="net.webootu.cordova.plugin.ReadSms" />
+ <plugin name="BackgroundServicePlugin" value="com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePlugin"/>
</plugins>
</widget>
View
5 cloud_app/_attachments/index.html
@@ -6,8 +6,11 @@
<div id='header'>
<h1>Pomegranate <a id='reference_url' href=''></a></h1><div id='menu'></div>
</div>
- <div id='content'></div>
<div id='send'></div>
+ <div id='sent'></div>
+ <div id='received'></div>
+ <div id='configure'></div>
+ <div id='selectProject'></div>
<div id='group-manager'></div>
View
531 cloud_app/_attachments/router.coffee
@@ -1,531 +0,0 @@
-class Router extends Backbone.Router
- routes:
- ":project/send" : "send"
- ":project/received" : "received"
- ":project/sent" : "sent"
- ":project" : "menu"
- ":project/configure" : "configure"
- "" : "selectProject"
-
- configure: (project) ->
- @menu(project)
- configureView = new ConfigureView
- configureView.project = project
- configureView.render()
-
- selectProject: ->
- $("#menu").html ""
- $("#content").html "
- Enter your project name:
- <input onChange='document.location=\"#\"+$(event.target).val()\' type='text'></input>
- "
- menu: (project) ->
- $("#content").html ""
- $("#menu").html "
- #{
- (for option in "send,sent,received,configure".split(/,/)
- "<a role='button' href='##{project}/#{option}'>#{option}</a>"
- ).join("")
- }
- <a role='button' href='#'>select project</a>
- "
-
- send: (project) ->
- @menu(project)
- sendView = new SendView
- sendView.project = project
- sendView.render()
-
- groupManager = new GroupManager
- groupManager.render()
-
- received: (project) ->
- @menu(project)
- receivedView = new ReceivedView
- receivedView.project = project
- receivedView.render()
-
- sent: (project) ->
- @menu(project)
- sentView = new SentView
- sentView.project = project
- sentView.render()
-
-
-
-class Person extends Backbone.Model
- url: "person"
-
-class People extends Backbone.Collection
-
- url: "person"
- model: Person
-
-class Group extends Backbone.Model
- url: "group"
-
-class Groups extends Backbone.Collection
- url: "group"
- model: Group
-
-
-class GroupManager extends Backbone.View
-
- el : "#group-manager"
-
- htmlAddNumbers : "<button class='add-to-numbers'>Add selected group to recipients</button>"
- htmlAddPerson : "<button class='add-person'>Add Person</button>"
- htmlAddGroup : "<button class='add-group'>Add Group</button>"
-
-
- events:
- "click #group-selector li" : "onGroupClick"
- "click .group-edit" : "onGroupEdit"
- "click .group-remove" : "onGroupRemove"
-
- "click .add-group" : "addGroup"
- "click .add-person" : "addPerson"
-
- "change .group-name" : "onGroupNameChange"
- "blur .group-name" : "onGroupNameBlur"
-
- "change .person-name" : "onPersonChange"
- "change .person-phone" : "onPersonChange"
- "change .person-tags" : "onPersonChange"
-
- "click .person-remove" : "onPersonRemove"
-
- "click .add-to-numbers" : "addToField"
-
- onPersonRemove: (event) =>
- $target = $(event.target)
- personId = $target.parents("li").attr('id')
-
- if window.confirm("are you sure you want to remove this person?")
- person = @allPeople.get personId
- @allPeople.remove personId
- person.destroy
- success: =>
- @updatePeople()
-
-
- onPersonChange: (event) ->
- $target = $(event.target)
- $person = $target.parents("li")
-
- personId = $person.attr('id')
- person = @allPeople.get(personId)
- person.save
- name : $person.find(".person-name").val()
-
- district : $person.find(".person-district").val()
- designation : $person.find(".person-designation").val()
- tags : $person.find(".person-tags").val()
- ,
- success: ->
- console.log "saved"
-
-
-
- onGroupEdit: (event) =>
- $target = $(event.target)
- groupId = $target.parent("li").attr('id')
- @editGroup @allGroups.get(groupId)
-
-
- onGroupRemove: (event) =>
- $target = $(event.target)
- groupId = $target.parent("li").attr('id')
- if window.confirm("are you sure you want to remove this group?")
- group = @allGroups.get groupId
- @allGroups.remove groupId
- group.destroy
- success: =>
- @updateGroups()
- @updatePeople()
-
- onGroupNameBlur: (event) ->
- $target = $(event.target)
- value = $target.val()
- groupId = $target.parent("li").attr('id')
- group = @allGroups.get(groupId)
- @updateGroup(group)
-
-
- onGroupNameChange: (event) ->
- $target = $(event.target)
- value = $target.val()
- groupId = $target.parent("li").attr('id')
- group = @allGroups.get(groupId)
- group.save
- "name" : value
- ,
- success: =>
- @updateGroup(group)
-
-
- onGroupClick : (event) ->
- $target = $(event.target)
- groupId = $target.attr('id')
- @selected.group = @allGroups.get(groupId)
- @showSelected()
-
- @$el.find("#people-label").html "People in \"#{@selected.group.escape('name')}\""
- @updatePeople()
-
- showSelected: ->
- @$el.find("#group-selector li").removeClass("selected")
- @$el.find("##{@selected.group.id}").addClass("selected")
-
-
- addPerson: ->
- person = new Person
- person.save
- "groupId" : @selected.group.id
- ,
- success: =>
- @allPeople.add person
- @updatePeople()
-
- addGroup: ->
- group = new Group
- group.save null,
- success: =>
- @allGroups.add group
- @updateGroups()
- @updatePeople()
-
-
- initialize: ->
- @selected = {}
-
- render: =>
-
- @$el.html "
- <h2>Group manager</h2>
-
- #{@htmlAddNumbers}<br>
-
- <label id='groups-label'>Groups</label><br>
- <ul id='group-selector'></ul>
-
- <label id='people-label'>People</label><br>
- <ul id='people'></ul>
- "
-
- @allGroups = new Groups
- @allGroups.fetch
- success: =>
- @selected.group = @allGroups.first()
- @allPeople = new People
- @allPeople.fetch
- success: =>
- @$el.find("#people-label").html "People in \"#{@selected.group.escape('name')}\""
- @updateGroups()
- @updatePeople()
- @showSelected()
-
- addToField: ->
- $("#numbers").val (@allPeople.where( "groupId" : @selected.group.id )).map((a)->a.attributes.phone).join("\n")
-
- updateGroups: =>
-
- html = ''
-
- for group in @allGroups.models
-
- html += "<li id='#{group.id}'>#{@htmlGroup(group)}</li>"
-
- html += "<li>#{@htmlAddGroup}</li>"
-
- @$el.find("#group-selector").html html
-
- editGroup: ( group ) ->
- @$el.find("##{group.id}").html("<input type='text' class='group-name' value='#{group.escape('name')}'></li>").select()
-
- updateGroup: ( group ) ->
- @$el.find("##{group.id}").html @htmlGroup(group)
-
- htmlGroup: (group) ->
- return "#{group.get('name')} <span class='group-edit action'>edit</span> <span class='group-remove action'>remove</span>"
-
- updatePeople: ->
- return @$el.find("#people").html "No group selected" unless @selected.group?
- return @$el.find("#people").html "
- <ul>
- <li>No one in group</li>
- <li>#{@htmlAddPerson}</li>
- </ul>
- " if (people = @allPeople.where( "groupId" : @selected.group.id )).length is 0
-
- html = ''
-
- for person in people
-
- html += "
- <li value='#{person.id}' id='#{person.id}'>
- #{@getPersonTable(person)}
- </li>
- "
-
- html += "<li>#{@htmlAddPerson}</li>"
-
- @$el.find("#people").html html
-
-
- updatePerson: ( personId ) ->
-
- @$el.find("##{personId}").html "
- <li value='#{person.id}' id='#{person.id}'>
- #{@getPersonTable(person)}
- </li>
- "
-
- onNameChange: (event) ->
- $target = $(event.target)
- name = $target.val()
- personId = $target.parent("li")
-
-
- getPersonTable: (person) ->
- return "
- <table>
- <tr><th>Name</th> <td><input type='text' class='person-name' value='#{person.escape('name')}'></td></tr>
- <tr><th>Phone</th> <td><input type='text' class='person-phone' value='#{person.escape('phone')}'></td></tr>
- <tr><th>District</th> <td><input type='text' class='person-district' value='#{person.escape('district')}'></td></tr>
- <tr><th>Designation</th> <td><input type='text' class='person-designation' value='#{person.escape('designation')}'></td></tr>
- <tr><th>Tags</th> <td><input type='text' class='person-tags' value='#{person.escape('tags')}'></td></tr>
- <tr><td><button class='person-remove'>remove</button></td></tr>
- </table>
- "
-
-
-class Message extends Backbone.Model
- url: "message"
-
-
-class ConfigureView extends Backbone.View
-
- el: "#content"
-
- events:
- "click #save_google_form_url" : "save"
-
- save: ->
- $.couch.db(@project).saveDoc {
- _id: "google_form"
- live_form_url: $("#google_form_url").val()
- }
-
- render: ->
- $("#content").html "
- URL for #{@project} live google form:
-
- <ol>
- <li>Make your own copy of the <a href='https://docs.google.com/forms/d/12qRAtzhSkRNv6SzSgPPzTmGQm39yzUK5TP-AKcfWvNo/edit?usp=sharing'> Sample SMS Data Form</a>. (Click on 'file', 'make a copy').
- </li>
- <li> Click View live form, once the page opens copy the URL
- </li>
- <li> Paste the URL here, <input id='google_form_url'> and click: <button id='save_google_form_url'>Save google form url</button>
- </li>
- </ol>
- "
-
-class SentView extends Backbone.View
-
- el: "#content"
-
- events:
- "click .send" : "send"
-
- render: ->
- # Rerender if something changes
- $.couch.db(@project).changes().onChange =>
- @render()
-
- columns = "Time, To, Message".split(/,/)
-
- $("#content").html "
- <h2>Sent Messages</h2>
- <table id='sentMessages'>
- <thead>
- <tr>
- #{
- (for header in columns
- "<td>#{header}</td>"
- ).join("")
- }
- </tr>
- </thead>
- <tbody>
- </tbody>
- <tfoot>
- <tr>
- #{
- (for header in columns
- "<td>#{header}</td>"
- ).join("")
- }
- </tr>
- </tfoot>
- </table>
- "
- $.couch.db(@project).allDocs
- include_docs: true
- error: (error) -> console.log JSON.stringify(error)
- success: (results) ->
- for result in results.rows
- if result.doc.to?
- $("table#sentMessages tbody").append "
- <tr>
- <td>#{
- if result.doc.time_sent
- moment(parseInt result.doc.time_sent).format("YYYY-MM-DD HH:mm")
- else
- "Pending"
- }</td>
- <td>#{result.doc.to}</td>
- <td>#{result.doc.message}</td>
- </tr>
-
- "
- $("table#sentMessages").dataTable
- aaSorting: [[0,"desc"]]
-
-class ReceivedView extends Backbone.View
-
- el: "#content"
-
- events:
- "click .send" : "send"
-
- render: =>
- # Rerender if something changes
- $.couch.db(@project).changes().onChange =>
- @render()
-
- columns = "Time, From, Message".split(/,/)
-
- $("#content").html "
- <h2>Received Messages</h2>
- <table id='receivedMessages'>
- <thead>
- <tr>
- #{
- (for header in columns
- "<td>#{header}</td>"
- ).join("")
- }
- </tr>
- </thead>
- <tbody>
- </tbody>
- <tfoot>
- <tr>
- #{
- (for header in columns
- "<td>#{header}</td>"
- ).join("")
- }
- </tr>
- </tfoot>
- </table>
- "
- $.couch.db(@project).allDocs
- include_docs: true
- error: (error) -> console.log JSON.stringify(error)
- success: (results) =>
- @currentNumberOfResults = results.total_rows
- for result in results.rows
- if result.doc.time_received?
- $("table#receivedMessages tbody").append "
- <tr>
- <td>#{moment(parseInt result.doc.time_received).format("YYYY-MM-DD HH:mm")}</td>
- <td>#{result.doc.from}</td>
- <td>#{result.doc.message}</td>
- </tr>
-
- "
- $("table#receivedMessages").dataTable
- aaSorting: [[0,"desc"]]
-
-
-class SendView extends Backbone.View
-
- el: "#content"
-
- events:
- "click .send" : "send"
- "keyup #numbers" : "countNumbers"
- "keyup #text" : "countCharacters"
-
- 'click .clear-numbers' : "clearNumbers"
- 'click .clear-text' : "clearText"
-
- clearText : -> @$el.find("#text").val(''); @countCharacters()
- clearNumbers : -> @$el.find("#numbers").val(''); @countNumbers()
-
- render: ->
- console.log @project
- @$el.html "
- <div>
-
- <h2>Send</h2>
- <div style='margin-bottom: 2em; width:40%; display:inline-block; vertical-align:top;'>
- <label for='numbers'>Phone numbers</label><br>
- <span id='number-phone-numbers' class='info'></span><br>
- <button class='clear-numbers'>Clear</button><br>
- <textarea id='numbers' style='height:200px'></textarea>
- </div>
-
- <div style='width:40%; display:inline-block;vertical-align:top;'>
- <label for='text'>Message</label><br>
- <span id='chars-left' class='info'></span><br>
- <button class='clear-text'>Clear</button><br>
- <textarea id='text'></textarea><br>
- <button class='send'>Send</button>
- </div>
-
- </div>
- "
-
- @countCharacters()
- @countNumbers()
-
- send: ->
-
- numbers = $("#numbers").val().split(/\n/)
-
- $("#log").append "Adding #{numbers.length} message(s) to the outgoing message queue<br>"
-
- for number in numbers
- $.couch.db(@project).saveDoc {
- message: $("#text").val()
- to: number
- }
-
- countNumbers: ->
- value = $("#numbers").val()
- count = 0
- count = value.split(/([^0-9].)/).length unless value.replace(/\s/g,'').length is 0
- $("#number-phone-numbers").text "#{count} numbers entered"
-
- countCharacters: ->
- remaining = 160 - $("#text").val().length
- $("#chars-left").text "#{remaining} characters left"
-
-Pomegranate =
- db_name : window.location.pathname.split("/")[1]
- design_doc : _.last(String(window.location).split("_design/")).split("/")[0]
-
-Pomegranate.router = new Router()
-
-Backbone.couch_connector.config.db_name = Pomegranate.db_name
-Backbone.couch_connector.config.ddoc_name = Pomegranate.design_doc
-Backbone.couch_connector.config.global_changes = false
-
-Backbone.history.start()
-
-Pomegranate.debug = (string) ->
- console.log string
- $("#log").append string + "<br/>"
View
2  cloud_app/_attachments/version
@@ -1 +1 @@
-4b45305
+452dd17

No commit comments for this range

Something went wrong with that request. Please try again.