starwisp.scm 52.3 KB
Newer Older
Dave Griffiths's avatar
Dave Griffiths committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
;; Starwisp Copyright (C) 2013 Dave Griffiths
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Affero General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU Affero General Public License for more details.
;;
;; You should have received a copy of the GNU Affero General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; strings


;; colours
21
(msg "starting up....")
Dave Griffiths's avatar
Dave Griffiths committed
22 23

(define trans-col (list 0 0 0 0))
24 25
(define colour-one (list 0 0 255 100))
(define colour-two (list  127 127 255 100))
Dave Griffiths's avatar
Dave Griffiths committed
26 27 28 29

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; persistent database

30
(define db "/sdcard/symbai/local-symbai.db")
Dave Griffiths's avatar
Dave Griffiths committed
31 32 33 34 35 36 37 38 39 40
(db-open db)
(setup db "local")
(setup db "sync")
(setup db "stream")

(insert-entity-if-not-exists
 db "local" "app-settings" "null" 1
 (list
  (ktv "user-id" "varchar" "No name yet...")))

Dave Griffiths's avatar
Dave Griffiths committed
41
(define entity-types (list "village" "household" "individual"))
42

Dave Griffiths's avatar
Dave Griffiths committed
43
;;(display (db-all db "local" "app-settings"))(newline)
Dave Griffiths's avatar
Dave Griffiths committed
44

