starwisp.scm 47.9 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
(db-open db)
(setup db "local")
(setup db "sync")
(setup db "stream")

(insert-entity-if-not-exists
37
 db "local" "app-settings" "null" 1
Dave Griffiths's avatar
Dave Griffiths committed
38
 (list
39 40 41 42
  (ktv "user-id" "varchar" "No name yet...")
  (ktv "language" "int" 0)
  (ktv "house-count" "int" 0)
  (ktv "photo-id-count" "int" 0)))
Dave Griffiths's avatar
Dave Griffiths committed
43

Dave Griffiths's avatar
Dave Griffiths committed
44
(define (get-setting-value name)
45
  (ktv-get (get-entity db "local" 1) name))
Dave Griffiths's avatar
Dave Griffiths committed
46 47 48

(define (set-setting! key type value)
  (update-entity
49
   db "local" 1 (list (ktv key type value))))
Dave Griffiths's avatar
Dave Griffiths committed
50 51 52 53 54 55 56 57

(define (get/inc-setting key)
  (let ((r (get-setting-value key)))
    (set-setting! key "int" (+ r 1))
    r))

(set! i18n-lang (get-setting-value "language"))

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

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

Dave Griffiths's avatar
Dave Griffiths committed
62 63 64 65
(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))
66 67 68 69
(define residence-list '(birthplace spouse-village))
(define gender-list '(male female))
(define occupation-list '(agriculture gathering labour cows fishing other))
(define house-type-list '(concrete tin thatched))
Dave Griffiths's avatar
Dave Griffiths committed
70

Dave Griffiths's avatar
Dave Griffiths committed
71
(define social-types-list '(friendship knowledge prestige))
Dave Griffiths's avatar
Dave Griffiths committed
72 73 74 75
(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
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
(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)))

92 93 94 95 96 97 98 99 100 101
(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)
102
   (ktv-create "gender" "varchar" "none")
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
   (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
134

135 136 137 138 139 140 141 142
(define crop-ktvlist
  (list
   (ktv-create "name" "varchar" (mtext-lookup 'default-crop-name))
   (ktv-create "unit" "varchar" "unit")
   (ktv-create "used" "real" 0)
   (ktv-create "sold" "real" 0)
   (ktv-create "seed" "varchar" "none")))

143 144 145 146 147 148 149 150 151
(define child-ktvlist
  (list
   (ktv-create "name" "varchar" (mtext-lookup 'default-child-name))
   (ktv-create "alive" "int" 1)
   (ktv-create "gender" "varchar" "none")
   (ktv-create "age" "int" 0)
   (ktv-create "living-at-home" "int" 0)))


Dave Griffiths's avatar
Dave Griffiths committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;

(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
170
        (msg "connected, going in...")
Dave Griffiths's avatar
Dave Griffiths committed
171 172 173
        (append
         (list (toast "sync-cb"))
         (upload-dirty db)
Dave Griffiths's avatar
Dave Griffiths committed
174
         (if (have-dirty? db "sync") '() (suck-new db "sync"))))))
Dave Griffiths's avatar
Dave Griffiths committed
175 176
    (else '()))
   (list
Dave Griffiths's avatar
Dave Griffiths committed
177
    (delayed "debug-timer" (+ 30000 (random 5000)) debug-timer-cb)
Dave Griffiths's avatar
Dave Griffiths committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
    (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
229 230
   "top"
   (horiz
Dave Griffiths's avatar
Dave Griffiths committed
231
    (image-view 0 "face" (layout 48 64 -1 'centre 0))
232
    (text-view (make-id "title") "" 30
233 234 235 236
               (layout 'fill-parent 'fill-parent 0.25 'centre 10))

    (linear-layout
     0 'vertical
Dave Griffiths's avatar
Dave Griffiths committed
237
     (layout 'fill-parent 'wrap-content 0.75 'centre 0)
238 239 240 241
     (list 0 0 0 0)

     (list
      (text-view (make-id "") 'name 20
Dave Griffiths's avatar
Dave Griffiths committed
242
                 (layout 'fill-parent 'wrap-content 1 'centre 0))
243
      (text-view (make-id "") 'photo-id 20
Dave Griffiths's avatar
Dave Griffiths committed
244
                 (layout 'fill-parent 'wrap-content 1 'centre 0)))))
Dave Griffiths's avatar
Dave Griffiths committed
245 246 247
   (lambda (fragment arg)
     (activity-layout fragment))
   (lambda (fragment arg)
248 249 250
     (list
      (update-widget 'text-view (get-id "title") 'text
                     (get-current 'activity-title "Title not set"))))
Dave Griffiths's avatar
Dave Griffiths committed
251 252 253 254 255 256
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '())
   (lambda (fragment) '()))


257 258 259 260
  (fragment
   "bottom"
   (linear-layout
    0 'horizontal
Dave Griffiths's avatar
Dave Griffiths committed
261
    (layout 'fill-parent 'fill-parent 1 'centre 0)
262 263
    (list 0 0 0 0)
    (list
264
     (mbutton-scale
265
      'save
266 267 268 269
      (lambda ()
        (list
         (alert-dialog
          "ok-check"
270
          (mtext-lookup 'save-are-you-sure)
271 272 273 274
          (lambda (v)
            (cond
             ((eqv? v 1)
              (entity-update-values!)
275
              (list))
276 277
             (else
              (list))))))))
278
     (mbutton-scale 'back (lambda () (list (finish-activity 1))))))
279 280 281 282 283 284 285 286
   (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
287 288 289 290 291 292


  )

(msg "one")

Dave Griffiths's avatar
Dave Griffiths committed
293 294 295 296
(define (build-activity . contents)
  (vert-fill
   (relative
    '(("parent-top"))
297
    colour-one ;;(list 100 100 255 127)
Dave Griffiths's avatar
Dave Griffiths committed
298 299 300 301 302 303 304 305 306
    (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"))
307
    colour-one
Dave Griffiths's avatar
Dave Griffiths committed
308 309 310 311
    (vert
     (spacer 5)
     (build-fragment "bottom" (make-id "bottom") fillwrap)))))

312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344

(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)))))

345

346
(define (update-individual-filter)
Dave Griffiths's avatar
Dave Griffiths committed
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
  (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)
362 363
             (button
              (make-id (string-append "chooser-" id))
Dave Griffiths's avatar
Dave Griffiths committed
364
              (ktv-get e "name") 30 (layout (car button-size) (/ (cadr button-size) 3) 1 'centre 5)
365 366
              (lambda ()
                (set-current! 'choose-result id)
Dave Griffiths's avatar
Dave Griffiths committed
367 368 369 370
                (list (finish-activity 0)))))

            ((equal? image "face")
             (button
371
              (make-id (string-append "chooser-" id))
Dave Griffiths's avatar
Dave Griffiths committed
372
              (ktv-get e "name") 30 (layout (car button-size) (cadr button-size) 1 'centre 5)
373 374
              (lambda ()
                (set-current! 'choose-result id)
Dave Griffiths's avatar
Dave Griffiths committed
375
                (list (finish-activity 0)))))
376

Dave Griffiths's avatar
Dave Griffiths committed
377 378 379 380 381 382 383 384 385 386 387 388 389 390
            (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)
391
  (let ((e (get-entity-by-unique db table unique-id)))
Dave Griffiths's avatar
Dave Griffiths committed
392 393 394
    (list
     (ktv-get e "name")
     (ktv-get e "photo"))))
395 396 397 398 399 400

(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
401
   (mtext-small (string->symbol (string-append (symbol->string id) "-text")))
402 403 404 405 406 407 408 409
   (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
410 411 412 413 414
(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
415
   (mtext-small (string->symbol (string-append (symbol->string id) "-text")))
Dave Griffiths's avatar
Dave Griffiths committed
416 417 418 419 420 421 422 423 424
   (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 ""))))))


425 426 427 428
;; 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)
429
        (entity-set-value! key "varchar" (get-current 'choose-result "not set"))))
430 431 432 433 434 435

;; 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
436 437 438 439 440 441 442 443 444 445 446 447
    (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))))))))
448

Dave Griffiths's avatar
Dave Griffiths committed
449 450 451 452 453 454 455 456 457
(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)
458 459 460
        (entity-set-value! (string-append key "-relationship") "varchar"
                           (spinner-choice social-relationship-list v))
        '()))
Dave Griffiths's avatar
Dave Griffiths committed
461 462 463 464 465
     (mspinner-other-vert
      (string->symbol (string-append id-text "-residence"))
      'social-residence
      social-residence-list
      (lambda (v)
466 467
        (entity-set-value! (string-append key "-residence") "varchar"
                           (spinner-choice social-residence-list v)) '()))
Dave Griffiths's avatar
Dave Griffiths committed
468 469 470 471
     (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
472
       (make-id (dbg (string-append id-text "-strength-spinner")))
473
       (map mtext-lookup social-strength-list)
Dave Griffiths's avatar
Dave Griffiths committed
474 475
       (layout 'wrap-content 'wrap-content 1 'centre 0)
       (lambda (v)
476 477
         (entity-set-value! (string-append key "-strength") "varchar"
                            (spinner-choice social-strength-list v)) '()))))))
Dave Griffiths's avatar
Dave Griffiths committed
478 479 480 481 482 483 484

(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
485
    (append
486
     (update-person-selector db table id key)
Dave Griffiths's avatar
Dave Griffiths committed
487 488 489 490 491 492 493 494 495 496 497 498 499
     (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
500 501
     )))

Dave Griffiths's avatar
Dave Griffiths committed
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
(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
520 521
      (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
522 523 524 525 526 527 528 529 530 531 532 533 534 535

(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
536 537 538
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; activities

539
(define photo-code 999)
540
(define choose-code 998)
541 542 543
(define spouse-request-code 997)
(define mother-request-code 996)
(define father-request-code 995)
Dave Griffiths's avatar
Dave Griffiths committed
544

Dave Griffiths's avatar
Dave Griffiths committed
545 546 547 548 549 550
(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
551 552 553 554
(define-activity-list

  (activity
   "main"
555 556 557 558
   (build-activity
    (mtitle 'title)
    (horiz
     (medit-text 'user-id "normal" (lambda () (list)))
559
     (mbutton-scale 'sync (lambda () (list (start-activity "sync" 0 "")))))
560

561
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
562 563
     (mspinner 'languages (list 'english 'khasi 'hindi)
               (lambda (c)
564 565
                 (set-setting! "language" "int" c)
                 (set! i18n-lang c)
Dave Griffiths's avatar
Dave Griffiths committed
566
                 (list)))
567
     (mbutton-scale 'find-individual (lambda () (list (start-activity "individual-chooser" choose-code "")))))
568
    (build-list-widget
Dave Griffiths's avatar
Dave Griffiths committed
569
     db "sync" 'villages "village" "village" (lambda () #f)
Dave Griffiths's avatar
Dave Griffiths committed
570
     village-ktvlist))
571

572
   (lambda (activity arg)
573
     (set-current! 'activity-title "Main screen")
574 575
     (activity-layout activity))
   (lambda (activity arg)
Dave Griffiths's avatar
Dave Griffiths committed
576
     (list
Dave Griffiths's avatar
Dave Griffiths committed
577 578
      (update-widget 'spinner (get-id "languages-spinner") 'selection
                     (get-setting-value "language"))
Dave Griffiths's avatar
Dave Griffiths committed
579 580 581 582 583 584
      (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)))
585 586 587 588
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
589 590
   (lambda (activity requestcode resultcode)
     (cond
591 592
      ((eqv? requestcode choose-code)
       (list (start-activity "individual" 0 (get-current 'choose-result 0))))
593 594 595 596 597 598 599
      ((eqv? requestcode photo-code)
       (msg "camera returned" resultcode)
       (list (update-widget
              'image-view (get-id "image")
              'external-image (string-append dirname "photo.jpg"))))
      (else
       '()))))
600 601 602 603


  (activity
   "village"
Dave Griffiths's avatar
Dave Griffiths committed
604 605
     (build-activity
      (horiz
606 607
       (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
608
      (horiz
609 610
       (medit-text 'district "normal" (lambda (v) (entity-set-value! "district" "varchar" v) '()))
       (mtoggle-button-scale 'car (lambda (v) (entity-set-value! "car" "int" v) '())))
611

Dave Griffiths's avatar
Dave Griffiths committed
612 613 614 615
      (mbutton 'household-list
               (lambda ()
                 (list (start-activity "household-list" 0
                                       (get-current 'village #f)))))
616

Dave Griffiths's avatar
Dave Griffiths committed
617
      (mtitle 'amenities)
Dave Griffiths's avatar
Dave Griffiths committed
618 619 620 621 622 623 624 625 626 627
      (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
628
   (lambda (activity arg)
629
     (set-current! 'activity-title "Village")
Dave Griffiths's avatar
Dave Griffiths committed
630 631
     (activity-layout activity))
   (lambda (activity arg)
632
     (entity-init! db "sync" "village" (get-entity-by-unique db "sync" arg))
633
     (set-current! 'village arg)
Dave Griffiths's avatar
Dave Griffiths committed
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
     (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
650 651 652 653
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
Dave Griffiths's avatar
Dave Griffiths committed
654
   (lambda (activity requestcode resultcode) '()))
Dave Griffiths's avatar
Dave Griffiths committed
655

Dave Griffiths's avatar
Dave Griffiths committed
656 657 658 659

  (activity
   "household-list"
   (build-activity
660
    (build-list-widget
Dave Griffiths's avatar
Dave Griffiths committed
661
     db "sync" 'households "household" "household" (lambda () (get-current 'village #f))
Dave Griffiths's avatar
Dave Griffiths committed
662
     household-ktvlist))
Dave Griffiths's avatar
Dave Griffiths committed
663
   (lambda (activity arg)
664
     (set-current! 'activity-title "Household List")
Dave Griffiths's avatar
Dave Griffiths committed
665
     (activity-layout activity))
666
   (lambda (activity arg)
Dave Griffiths's avatar
Dave Griffiths committed
667
     (msg "rebuilding household list with" arg)
Dave Griffiths's avatar
Dave Griffiths committed
668 669
     (list (update-list-widget
            db "sync" "household" "household" arg)))
Dave Griffiths's avatar
Dave Griffiths committed
670 671 672 673 674 675 676 677 678
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
   "household"
   (build-activity
679
    (horiz
680 681
     (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) '())))
682 683
    (horiz
     (vert
Dave Griffiths's avatar
Dave Griffiths committed
684 685 686 687
      (mtext 'location)
      (mbutton 'house-gps (lambda () (do-gps 'house "house")))
      (mtext-small 'house-lat)
      (mtext-small 'house-lon))
688
     (vert
Dave Griffiths's avatar
Dave Griffiths committed
689 690 691 692 693
      (mtext 'toilet-location)
      (mbutton 'toilet-gps (lambda () (do-gps 'toilet "toilet")))
      (mtext-small 'toilet-lat)
      (mtext-small 'toilet-lon)))

694 695

    (build-list-widget
Dave Griffiths's avatar
Dave Griffiths committed
696 697
     db "sync" 'individuals "individual" "individual"
     (lambda () (get-current 'household #f))
698
     individual-ktvlist)
Dave Griffiths's avatar
Dave Griffiths committed
699

Dave Griffiths's avatar
Dave Griffiths committed
700
    (delete-button))
Dave Griffiths's avatar
Dave Griffiths committed
701
   (lambda (activity arg)
702
     (set-current! 'activity-title "Household")
Dave Griffiths's avatar
Dave Griffiths committed
703
     (activity-layout activity))
704 705 706
   (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
707 708 709 710 711 712 713
     (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")))
714

Dave Griffiths's avatar
Dave Griffiths committed
715 716 717 718 719 720 721 722 723
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
   "individual"
   (build-activity
724 725 726
    (horiz
     (image-view (make-id "photo") "face" (layout 240 320 -1 'centre 10))
     (vert
Dave Griffiths's avatar
Dave Griffiths committed
727
      (mtext 'name-display)
728
      (spacer 20)
Dave Griffiths's avatar
Dave Griffiths committed
729
      (mtext 'family-display)
730
      (spacer 20)
731 732
      (mtext 'photo-id-display)
      ))
733
    (mbutton 'agreement-button (lambda () (list (start-activity "agreement" 0 ""))))
734
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
735 736
     (mbutton-scale 'details-button (lambda () (list (start-activity "details" 0 ""))))
     (mbutton-scale 'family-button (lambda () (list (start-activity "family" 0 "")))))
737
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
738 739
     (mbutton-scale 'migration-button (lambda () (list (start-activity "migration" 0 ""))))
     (mbutton-scale 'income-button (lambda () (list (start-activity "income" 0 "")))))
740
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
741 742
     (mbutton-scale 'geneaology-button (lambda () (list (start-activity "geneaology" 0 ""))))
     (mbutton-scale 'social-button (lambda () (list (start-activity "social" 0 "")))))
743
    (mbutton-scale 'move-button (lambda () (list (start-activity "move" 0 ""))))
744
    (spacer 20)
Dave Griffiths's avatar
Dave Griffiths committed
745
    (delete-button))
746

Dave Griffiths's avatar
Dave Griffiths committed
747
   (lambda (activity arg)
748
     (set-current! 'activity-title "Individual")
Dave Griffiths's avatar
Dave Griffiths committed
749
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
750 751 752 753
   (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
754 755 756
      (mupdate 'text-view 'name-display "name")
      (mupdate 'text-view 'family-display "family")
      (mupdate 'text-view 'photo-id-display "photo-id")
757
      (mupdate 'image-view 'photo "photo")))
Dave Griffiths's avatar
Dave Griffiths committed
758 759 760 761 762 763 764 765 766
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
   "details"
   (build-activity
767
    (horiz
Dave Griffiths's avatar
Dave Griffiths committed
768

769
     (vert
Dave Griffiths's avatar
Dave Griffiths committed
770
      (image-view (make-id "photo") "face" (layout 240 320 -1 'centre 10))
771 772 773
      (mbutton
       'change-photo
       (lambda ()
774 775
         (set-current!
          'photo-name (string-append (entity-get-value "unique_id") "-" (get-unique "p") "-face.jpg"))
Dave Griffiths's avatar
Dave Griffiths committed
776
         (list
777
          (take-photo (string-append dirname "files/" (get-current 'photo-name "")) photo-code))
Dave Griffiths's avatar
Dave Griffiths committed
778 779
         )))

780
     (vert
781 782 783
      (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) '()))))
784 785
    (mspinner-other 'tribe tribes-list (lambda (v) (msg "tribe now:" v) (entity-set-value! "tribe" "varchar" (spinner-choice tribes-list v)) '()))
    (mspinner-other 'sub-tribe subtribe-list (lambda (v) (entity-set-value! "subtribe" "varchar" (spinner-choice subtribe-list v)) '()))
786
    (horiz
787
     (medit-text 'age "numeric" (lambda (v) (entity-set-value! "age" "int" v) '()))
788
     (mspinner 'gender gender-list (lambda (v) (entity-set-value! "gender" "varchar" (spinner-choice gender-list v)) '()))
789
     (mspinner 'education education-list (lambda (v) (entity-set-value! "education" "varchar" v) '())))
Dave Griffiths's avatar
Dave Griffiths committed
790 791
    )
   (lambda (activity arg)
792
     (set-current! 'activity-title "Individual details")
Dave Griffiths's avatar
Dave Griffiths committed
793
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
794 795 796 797 798
   (lambda (activity arg)
     (list
      (mupdate 'edit-text 'details-name "name")
      (mupdate 'edit-text 'details-family "family")
      (mupdate 'edit-text 'details-photo-id "photo-id")
799
      (mupdate 'image-view 'photo "photo")
Dave Griffiths's avatar
Dave Griffiths committed
800 801
      (mupdate-spinner-other 'tribe "tribe" tribes-list)
      (mupdate-spinner-other 'sub-tribe "subtribe" subtribe-list)
802
      (mupdate 'edit-text 'age "age")
803
      (mupdate-spinner 'gender "gender" gender-list)
Dave Griffiths's avatar
Dave Griffiths committed
804
      (mupdate-spinner 'education "education" education-list)
Dave Griffiths's avatar
Dave Griffiths committed
805
      ))
Dave Griffiths's avatar
Dave Griffiths committed
806 807 808 809
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
Dave Griffiths's avatar
Dave Griffiths committed
810 811 812 813 814 815 816
   (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
817
       (let ((unique-id (entity-get-value "unique_id")))
818
         (entity-set-value! "photo" "file" (get-current 'photo-name "error no photo name!!"))
819 820 821
         (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
822 823 824 825
       (list
        (mupdate 'image-view 'photo "photo")))
      (else
       '()))))
Dave Griffiths's avatar
Dave Griffiths committed
826 827 828 829

  (activity
   "family"
   (build-activity
830 831
    (horiz
     (vert
832 833
      (mspinner 'head-of-house gender-list (lambda (v) (entity-set-value! "head-of-house" "varchar" (spinner-choice gender-list v)) '()))
      (mspinner 'marital-status married-list (lambda (v) (entity-set-value! "marital-status" "varchar" (spinner-choice married-list v)) '()))
834
      (medit-text 'times-married "numeric" (lambda (v) (entity-set-value! "times-married" "int" v) '())))
835 836 837

     (build-person-selector 'spouse "id-spouse" (list) spouse-request-code)
     )
838

839 840 841 842 843 844 845 846 847 848 849
;;    (mtitle 'children)
;;    (horiz
;;     (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) '())))
;;    (horiz
;;     (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) '())))

    (mspinner-other 'residence-after-marriage residence-list (lambda (v) (entity-set-value!
                                                                          "residence-after-marriage" "varchar"
                                                                          (spinner-choice residence-list v)) '()))
850 851
    (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
852
   (lambda (activity arg)
853
     (set-current! 'activity-title "Individual family")
854
      (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
855
   (lambda (activity arg)
Dave Griffiths's avatar
Dave Griffiths committed
856
     (append
857
      (update-person-selector db "sync" 'spouse "id-spouse")
Dave Griffiths's avatar
Dave Griffiths committed
858
      (list
859
       (mupdate-spinner 'head-of-house "head-of-house" gender-list)
Dave Griffiths's avatar
Dave Griffiths committed
860 861 862
       (mupdate-spinner 'marital-status "marital-status" married-list)
       (mupdate 'edit-text 'times-married "times-married")
       ;;(mupdate 'id-spouse "id-spouse")
863 864 865 866 867
;;       (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" residence-list)
Dave Griffiths's avatar
Dave Griffiths committed
868 869
       (mupdate 'edit-text 'num-siblings "num-siblings")
       (mupdate 'edit-text 'birth-order "birth-order"))))
Dave Griffiths's avatar
Dave Griffiths committed
870 871 872 873
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
874 875
   (lambda (activity requestcode resultcode)
     (person-selector-return requestcode "id-spouse" spouse-request-code)
876 877 878 879 880

     ;; 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
881
           (update-entity db "sync" (entity-id-from-unique db "sync" (get-current 'choose-result #f))
882 883 884 885 886 887 888 889 890
                          (list (ktv "id-spouse" "varchar" (entity-get-value "unique_id"))))
           (msg "done..."))

     ;; save and reinit otherwise we can get out of sync here with the spouse :/
     (let ((unique-id (entity-get-value "unique_id")))
       (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)))

891
     '()))
Dave Griffiths's avatar
Dave Griffiths committed
892

893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919
  (activity
   "move"
   (build-activity
    (mspinner 'move-household '()
              (lambda (v)
                (msg v)
                (msg (number? v))
                (msg (list-ref (get-current 'move-household-list '()) v))
                (entity-set-value!
                 "parent" "varchar"
                 (cadr (list-ref (get-current 'move-household-list '()) v)))
                '())))
   (lambda (activity arg)
     (set-current! 'activity-title "Move individual")
     (activity-layout activity))
   (lambda (activity arg)
     (set-current! 'move-household-list (build-array-from-names db "sync" "household"))
     (list
      (update-widget 'spinner (get-id "move-household-spinner") 'array
                     (map car (get-current 'move-household-list '())))))
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))


Dave Griffiths's avatar
Dave Griffiths committed
920 921 922 923

  (activity
   "migration"
   (build-activity
924 925 926 927 928
    (medit-text 'length-time "numeric" (lambda (v) (entity-set-value! "length-time" "int" v) '()))
    (medit-text 'place-of-birth "normal" (lambda (v) (entity-set-value! "place-of-birth" "varchar" v) '()))
    (medit-text 'num-residence-changes "numeric" (lambda (v) (entity-set-value! "num-residence-changes" "int" v) '()))
    (medit-text 'village-visits-month "numeric" (lambda (v) (entity-set-value! "village-visits-month" "int" v) '()))
    (medit-text 'village-visits-year "numeric" (lambda (v) (entity-set-value! "village-visits-year" "int" v) '()))
Dave Griffiths's avatar
Dave Griffiths committed
929 930
    )
   (lambda (activity arg)
931
     (set-current! 'activity-title "Individual migration")
Dave Griffiths's avatar
Dave Griffiths committed
932
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
933 934 935 936 937 938 939
   (lambda (activity arg)
     (list
      (mupdate 'edit-text 'length-time "length-time")
      (mupdate 'edit-text 'place-of-birth "place-of-birth")
      (mupdate 'edit-text 'num-residence-changes "num-residence-changes")
      (mupdate 'edit-text 'village-visits-month "village-visits-month")
      (mupdate 'edit-text 'village-visits-year "village-visits-year")))
Dave Griffiths's avatar
Dave Griffiths committed
940 941 942 943 944 945 946 947 948
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

  (activity
   "income"
   (build-activity
949 950 951 952
    (mspinner 'occupation occupation-list
              (lambda (v) (entity-set-value! "occupation" "varchar"
                                             (spinner-choice occupation-list v))
                      '()))
953
    (horiz
954 955
     (mtoggle-button-scale 'contribute (lambda (v) (entity-set-value! "contribute" "int" v) '()))
     (mtoggle-button-scale 'own-land (lambda (v) (entity-set-value! "own-land" "int" v) '())))
956
    (horiz
957 958
     (mtoggle-button-scale 'rent-land (lambda (v) (entity-set-value! "rent-land" "int" v) '()))
     (mtoggle-button-scale 'hire-land (lambda (v) (entity-set-value! "hire-land" "int" v) '())))
959 960 961
    (build-list-widget
     db "sync" 'crops "crop" "crop" (lambda () (get-current 'individual #f))
     crop-ktvlist)
962 963
    (mspinner-other 'house-type house-type-list (lambda (v) (entity-set-value! "house-type" "varchar"
                                                                               (spinner-choice house-type-list v)) '()))
964
    (horiz
965 966
     (medit-text 'loan "numeric" (lambda (v) (entity-set-value! "loan" "int" v) '()))
     (medit-text 'earning "numeric" (lambda (v) (entity-set-value! "earning" "int" v) '())))
967 968
    (mtext 'in-the-home)
    (horiz
969 970 971
     (mtoggle-button-scale 'radio (lambda (v) (entity-set-value! "radio" "int" v) '()))
     (mtoggle-button-scale 'tv (lambda (v) (entity-set-value! "tv" "int" v) '()))
     (mtoggle-button-scale 'mobile (lambda (v) (entity-set-value! "mobile" "int" v) '())))
972
    (horiz
973 974
     (medit-text 'visit-market "numeric" (lambda (v) (entity-set-value! "visit-market" "int" v) '()))
     (medit-text 'town-sell "numeric" (lambda (v) (entity-set-value! "town-sell" "int" v) '())))
Dave Griffiths's avatar
Dave Griffiths committed
975 976
    )
   (lambda (activity arg)
977
     (set-current! 'activity-title "Individual income")
Dave Griffiths's avatar
Dave Griffiths committed
978
     (activity-layout activity))
Dave Griffiths's avatar
Dave Griffiths committed
979 980
   (lambda (activity arg)
     (list
981
      (update-list-widget db "sync" "crop" "crop" (get-current 'individual #f))
982
      (mupdate-spinner 'occupation "occupation" occupation-list)
Dave Griffiths's avatar
Dave Griffiths committed
983 984 985 986
      (mupdate 'toggle-button 'contribute "contribute")
      (mupdate 'toggle-button 'own-land "own-land")
      (mupdate 'toggle-button 'rent-land "rent-land")
      (mupdate 'toggle-button 'hire-land "hire-land")
987
      (mupdate-spinner-other 'house-type "house-type" house-type-list)
Dave Griffiths's avatar
Dave Griffiths committed
988 989 990 991 992 993 994
      (mupdate 'edit-text 'loan "loan")
      (mupdate 'edit-text 'earning "earning")
      (mupdate 'toggle-button 'radio "radio")
      (mupdate 'toggle-button 'tv "tv")
      (mupdate 'toggle-button 'mobile "mobile")
      (mupdate 'edit-text 'visit-market "visit-market")
      (mupdate 'edit-text 'town-sell "town-sell")))
Dave Griffiths's avatar
Dave Griffiths committed
995 996 997 998 999 1000
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
  (activity
   "crop"
   (build-activity
    (vert
     (medit-text 'crop-name "normal" (lambda (v) (entity-set-value! "name" "varchar" v) '()))
     (medit-text 'crop-unit "normal" (lambda (v) (entity-set-value! "unit" "varchar" v) '()))
     (medit-text 'crop-used "numeric" (lambda (v) (entity-set-value! "used" "real" (string->number v)) '()))
     (medit-text 'crop-sold "numeric" (lambda (v) (entity-set-value! "sold" "real" (string->number v)) '()))
     (medit-text 'crop-seed "numeric" (lambda (v) (entity-set-value! "seed" "varchar" v) '()))
     (delete-button)))
   (lambda (activity arg)
     (set-current! 'activity-title "Crop")
     (activity-layout activity))
   (lambda (activity arg)
     (entity-init! db "sync" "crop" (get-entity-by-unique db "sync" arg))
     (set-current! 'crop arg)
     (list
      (mupdate 'edit-text 'crop-name "name")
      (mupdate 'edit-text 'crop-unit "unit")
      (mupdate 'edit-text 'crop-used "used")
      (mupdate 'edit-text 'crop-sold "sold")
      (mupdate 'edit-text 'crop-seed "seed")
      ))

   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
  (activity
   "child"
   (build-activity
    (vert
     (medit-text 'child-name "normal" (lambda (v) (entity-set-value! "name" "varchar" v) '()))
     (horiz
      (mspinner 'child-gender gender-list (lambda (v) (entity-set-value! "gender" "varchar" (spinner-choice gender-list v)) '()))
      (medit-text 'child-age "numeric" (lambda (v) (entity-set-value! "age" "int" (string->number v)) '())))
     (horiz
      (mtoggle-button-scale 'child-alive (lambda (v) (entity-set-value! "alive" "int" v) '()))
      (mtoggle-button-scale 'child-home (lambda (v) (entity-set-value! "living-at-home" "int" v) '())))
     (delete-button)))
   (lambda (activity arg)
     (set-current! 'activity-title "Child")
     (activity-layout activity))
   (lambda (activity arg)
     (entity-init! db "sync" "child" (get-entity-by-unique db "sync" arg))
     (set-current! 'child arg)
     (list
      (mupdate 'edit-text 'child-name "name")
      (mupdate-spinner 'child-gender "gender" gender-list)
      (mupdate 'edit-text 'child-age "age")
      (mupdate 'toggle-button 'child-alive "alive")
      (mupdate 'toggle-button 'child-home "living-at-home")
      ))

   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity) '())
   (lambda (activity requestcode resultcode) '()))

1063

Dave Griffiths's avatar
Dave Griffiths committed
1064 1065 1066
  (activity
   "geneaology"
   (build-activity
1067
    (horiz
1068 1069
     (build-person-selector 'mother "id-mother" (list) mother-request-code)
     (build-person-selector 'father "id-father" (list) father-request-code))
1070 1071 1072 1073 1074

    (build-list-widget
     db "sync" 'children "child" "child" (lambda () (get-current 'individual #f))
     child-ktvlist))

Dave Griffiths's avatar
Dave Griffiths committed