@@ -33,10 +33,10 @@ var UI = {
3333/** A control to capture a picture using camera
3434 * @param {Docuemnt } dom - The Document object
3535 * @param {IndexedForumla } store - The quadstore to store data in
36- * @param {NamedNode } destination - NN of the image file to be created
36+ * @param {NamedNode } getImageDoc() - NN of the image file to be created
3737 * @param {function } doneCallback - Called when a picture has been taken
3838 */
39- function cameraCaptureControl ( dom , store , destination , doneCallback ) {
39+ function cameraCaptureControl ( dom , store , getImageDoc , doneCallback ) {
4040 const div = dom . createElement ( 'div' )
4141 const player = div . appendChild ( dom . createElement ( 'video' ) )
4242 const controlStyle = 'border-radius: 0.5em; margin: 0.8em; width: 320; height:240;'
@@ -70,8 +70,9 @@ function cameraCaptureControl (dom, store, destination, doneCallback) {
7070 canvas . toBlob ( blob => {
7171 let msg = `got blob type ${ blob . type } size ${ blob . size } `
7272 console . log ( msg )
73+ let destination = getImageDoc ( )
7374 saveBlob ( blob , destination )
74- alert ( msg )
75+ // alert(msg)
7576 } , contentType ) // toBlob
7677 }
7778
@@ -81,6 +82,7 @@ function cameraCaptureControl (dom, store, destination, doneCallback) {
8182 console . log ( 'Putting ' + blob . size + ' bytes of ' + contentType + ' to ' + destination )
8283 store . fetcher . webOperation ( 'PUT' , destination . uri , { data : blob , contentType : contentType } ) . then ( resp => {
8384 console . log ( 'ok saved ' + destination )
85+ doneCallback ( destination )
8486 alert ( 'saved ok: ' + destination )
8587 } , err => {
8688 alert ( err )
@@ -100,23 +102,25 @@ function cameraCaptureControl (dom, store, destination, doneCallback) {
100102/** A button to capture a picture using camera
101103 * @param {Docuemnt } dom - The Document object
102104 * @param {IndexedForumla } store - The quadstore to store data in
103- * @param {NamedNode } destination - NN of the image file to be created
105+ * @param {fuunction } getImageDoc - returns NN of the image file to be created
106+ * @param {function<Node> } doneCallback - called with the image taken
104107 * @returns {DomElement } - A div element with the buton in it
105108 *
106109 * This expacts the buttton to a large control when it is pressed
107110 */
108- function cameraButton ( dom , store , destination ) {
111+ function cameraButton ( dom , store , getImageDoc , doneCallback ) {
109112 const div = dom . createElement ( 'div' )
110113 const but = UI . widgets . button ( dom , UI . icons . iconBase + 'noun_383448.svg' , 'Take picture' )
111114 var control
112- function restoreButton ( ) {
115+ function restoreButton ( imageDoc ) {
113116 div . removeChild ( control )
114117 div . appendChild ( but )
118+ doneCallback ( imageDoc )
115119 }
116120 div . appendChild ( but )
117121 but . addEventListener ( 'click' , event => {
118122 div . removeChild ( but )
119- control = control || cameraCaptureControl ( dom , store , destination , restoreButton )
123+ control = control || cameraCaptureControl ( dom , store , getImageDoc , restoreButton )
120124 div . appendChild ( control )
121125 } )
122126 return div
0 commit comments