Dave Griffiths's avatar
Dave Griffiths committed
45 46 47 48
(define tribes-list '(khasi other))
(define subtribe-list '(khynriam pnar bhoi war other))
(define education-list   '(illiterate literate primary middle high secondary university))
(define married-list '(ever-married currently-married currently-single seperated))
Dave Griffiths's avatar
Dave Griffiths committed
49

Dave Griffiths's avatar
Dave Griffiths committed
50
(define social-types-list '(friendship knowledge prestige))
Dave Griffiths's avatar
Dave Griffiths committed
51 52 53 54
(define social-relationship-list '(mother father sister brother spouse children co-wife spouse-mother spouse-father spouse-brother-wife spouse-sister-husband friend neighbour other))
(define social-residence-list '(same other))
(define social-strength-list '(daily weekly monthly less))

Dave Griffiths's avatar
Dave Griffiths committed
55 56 57
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; user interface abstraction

58 59 60 61 62
;;;;;;;;;;;;; i18n ;;;;;;;;;;;;;;;;;;;;;;


(define i18n-text
  (list
Dave Griffiths's avatar
Dave Griffiths committed
63
   (list 'test-num (list "1.0000000" "1.0000000" "1.0000000"))
64 65 66 67 68 69
   (list 'test-text (list "I am test text" "I am test text" "I am test text"))
   (list 'one (list "one"))
   (list 'two (list "two"))
   (list 'three (list "three"))
   (list 'village (list "Village"))
   (list 'household (list "Household"))
70
   (list 'households (list "Households"))
71
   (list 'individual (list "Individual"))
72
   (list 'individuals (list "Individuals"))
73

74
   (list 'add-item-to-list (list "+"))
75
   (list 'default-village-name (list "New village"))
Dave Griffiths's avatar
Dave Griffiths committed
76

77 78 79 80 81 82
   (list 'title (list "Symbai" "Symbai" "Symbai"))
   (list 'sync (list "Sync" "Sync" "Sync"))
   (list 'languages (list "Choose language" "Choose language" "Choose language"))
   (list 'english (list "English" "English" "English"))
   (list 'khasi (list "Khasi" "Khasi" "Khasi"))
   (list 'hindi (list "Hindi" "Hindi" "Hindi"))
Dave Griffiths's avatar
Dave Griffiths committed
83
   (list 'user-id (list "Your user ID" "User ID" "User ID"))
84 85 86
   (list 'save (list "Save" "Save" "Save"))
   (list 'back (list "Back" "Back" "Back"))
   (list 'off (list "Off" "Off" "Off"))
Dave Griffiths's avatar
Dave Griffiths committed
87
   (list 'villages (list "Villages" "Villages" "Villages"))
88 89 90 91
   (list 'list-empty (list "List empty"))
   (list 'delete (list "Delete"))
   (list 'delete-are-you-sure (list "Are you sure you want to delete this?"))
   (list 'save-are-you-sure (list "Are you sure you want to save changes?"))
Dave Griffiths's avatar
Dave Griffiths committed
92

93 94 95
   ;; individual filter
   (list 'quick-name (list "New person name"))
   (list 'quick-add (list "Quick add"))
96 97 98 99 100
   (list 'find-individual (list "Find individual"))
   (list 'filter (list "Filter"))
   (list 'off (list "Off" "Off" "Off"))
   (list 'name (list "Name"))

101 102 103 104 105 106 107 108 109 110 111
   ;; sync
   (list 'sync-all (list "Sync me!"))
   (list 'sync-syncall (list "Sync everything"))
   (list 'export-data (list "Exporting data"))
   (list 'sync-download (list "Download main DB"))
   (list 'sync-export (list "Email main DB"))
   (list 'email-local (list "Email local DB"))
   (list 'debug (list "Debug"))
   (list 'sync-back (list "Back"))
   (list 'sync-prof (list "Profile"))

Dave Griffiths's avatar
Dave Griffiths committed
112
   ;; village screen
113
   (list 'village-name (list "Village name" "Village name" "Village name"))
Dave Griffiths's avatar
Dave Griffiths committed
114 115 116 117 118 119 120
   (list 'block (list "Block" "Block" "Block"))
   (list 'district (list "District" "District" "District"))
   (list 'car (list "Accessible by car"))
   (list 'household-list (list "Household list"))
   (list 'amenities (list "Amenities"))
   (list 'school (list "School"))
   (list 'present (list "Present"))
Dave Griffiths's avatar
Dave Griffiths committed
121
   (list 'closest-access (list "Closest place of access"))
Dave Griffiths's avatar
Dave Griffiths committed
122 123
   (list 'house-gps (list "GPS"))
   (list 'toilet-gps (list "GPS"))
Dave Griffiths's avatar
Dave Griffiths committed
124
   (list 'school (list "School"))
Dave Griffiths's avatar
Dave Griffiths committed
125 126
   (list 'school-closest-access (list "Access"))
   (list 'school-gps (list "GPS"))
Dave Griffiths's avatar
Dave Griffiths committed
127
   (list 'hospital (list "Hospital/Health care centre"))
Dave Griffiths's avatar
Dave Griffiths committed
128 129
   (list 'hospital-closest-access (list "Access"))
   (list 'hospital-gps (list "GPS"))
Dave Griffiths's avatar
Dave Griffiths committed
130
   (list 'post-office (list "Post Office"))
Dave Griffiths's avatar
Dave Griffiths committed
131 132
   (list 'post-office-closest-access (list "Access"))
   (list 'post-office-gps (list "GPS"))
Dave Griffiths's avatar
Dave Griffiths committed
133
   (list 'railway-station (list "Railway station"))
Dave Griffiths's avatar
Dave Griffiths committed
134 135
   (list 'railway-station-closest-access (list "Access"))
   (list 'railway-station-gps (list "GPS"))
Dave Griffiths's avatar
Dave Griffiths committed
136
   (list 'state-bus-service (list "Inter-state bus service"))
Dave Griffiths's avatar
Dave Griffiths committed
137 138
   (list 'state-bus-service-closest-access (list "Access"))
   (list 'state-bus-service-gps (list "GPS"))
Dave Griffiths's avatar
Dave Griffiths committed
139
   (list 'district-bus-service (list "Inter-village/district bus service"))
Dave Griffiths's avatar
Dave Griffiths committed
140 141
   (list 'district-bus-service-closest-access (list "Access"))
   (list 'district-bus-service-gps (list "GPS"))
Dave Griffiths's avatar
Dave Griffiths committed
142
   (list 'panchayat (list "Village Panchayat Office"))
Dave Griffiths's avatar
Dave Griffiths committed
143 144
   (list 'panchayat-closest-access (list "Access"))
   (list 'panchayat-gps (list "GPS"))
Dave Griffiths's avatar
Dave Griffiths committed
145
   (list 'NGO (list "Presence of NGO's working with them"))
Dave Griffiths's avatar
Dave Griffiths committed
146 147
   (list 'NGO-closest-access (list "Access"))
   (list 'NGO-gps (list "GPS"))
Dave Griffiths's avatar
Dave Griffiths committed
148
   (list 'market (list "Market"))
Dave Griffiths's avatar
Dave Griffiths committed
149 150
   (list 'market-closest-access (list "Access"))
   (list 'market-gps (list "GPS"))
Dave Griffiths's avatar
Dave Griffiths committed
151

152
   ;; household
Dave Griffiths's avatar
Dave Griffiths committed
153 154
   (list 'household-name (list "Household name"))
   (list 'default-household-name (list "A household"))
155 156 157 158 159 160 161 162 163 164 165
   (list 'location (list "House location"))
   (list 'elevation (list "Elevation"))
   (list 'toilet-location (list "Toilet location"))
   (list 'children (list "Children"))
   (list 'male (list "Male"))
   (list 'female (list "Female"))
   (list 'num-pots (list "Number of pots"))
   (list 'adults (list "Adults"))
   (list 'add-individual (list "Add individual"))

   ;; individual
Dave Griffiths's avatar
Dave Griffiths committed
166 167 168
   (list 'default-individual-name (list "A person"))
   (list 'default-family-name (list "A family"))
   (list 'default-photo-id (list "???"))
Dave Griffiths's avatar
Dave Griffiths committed
169 170 171 172 173 174 175 176 177 178
   (list 'name-display (list "Name"))
   (list 'photo-id-display (list "Photo ID"))
   (list 'family-display (list "Family"))
   (list 'details-button (list "Details"))
   (list 'family-button (list "Family"))
   (list 'migration-button (list "Migration"))
   (list 'income-button (list "Income"))
   (list 'geneaology-button (list "Geneaology"))
   (list 'social-button (list "Social"))
   (list 'agreement-button (list "Agreement"))
179
   (list 'is-a-child (list "Child"))
180 181 182

   ;; details
   (list 'change-photo (list "Change photo"))
Dave Griffiths's avatar
Dave Griffiths committed
183 184 185
   (list 'details-name (list "Name"))
   (list 'details-photo-id (list "Photo ID"))
   (list 'details-family (list "Family"))
186 187
   (list 'tribe (list "Tribe"))
   (list 'sub-tribe (list "Sub tribe"))
Dave Griffiths's avatar
Dave Griffiths committed
188 189 190 191 192
   (list 'khasi (list "Khasi"))
   (list 'khynriam (list "Khynriam"))
   (list 'pnar (list "Pnar"))
   (list 'bhoi (list "Bhoi"))
   (list 'war (list "War"))
193 194 195 196
   (list 'other (list "Other"))
   (list 'age (list "Age"))
   (list 'gender (list "Gender"))
   (list 'education (list "Education"))
Dave Griffiths's avatar
Dave Griffiths committed
197 198 199 200 201 202 203 204
   (list 'illiterate (list "Illiterate"))
   (list 'literate (list "Literate"))
   (list 'primary (list "Primary 1-5"))
   (list 'middle (list "Middle 6-8"))
   (list 'high (list "High 9-10"))
   (list 'secondary (list "Higher Secondary"))
   (list 'university (list "University"))

205 206 207

   ;; family
   (list 'spouse (list "Spouse"))
Dave Griffiths's avatar
Dave Griffiths committed
208
   (list 'change-id (list "Change"))
209 210 211 212 213 214 215 216
   (list 'head-of-house (list "Head of house"))
   (list 'marital-status (list "Marital status"))
   (list 'ever-married (list "Ever married"))
   (list 'currently-married (list "Currently married"))
   (list 'currently-single (list "Currently single"))
   (list 'seperated (list "Seperated/divorced"))
   (list 'times-married (list "How many times married"))
   (list 'change-spouse (list "Change/add spouse"))
Dave Griffiths's avatar
Dave Griffiths committed
217 218 219 220
   (list 'children-living (list "Living"))
   (list 'children-dead (list "Dead"))
   (list 'children-together (list "Living together"))
   (list 'children-apart (list "Living apart"))
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
   (list 'residence-after-marriage (list "Residence after marriage"))
   (list 'birthplace (list "Birthplace"))
   (list 'spouse-village (list "Spouses natal village"))
   (list 'num-siblings (list "Number of living siblings of the same sex born from same mother"))
   (list 'birth-order (list "Birth order amoung currently living same sex siblings born from same mother"))

   ;; migration
   (list 'length-time (list "Length of time lived in this village (years)"))
   (list 'place-of-birth (list "Place of birth"))
   (list 'num-residence-changes (list "Number of time place of residence changed since birth"))
   (list 'village-visits-month (list "Number of times you have visited another village in the last month"))
   (list 'village-visits-year (list "Number of times you have visited another village in the last year (i.e. betwen last summer and this summer)"))

   ;; income
   (list 'occupation (list "Occupation"))
   (list 'occupation (list "Occupation"))
   (list 'agriculture (list "Agriculture"))
   (list 'gathering (list "Gathering"))
   (list 'labour (list "Labour"))
   (list 'cows (list "Cows"))
   (list 'fishing (list "Fishing"))
Dave Griffiths's avatar
Dave Griffiths committed
242 243 244 245 246
   (list 'num-people-in-house (list "People living in house"))
   (list 'contribute (list "Contribute to family earnings?"))
   (list 'own-land (list "Own land?"))
   (list 'rent-land (list "Rent out your land?"))
   (list 'hire-land (list "Hire land?"))
247 248 249 250 251 252 253 254 255 256 257
   (list 'crops (list "Crops"))
   (list 'crop (list "Crop"))
   (list 'unit (list "Unit"))
   (list 'quantity (list "Quantity"))
   (list 'used-or-eaten (list "Used/Eaten"))
   (list 'sold (list "Sold"))
   (list 'seed (list "Seed (hybrid/local)"))
   (list 'house-type (list "House type"))
   (list 'concrete (list "Concrete"))
   (list 'tin (list "Tin"))
   (list 'thatched (list "Thatched"))
Dave Griffiths's avatar
Dave Griffiths committed
258 259
   (list 'loan (list "Outstanding loans"))
   (list 'earning (list "One day's earnings"))
260 261 262 263
   (list 'in-the-home (list "In the home"))
   (list 'radio (list "Radio"))
   (list 'tv (list "TV"))
   (list 'mobile (list "Mobile phone"))
Dave Griffiths's avatar
Dave Griffiths committed
264 265
   (list 'visit-market (list "Tribal market visits"))
   (list 'town-sell (list "Town or city visits"))
266 267 268 269 270 271 272 273

   ;; geneaology
   (list 'mother (list "Mother"))
   (list 'father (list "Father"))
   (list 'change-mother (list "Change mother"))
   (list 'change-father (list "Change father"))
   (list 'alive (list "Alive"))
   (list 'sex (list "Sex"))
Dave Griffiths's avatar
Dave Griffiths committed
274 275

   ;; social
Dave Griffiths's avatar
Dave Griffiths committed
276 277 278 279
   (list 'social-type (list "Type"))
   (list 'friendship (list "Friendship"))
   (list 'knowledge (list "Knowledge"))
   (list 'prestige (list "Prestige"))
Dave Griffiths's avatar
Dave Griffiths committed
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
   (list 'social-one (list "One"))
   (list 'social-two (list "Two"))
   (list 'social-three (list "Three"))
   (list 'social-four (list "Four"))
   (list 'social-five (list "Five"))
   (list 'social-relationship (list "Relationship"))
   (list 'social-residence (list "Residence"))
   (list 'social-strength (list "Strength"))
   (list 'mother (list "Mother"))
   (list 'father (list "Father"))
   (list 'sister (list "Sister"))
   (list 'brother (list "Brother"))
   (list 'spouse (list "Spouse"))
   (list 'children (list "Children"))
   (list 'co-wife (list "Co-wife"))
   (list 'spouse-mother (list "Spouse's mother"))
   (list 'spouse-father (list "Spouse's father"))
   (list 'spouse-brother-wife (list "Spouse's brother's wife"))
   (list 'spouse-sister-husband (list "Spouse's sister's husband"))
   (list 'friend (list "Friend"))
   (list 'neighbour (list "Neighbour"))
   (list 'same (list "Same"))
   (list 'daily (list "Daily"))
   (list 'weekly (list "Weekly"))
   (list 'monthly (list "Monthly"))
   (list 'less (list "Less"))
306 307
   ))

Dave Griffiths's avatar
Dave Griffiths committed
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
(define village-ktvlist
  (list
   (ktv-create "name" "varchar" (mtext-lookup 'default-village-name))
   (ktv-create "block" "varchar" "")
   (ktv-create "district" "varchar" "test")
   (ktv-create "car" "int" 0)))

(define household-ktvlist
  (list
   (ktv-create "name" "varchar" (mtext-lookup 'default-household-name))
   (ktv-create "num-pots" "int" 0)
   (ktv-create "house-lat" "real" 0) ;; get from current location?
   (ktv-create "house-lon" "real" 0)
   (ktv-create "toilet-lat" "real" 0)
   (ktv-create "toilet-lon" "real" 0)))

324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
(define individual-ktvlist
  (list
   (ktv-create "name" "varchar" (mtext-lookup 'default-individual-name))
   (ktv-create "family" "varchar" (mtext-lookup 'default-family-name))
   (ktv-create "photo-id" "varchar" (mtext-lookup 'default-photo-id))
   (ktv-create "photo" "file" "none")
   (ktv-create "tribe" "varchar" "none")
   (ktv-create "subtribe" "varchar" "none")
   (ktv-create "child" "int" 0)
   (ktv-create "age" "int" 0)
   (ktv-create "gender" "varchar" "Female")
   (ktv-create "education" "varchar" "none")
   (ktv-create "head-of-house" "varchar" "none")
   (ktv-create "marital-status" "varchar" "none")
   (ktv-create "times-married" "int" 0)
   (ktv-create "id-spouse" "varchar" "none")
   (ktv-create "children-living" "int" 0)
   (ktv-create "children-dead" "int" 0)
   (ktv-create "children-together" "int" 0)
   (ktv-create "children-apart" "int" 0)
   (ktv-create "residence-after-marriage" "varchar" "none")
   (ktv-create "num-siblings" "int" 0)
   (ktv-create "birth-order" "int" 0)
   (ktv-create "length-time" "int" 0)
   (ktv-create "place-of-birth" "varchar" "none")
   (ktv-create "num-residence-changes" "int" 0)
   (ktv-create "village-visits-month" "int" 0)
   (ktv-create "village-visits-year" "int" 0)
   (ktv-create "occupation" "varchar" "none")
   (ktv-create "contribute" "int" 0)
   (ktv-create "own-land" "int" 0)
   (ktv-create "rent-land" "int" 0)
   (ktv-create "hire-land" "int" 0)
   (ktv-create "house-type" "varchar" "none")
   (ktv-create "loan" "int" 0)
   (ktv-create "earning" "int" 0)
   (ktv-create "radio" "int" 0)
   (ktv-create "tv" "int" 0)
   (ktv-create "mobile" "int" 0)
   (ktv-create "visit-market" "int" 0)
   (ktv-create "town-sell" "int" 0)
   ))
Dave Griffiths's avatar
Dave Griffiths committed
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;

(define (debug! txt)
  (set-current! 'debug-text (string-append txt "\n" (get-current 'debug-text ""))))

(define (update-debug)
  (update-widget 'debug-text-view (get-id "sync-debug") 'text
                 (get-current 'debug-text "")))

(define (debug-timer-cb)
  (append
   (cond
    ((get-current 'sync-on #f)
     (set-current! 'upload 0)
     (set-current! 'download 0)
     (connect-to-net
      (lambda ()
Dave Griffiths's avatar
Dave Griffiths committed
385
        (msg "connected, going in...")
Dave Griffiths's avatar
Dave Griffiths committed
386 387 388
        (append
         (list (toast "sync-cb"))
         (upload-dirty db)
Dave Griffiths's avatar
Dave Griffiths committed
389
         (if (have-dirty? db "sync") '() (suck-new db "sync"))))))
Dave Griffiths's avatar
Dave Griffiths committed
390 391
    (else '()))
   (list
Dave Griffiths's avatar
Dave Griffiths committed
392
    (delayed "debug-timer" (+ 30000 (random 5000)) debug-timer-cb)
Dave Griffiths's avatar
Dave Griffiths committed
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
    (update-debug))))


(define pf-length 20) ;; minutes...

(define (timer-cb)
  (set-current!
   'timer-seconds
   (- (get-current 'timer-seconds 59) 1))
  (append
   (cond
    ((< (get-current 'timer-seconds 59) 0)
     (set-current! 'timer-minutes (- (get-current 'timer-minutes pf-length) 1))
     (set-current! 'timer-seconds 59)
     (cond ((< (get-current 'timer-minutes pf-length) 1)
            (list
             (alert-dialog
              "pup-focal-end"
              "Pup focal time is up, have you finished?"
              (lambda (v)
                (cond
                 ((eqv? v 1)
                  (list (finish-activity 1)))
                 (else
                  (set-current! 'timer-minutes 1)
                  (list)))))))
           (else
            (list (replace-fragment (get-id "pf-top") "pf-scan1")))))
    (else '()))
   (list
    (delayed "timer" 1000 timer-cb)
    (update-widget
     'text-view (get-id "pf-timer-time-minutes") 'text
     (string-append (number->string (get-current 'timer-minutes pf-length))))
    (update-widget
     'text-view (get-id "pf-timer-time") 'text
     (string-append (number->string (get-current 'timer-seconds 59))))
    )))


(define (force-pause)
  (list
   (delayed "timer" 1000 (lambda () '()))
   (update-widget 'toggle-button (get-id "pf-pause") 'checked 1)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; fragments

(define-fragment-list

  (fragment
444 445
   "top"
   (horiz
Dave Griffiths's avatar
Dave Griffiths committed
446
    (image-view 0 "face" (layout 48 64 -1 'centre 0))
447
    (text-view (make-id "title") "" 30
448 449 450 451
               (layout 'fill-parent 'fill-parent 0.25 'centre 10))

    (linear-layout
     0 'vertical
Dave Griffiths's avatar
Dave Griffiths committed
452
     (layout 'fill-parent 'wrap-content 0.75 'centre 0)
453 454 455 456
     (list 0 0 0 0)

     (list
      (text-view (make-id "") 'name 20
Dave Griffiths's avatar
Dave Griffiths committed
457
                 (layout 'fill-parent 'wrap-content 1 'centre 0))
458
      (text-view (make-id "") 'photo-id 20
Dave Griffiths's avatar
Dave Griffiths committed
459
                 (layout 'fill-parent 'wrap-content 1 'centre 0)))))
Dave Griffiths's avatar
Dave Griffiths committed
460 461 462
   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
463 464 465
     (list
      (update-widget 'text-view (get-id "title") 'text
                     (get-current 'activity-title "Title not set"))))
Dave Griffiths's avatar
Dave Griffiths committed
466 467 468 469 470 471
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))


472 473 474 475
  (fragment
   "bottom"
   (linear-layout
    0 'horizontal
Dave Griffiths's avatar
Dave Griffiths committed
476
    (layout 'fill-parent 'fill-parent 1 'centre 0)
477 478
    (list 0 0 0 0)
    (list
479
     (mbutton-scale
480
      'save
481 482 483 484
      (lambda ()
        (list
         (alert-dialog
          "ok-check"
485
          (mtext-lookup 'save-are-you-sure)
486 487 488 489
          (lambda (v)
            (cond
             ((eqv? v 1)
              (entity-update-values!)
490
              (list))
491 492
             (else
              (list))))))))
493
     (mbutton-scale 'back (lambda () (list (finish-activity 1))))))
494 495 496 497 498 499 500 501
   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
     (list))
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))
Dave Griffiths's avatar
Dave Griffiths committed
502 503 504 505 506 507


  )

(msg "one")

Dave Griffiths's avatar
Dave Griffiths committed
508 509 510 511
(define (build-activity . contents)
  (vert-fill
   (relative
    '(("parent-top"))
512
    colour-one ;;(list 100 100 255 127)
Dave Griffiths's avatar
Dave Griffiths committed
513 514 515 516 517 518 519 520 521
    (build-fragment "top" (make-id "top") fillwrap))

   (scroll-view-vert
    0 (layout 'fill-parent 'fill-parent 1 'centre 0)
    (list
     (apply vert-fill contents)))

   (relative
    '(("parent-bottom"))
522
    colour-one
Dave Griffiths's avatar
Dave Griffiths committed
523 524 525 526
    (vert
     (spacer 5)
     (build-fragment "bottom" (make-id "bottom") fillwrap)))))

527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559

(define (grid-ify widgets n)
  (map
   (lambda (w)
     (linear-layout
      0 'horizontal
      (layout 'wrap-content 'wrap-content 1 'left 0)
      (list 0 0 0 0)
      w))
   (chop widgets n)))

(define (filter-set! l)
  (set-current! 'individual-filter l))

(define (filter-clear!)
  (filter-set! '()))

(define (filter-add! f)
  (set-current!
   'individual-filter
   (merge-filter f (get-current 'individual-filter '()))))

(define (filter-remove! key)
  (set-current!
   'individual-filter
   (delete-filter key (get-current 'individual-filter '()))))

(define (filter-get)
  (get-current 'individual-filter '()))

(define button-size (list (inexact->exact (round (* 192 0.9)))
                          (inexact->exact (round (* 256 0.9)))))

560

561
(define (update-individual-filter)
Dave Griffiths's avatar
Dave Griffiths committed
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
  (let ((search (db-filter-only db "sync" "individual" (filter-get)
                                (list
                                 (list "photo" "file")
                                 (list "name" "varchar")))))
    (update-widget
     'linear-layout (get-id "choose-pics") 'contents
     (grid-ify
      (map
       (lambda (e)
         (let* ((id (ktv-get e "unique_id"))
                (image-name (ktv-get e "photo"))
                (image (if (image-invalid? image-name)
                           "face" (string-append "/sdcard/symbai/files/" image-name))))
           (cond
            ((> (length search) 50)
577 578
             (button
              (make-id (string-append "chooser-" id))
Dave Griffiths's avatar
Dave Griffiths committed
579
              (ktv-get e "name") 30 (layout (car button-size) (/ (cadr button-size) 3) 1 'centre 5)
580 581
              (lambda ()
                (set-current! 'choose-result id)
Dave Griffiths's avatar
Dave Griffiths committed
582 583 584 585
                (list (finish-activity 0)))))

            ((equal? image "face")
             (button
586
              (make-id (string-append "chooser-" id))
Dave Griffiths's avatar
Dave Griffiths committed
587
              (ktv-get e "name") 30 (layout (car button-size) (cadr button-size) 1 'centre 5)
588 589
              (lambda ()
                (set-current! 'choose-result id)
Dave Griffiths's avatar
Dave Griffiths committed
590
                (list (finish-activity 0)))))
591

Dave Griffiths's avatar
Dave Griffiths committed
592 593 594 595 596 597 598 599 600 601 602 603 604 605
            (else
             (vert
              (image-button
               (make-id (string-append "chooser-" id))
               image (layout (car button-size) (cadr button-size) 1 'centre 5)
               (lambda ()
                 (set-current! 'choose-result id)
                 (list (finish-activity 0))))
              (text-view 0 (ktv-get e "name") 20 (layout 'wrap-content 'wrap-content -1 'centre 0)))
             ))))
       search)
     3))))

(define (image/name-from-unique-id db table unique-id)
606
  (let ((e (get-entity-by-unique db table unique-id)))
Dave Griffiths's avatar
Dave Griffiths committed
607 608 609
    (list
     (ktv-get e "name")
     (ktv-get e "photo"))))
610 611 612 613 614 615

(define (build-person-selector id key filter request-code)
  (vert
   (mtitle id)
   (image-view (make-id (string-append (symbol->string id) "-image"))
               "face" (layout 240 320 -1 'centre 0))
Dave Griffiths's avatar
Dave Griffiths committed
616
   (mtext-small (string->symbol (string-append (symbol->string id) "-text")))
617 618 619 620 621 622 623 624
   (button
    (make-id (string-append "change-" (symbol->string id)))
    (mtext-lookup 'change-id)
    40 (layout 'fill-parent 'wrap-content -1 'centre 5)
    (lambda ()
      (filter-set! filter)
      (list (start-activity "individual-chooser" request-code ""))))))

Dave Griffiths's avatar
Dave Griffiths committed
625 626 627 628 629
(define (build-small-person-selector id key filter request-code)
  (vert
   (mtitle id)
   (image-view (make-id (string-append (symbol->string id) "-image"))
               "face" (layout 120 160 -1 'centre 0))
Dave Griffiths's avatar
Dave Griffiths committed
630
   (mtext-small (string->symbol (string-append (symbol->string id) "-text")))
Dave Griffiths's avatar
Dave Griffiths committed
631 632 633 634 635 636 637 638 639
   (button
    (make-id (string-append "change-" (symbol->string id)))
    (mtext-lookup 'change-id)
    40 (layout 'fill-parent 'wrap-content -1 'centre 5)
    (lambda ()
      (filter-set! filter)
      (list (start-activity "individual-chooser" request-code ""))))))


640 641 642 643
;; from activity on result with request id: choose-code
;; todo determine *which* selector this came from...
(define (person-selector-return request-code key choose-code)
  (when (eqv? request-code choose-code)
644
        (entity-set-value! key "varchar" (get-current 'choose-result "not set"))))
645 646 647 648 649 650

;; need to load from across entities, so need db, table
(define (update-person-selector db table id key)
  (msg "update-person-selector" key)
  (let ((entity-id (entity-get-value key)))
    (msg "entity-id is" entity-id)
Dave Griffiths's avatar
Dave Griffiths committed
651 652 653 654 655 656 657 658 659 660 661 662
    (let ((image-name (image/name-from-unique-id db table entity-id))
          (id (get-id (string-append (symbol->string id) "-image")))
          (text-id (get-id (string-append (symbol->string id) "-text"))))
      (msg "image-name is" (cadr image-name) (image-invalid? (cadr image-name)))
      (if (image-invalid? (cadr image-name))
          (list
           (update-widget 'image-view id 'image "face")
           (update-widget 'text-view text-id 'text (car image-name)))
          (list
           (update-widget 'text-view text-id 'text (car image-name))
           (update-widget 'image-view id 'external-image
                          (string-append dirname "files/" (cadr image-name))))))))
663

Dave Griffiths's avatar
Dave Griffiths committed
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
(define (build-social-connection id key type request-code)
  (let ((id-text (string-append (symbol->string id))))
    (horiz
     (build-small-person-selector id key (list) request-code)
     (mspinner-other-vert
      (string->symbol (string-append id-text "-relationship"))
      'social-relationship
      social-relationship-list
      (lambda (v)
        (entity-set-value! (string-append key "-relationship") "varchar" v) '()))
     (mspinner-other-vert
      (string->symbol (string-append id-text "-residence"))
      'social-residence
      social-residence-list
      (lambda (v)
        (entity-set-value! (string-append key "-residence") "varchar" v) '()))
     (vert
      (text-view 0 (mtext-lookup 'social-strength)
                 30 (layout 'wrap-content 'wrap-content 1 'centre 10))
      (spinner
Dave Griffiths's avatar
Dave Griffiths committed
684
       (make-id (dbg (string-append id-text "-strength-spinner")))
Dave Griffiths's avatar
Dave Griffiths committed
685 686 687 688 689 690 691 692 693 694 695
       (map mtext-lookup  social-strength-list)
       (layout 'wrap-content 'wrap-content 1 'centre 0)
       (lambda (v)
         (entity-set-value! (string-append key "-strength") "varchar" v) '()))))))

(define (social-connection-return request-code key choose-code)
  (when (eqv? request-code choose-code)
        (entity-set-value! key "varchar" (get-current 'choose-result "not set"))))

(define (update-social-connection db table id key type request-code)
  (let ((id-text (string-append (symbol->string id))))
Dave Griffiths's avatar
Dave Griffiths committed
696
    (append
697
     (update-person-selector db table id key)
Dave Griffiths's avatar
Dave Griffiths committed
698 699 700 701 702 703 704 705 706 707 708 709 710
     (list
      (mupdate-spinner-other
       (string->symbol (string-append id-text "-relationship"))
       (string-append key "-relationship")
       social-relationship-list)
      (mupdate-spinner-other
       (string->symbol (string-append id-text "-residence"))
       (string-append key "-residence")
       social-residence-list)
      (mupdate-spinner
       (string->symbol (dbg (string-append id-text "-strength")))
       (string-append key "-strength")
       social-strength-list))
Dave Griffiths's avatar
Dave Griffiths committed
711 712
     )))

Dave Griffiths's avatar
Dave Griffiths committed
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
(define (build-amenity-widgets id shade)
  (let ((id-text (symbol->string id)))
    (horiz-colour
     (if shade colour-one colour-two)
     (mtoggle-button-scale
      id (lambda (v)
           (entity-set-value! id-text "int" v) '()))
     (medit-text-scale
      (string->symbol (string-append id-text "-closest-access"))
      "normal" (lambda (v) (entity-set-value!
                            (string-append id-text "-closest-access")
                            "varchar" v) '()))
     (vert
      (mbutton-scale
       (string->symbol (string-append id-text "-gps"))
       (lambda ()  (do-gps
                    (string->symbol (string-append id-text "-gps"))
                    (string-append id-text "-gps"))))
Dave Griffiths's avatar
Dave Griffiths committed
731 732
      (mtext-small (string->symbol (string-append id-text "-gps-lat")))
      (mtext-small (string->symbol (string-append id-text "-gps-lon")))))))
Dave Griffiths's avatar
Dave Griffiths committed
733 734 735 736 737 738 739 740 741 742 743 744 745 746

(define (update-amenity-widgets id)
  (let ((id-text (symbol->string id)))
    (append
     (list
      (mupdate 'toggle-button id id-text)
      (mupdate 'edit-text
               (string->symbol (string-append id-text "-closest-access"))
               (string-append id-text "-closest-access")))
     (mupdate-gps
      (string->symbol (string-append id-text "-gps"))
      (string-append id-text "-gps")))))


Dave Griffiths's avatar
Dave Griffiths committed
747 748 749
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; activities

750
(define photo-code 999)
751
(define choose-code 998)
752 753 754
(define spouse-request-code 997)
(define mother-request-code 996)
(define father-request-code 995)
Dave Griffiths's avatar
Dave Griffiths committed
755

Dave Griffiths's avatar
Dave Griffiths committed
756 757 758 759 760 761
(define social-request-code-one 994)
(define social-request-code-two 993)
(define social-request-code-three 992)
(define social-request-code-four 991)
(define social-request-code-five 990)

Dave Griffiths's avatar
Dave Griffiths committed
762 763 764 765
(define-activity-list

  (activity
   "main"
766 767 768 769
   (build-activity
    (mtitle 'title)
    (horiz
     (medit-text 'user-id "normal" (lambda () (list)))
770
     (mbutton-scale 'sync (lambda () (list (start-activity "sync" 0 "")))))
771

772 773 774
    (horiz
     (mspinner 'languages (list 'english 'khasi 'hindi) (lambda (c) (list)))
     (mbutton-scale 'find-individual (lambda () (list (start-activity "individual-chooser" choose-code "")))))
775
    (build-list-widget
Dave Griffiths's avatar
Dave Griffiths committed
776
     db "sync" 'villages "village" "village" (lambda () #f)
Dave Griffiths's avatar
Dave Griffiths committed
777
     village-ktvlist))
778

779
   (lambda (activity arg)
780
     (set-current! 'activity-title "Main screen")
781 782
     (activity-layout activity))
   (lambda (activity arg)
Dave Griffiths's avatar
Dave Griffiths committed
783 784 785 786 787 788 789
     (list
      (gps-start "gps" (lambda (loc)
                         (set-current! 'location loc)
                         (list (toast (string-append
                                       (number->string (car loc)) ", "
                                       (number->string (cadr loc)))))))
      (update-list-widget db "sync" "village" "village" #f)))
790 791 792 793
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
794 795
   (lambda (activity requestcode resultcode)
     (cond
796 797
      ((eqv? requestcode choose-code)
       (list (start-activity "individual" 0 (get-current 'choose-result 0))))
798 799 800 801 802 803 804
      ((eqv? requestcode photo-code)
       (msg "camera returned" resultcode)
       (list (update-widget
              'image-view (get-id "image")
              'external-image (string-append dirname "photo.jpg"))))
      (else
       '()))))
805 806 807 808


  (activity
   "village"
Dave Griffiths's avatar
Dave Griffiths committed
809 810
     (build-activity
      (horiz
811 812
       (medit-text 'village-name "normal" (lambda (v) (entity-set-value! "name" "varchar" v) '()))
       (medit-text 'block "normal" (lambda (v) (entity-set-value! "block" "varchar" v) '())))
Dave Griffiths's avatar
Dave Griffiths committed
813
      (horiz
814 815
       (medit-text 'district "normal" (lambda (v) (entity-set-value! "district" "varchar" v) '()))
       (mtoggle-button-scale 'car (lambda (v) (entity-set-value! "car" "int" v) '())))
816

Dave Griffiths's avatar
Dave Griffiths committed
817 818 819 820
      (mbutton 'household-list
               (lambda ()
                 (list (start-activity "household-list" 0
                                       (get-current 'village #f)))))
821

Dave Griffiths's avatar
Dave Griffiths committed
822
      (mtitle 'amenities)
Dave Griffiths's avatar
Dave Griffiths committed
823 824 825 826 827 828 829 830 831 832
      (build-amenity-widgets 'school #t)
      (build-amenity-widgets 'hospital #f)
      (build-amenity-widgets 'post-office #t)
      (build-amenity-widgets 'railway-station #f)
      (build-amenity-widgets 'state-bus-service #t)
      (build-amenity-widgets 'district-bus-service #f)
      (build-amenity-widgets 'panchayat #t)
      (build-amenity-widgets 'NGO #f)
      (build-amenity-widgets 'market #t)
      (delete-button))
Dave Griffiths's avatar
Dave Griffiths committed
833
   (lambda (activity arg)
834
     (set-current! 'activity-title "Village")
Dave Griffiths's avatar
Dave Griffiths committed
835 836
     (activity-layout activity))
   (lambda (activity arg)
837
     (entity-init! db "sync" "village" (get-entity-by-unique db "sync" arg))
838
     (set-current! 'village arg)
Dave Griffiths's avatar
Dave Griffiths committed
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854
     (append
      (list
       (mupdate 'edit-text 'village-name "name")
       (mupdate 'edit-text 'block "block")
       (mupdate 'edit-text 'district "district")
       (mupdate 'toggle-button 'car "car"))
      (update-amenity-widgets 'school)
      (update-amenity-widgets 'hospital)
      (update-amenity-widgets 'post-office)
      (update-amenity-widgets 'railway-station)
      (update-amenity-widgets 'state-bus-service)
      (update-amenity-widgets 'district-bus-service)
      (update-amenity-widgets 'panchayat)
      (update-amenity-widgets 'NGO)
      (update-amenity-widgets 'market)))

Dave Griffiths's avatar
Dave Griffiths committed
855 856 857 858
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
Dave Griffiths's avatar
Dave Griffiths committed
859
   (lambda (activity requestcode resultcode) '()))
Dave Griffiths's avatar
Dave Griffiths committed
860

Dave Griffiths's avatar
Dave Griffiths committed
861 862 863 864

  (activity
   "household-list"
   (build-activity
865
    (build-list-widget
Dave Griffiths's avatar
Dave Griffiths committed
866
     db "sync" 'households "household" "household" (lambda () (get-current 'village #f))
Dave Griffiths's avatar
Dave Griffiths committed
867
     household-ktvlist))
Dave Griffiths's avatar
Dave Griffiths committed
868
   (lambda (activity arg)
869
     (set-current! 'activity-title "Household List")
Dave Griffiths's avatar
Dave Griffiths committed
870
     (activity-layout activity))
871
   (lambda (activity arg)
Dave Griffiths's avatar
Dave Griffiths committed
872
     (msg "rebuilding household list with" arg)
Dave Griffiths's avatar
Dave Griffiths committed
873 874
     (list (update-list-widget
            db "sync" "household" "household" arg)))
Dave Griffiths's avatar
Dave Griffiths committed
875 876 877 878 879 880 881 882 883
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
   "household"
   (build-activity
884
    (horiz
885 886
     (medit-text 'household-name "normal" (lambda (v) (entity-set-value! "name" "varchar" v) '()))
     (medit-text 'num-pots "numeric" (lambda (v) (entity-set-value! "num-pots" "int" v) '())))
887 888
    (horiz
     (vert
Dave Griffiths's avatar
Dave Griffiths committed
889 890 891 892
      (mtext 'location)
      (mbutton 'house-gps (lambda () (do-gps 'house "house")))
      (mtext-small 'house-lat)
      (mtext-small 'house-lon))
893
     (vert
Dave Griffiths's avatar
Dave Griffiths committed
894 895 896 897 898
      (mtext 'toilet-location)
      (mbutton 'toilet-gps (lambda () (do-gps 'toilet "toilet")))
      (mtext-small 'toilet-lat)
      (mtext-small 'toilet-lon)))

899 900

    (build-list-widget
Dave Griffiths's avatar
Dave Griffiths committed
901 902
     db "sync" 'individuals "individual" "individual"
     (lambda () (get-current 'household #f))
903
     individual-ktvlist)
Dave Griffiths's avatar
Dave Griffiths committed
904

Dave Griffiths's avatar
Dave Griffiths committed
905
    (delete-button))
Dave Griffiths's avatar
Dave Griffiths committed
906
   (lambda (activity arg)
907
     (set-current! 'activity-title "Household")
Dave Griffiths's avatar
Dave Griffiths committed
908
     (activity-layout activity))
909 910 911
   (lambda (activity arg)
     (entity-init! db "sync" "household" (get-entity-by-unique db "sync" arg))
     (set-current! 'household arg)
Dave Griffiths's avatar
Dave Griffiths committed
912 913 914 915 916 917 918
     (append
      (list
       (update-list-widget db "sync" "individual" "individual" arg)
       (mupdate 'edit-text 'household-name "name")
       (mupdate 'edit-text 'num-pots "num-pots"))
      (mupdate-gps 'house "house")
      (mupdate-gps 'toilet "toilet")))
919

Dave Griffiths's avatar
Dave Griffiths committed
920 921 922 923 924 925 926 927 928
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
   "individual"
   (build-activity
929 930 931
    (horiz
     (image-view (make-id "photo") "face" (layout 240 320 -1 'centre 10))
     (vert
Dave Griffiths's avatar
Dave Griffiths committed
932
      (mtext 'name-display)
933
      (spacer 20)
Dave Griffiths's avatar
Dave Griffiths committed
934
      (mtext 'family-display)
935
      (spacer 20)
936 937 938 939
      (mtext 'photo-id-display)
      (spacer 20)
      (mtoggle-button-scale 'is-a-child (lambda (v) (entity-set-value! "child" "int" v) '()))
      ))
940
    (mbutton 'agreement-button (lambda () (list (start-activity "agreement" 0 ""))))
941
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
942 943
     (mbutton-scale 'details-button (lambda () (list (start-activity "details" 0 ""))))
     (mbutton-scale 'family-button (lambda () (list (start-activity "family" 0 "")))))
944
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
945 946
     (mbutton-scale 'migration-button (lambda () (list (start-activity "migration" 0 ""))))
     (mbutton-scale 'income-button (lambda () (list (start-activity "income" 0 "")))))
947
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
948 949
     (mbutton-scale 'geneaology-button (lambda () (list (start-activity "geneaology" 0 ""))))
     (mbutton-scale 'social-button (lambda () (list (start-activity "social" 0 "")))))
950
    (spacer 20)
Dave Griffiths's avatar
Dave Griffiths committed
951
    (delete-button))
952

Dave Griffiths's avatar
Dave Griffiths committed
953
   (lambda (activity arg)
954
     (set-current! 'activity-title "Individual")
Dave Griffiths's avatar
Dave Griffiths committed
955
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
956 957 958 959
   (lambda (activity arg)
     (entity-init! db "sync" "individual" (get-entity-by-unique db "sync" arg))
     (set-current! 'individual arg)
     (list
Dave Griffiths's avatar
Dave Griffiths committed
960 961 962
      (mupdate 'text-view 'name-display "name")
      (mupdate 'text-view 'family-display "family")
      (mupdate 'text-view 'photo-id-display "photo-id")
963 964
      (mupdate 'image-view 'photo "photo")
      (mupdate 'toggle-button 'is-a-child "child")))
Dave Griffiths's avatar
Dave Griffiths committed
965 966 967 968 969 970 971 972 973
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
   "details"
   (build-activity
974
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
975

976
     (vert
Dave Griffiths's avatar
Dave Griffiths committed
977
      (image-view (make-id "photo") "face" (layout 240 320 -1 'centre 10))
978 979 980
      (mbutton
       'change-photo
       (lambda ()
981 982
         (set-current!
          'photo-name (string-append (entity-get-value "unique_id") "-" (get-unique "p") "-face.jpg"))
Dave Griffiths's avatar
Dave Griffiths committed
983
         (list
984
          (take-photo (string-append dirname "files/" (get-current 'photo-name "")) photo-code))
Dave Griffiths's avatar
Dave Griffiths committed
985 986
         )))

987
     (vert
988 989 990 991 992
      (medit-text 'details-name "normal" (lambda (v) (entity-set-value! "name" "varchar" v) '()))
      (medit-text 'details-family "normal" (lambda (v) (entity-set-value! "family" "varchar" v) '()))
      (medit-text 'details-photo-id "normal" (lambda (v) (entity-set-value! "photo-id" "varchar" v) '()))))
    (mspinner-other 'tribe tribes-list (lambda (v) (msg "tribe now:" v) (entity-set-value! "tribe" "varchar" v) '()))
    (mspinner-other 'sub-tribe subtribe-list (lambda (v) (entity-set-value! "subtribe" "varchar" v) '()))
993
    (horiz
994 995 996
     (medit-text 'age "numeric" (lambda (v) (entity-set-value! "age" "int" v) '()))
     (mspinner 'gender '(male female) (lambda (v) (entity-set-value! "gender" "varchar" v) '()))
     (mspinner 'education education-list (lambda (v) (entity-set-value! "education" "varchar" v) '())))
Dave Griffiths's avatar
Dave Griffiths committed
997 998
    )
   (lambda (activity arg)
999
     (set-current! 'activity-title "Individual details")
Dave Griffiths's avatar
Dave Griffiths committed
1000
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
1001 1002 1003 1004 1005
   (lambda (activity arg)
     (list
      (mupdate 'edit-text 'details-name "name")
      (mupdate 'edit-text 'details-family "family")
      (mupdate 'edit-text 'details-photo-id "photo-id")
1006
      (mupdate 'image-view 'photo "photo")
Dave Griffiths's avatar
Dave Griffiths committed
1007 1008
      (mupdate-spinner-other 'tribe "tribe" tribes-list)
      (mupdate-spinner-other 'sub-tribe "subtribe" subtribe-list)
1009 1010
      (mupdate 'edit-text 'age "age")
      (mupdate-spinner 'gender "gender" '(male female))
Dave Griffiths's avatar
Dave Griffiths committed
1011
      (mupdate-spinner 'education "education" education-list)
Dave Griffiths's avatar
Dave Griffiths committed
1012
      ))
Dave Griffiths's avatar
Dave Griffiths committed
1013 1014 1015 1016
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
Dave Griffiths's avatar
Dave Griffiths committed
1017 1018 1019 1020 1021 1022 1023
   (lambda (activity requestcode resultcode)
     (msg "back from camera")
     (cond
      ((eqv? requestcode photo-code)
       ;; todo: means we save when the camera happens
       ;; need to do this before init is called again in on-start,
       ;; which happens next
1024
       (let ((unique-id (entity-get-value "unique_id")))
1025
         (entity-set-value! "photo" "file" (get-current 'photo-name "error no photo name!!"))
1026 1027 1028
         (entity-update-values!)
         ;; need to reset the individual from the db now (as update reset it)
         (entity-init! db "sync" "individual" (get-entity-by-unique db "sync" unique-id)))
Dave Griffiths's avatar
Dave Griffiths committed
1029 1030 1031 1032
       (list
        (mupdate 'image-view 'photo "photo")))
      (else
       '()))))
Dave Griffiths's avatar
Dave Griffiths committed
1033 1034 1035 1036

  (activity
   "family"
   (build-activity
1037 1038
    (horiz
     (vert
1039 1040 1041
      (mspinner 'head-of-house '(male female) (lambda (v) (entity-set-value! "head-of-house" "varchar" v) '()))
      (mspinner 'marital-status married-list (lambda (v) (entity-set-value! "marital-status" "varchar" v) '()))
      (medit-text 'times-married "numeric" (lambda (v) (entity-set-value! "times-married" "int" v) '())))
1042 1043 1044

     (build-person-selector 'spouse "id-spouse" (list) spouse-request-code)
     )
1045 1046 1047

    (mtitle 'children)
    (horiz
1048 1049
     (medit-text 'children-living "numeric" (lambda (v) (entity-set-value! "children-living" "int" v) '()))
     (medit-text 'children-dead "numeric" (lambda (v) (entity-set-value! "children-dead" "int" v) '())))
1050
    (horiz
1051 1052
     (medit-text 'children-together "numeric" (lambda (v) (entity-set-value! "children-together" "int" v) '()))
     (medit-text 'children-apart "numeric" (lambda (v) (entity-set-value! "children-apart" "int" v) '())))
1053
    (mspinner-other 'residence-after-marriage '(birthplace spouse-village) (lambda (v) '()))
1054 1055
    (medit-text 'num-siblings "numeric" (lambda (v) (entity-set-value! "num-siblings" "int" v) '()))
    (medit-text 'birth-order "numeric" (lambda (v) (entity-set-value! "birth-order" "int" v) '())))
Dave Griffiths's avatar
Dave Griffiths committed
1056
   (lambda (activity arg)
1057
     (set-current! 'activity-title "Individual family")
1058
      (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
1059
   (lambda (activity arg)
Dave Griffiths's avatar
Dave Griffiths committed
1060
     (append
1061
      (update-person-selector db "sync" 'spouse "id-spouse")
Dave Griffiths's avatar
Dave Griffiths committed
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
      (list
       (mupdate-spinner 'head-of-house "head-of-house" '(male female))
       (mupdate-spinner 'marital-status "marital-status" married-list)
       (mupdate 'edit-text 'times-married "times-married")
       ;;(mupdate 'id-spouse "id-spouse")
       (mupdate 'edit-text 'children-living "children-living")
       (mupdate 'edit-text 'children-dead "children-dead")
       (mupdate 'edit-text 'children-together "children-together")
       (mupdate 'edit-text 'children-apart "children-apart")
       (mupdate-spinner 'residence-after-marriage "residence-after-marriage" '(birthplace spouse-village))
       (mupdate 'edit-text 'num-siblings "num-siblings")
       (mupdate 'edit-text 'birth-order "birth-order"))))
Dave Griffiths's avatar
Dave Griffiths committed
1074 1075 1076 1077
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
1078 1079
   (lambda (activity requestcode resultcode)
     (person-selector-return requestcode "id-spouse" spouse-request-code)
1080 1081 1082 1083 1084

     ;; intercept a spouse setting and set the other individual
     ;; BIDIRECTIONAL AUTOSPOUSE
     (when (and (eqv? requestcode spouse-request-code)
                (get-current 'choose-result #f))
Dave Griffiths's avatar
Dave Griffiths committed
1085
           (update-entity db "sync" (entity-id-from-unique db "sync" (get-current 'choose-result #f))