@@ -121,7 +121,7 @@ UI.aclControl.ACLControlBox5 = function (subject, dom, noun, kb, callback) {
121121
122122 var kToColor = { 13 : 'purple' , 9 : 'blue' , 5 : 'red' , 3 : 'orange' , 2 : '#cc0' , 1 : 'green' }
123123
124- var ktToList = function ( k ) {
124+ function ktToList ( k ) {
125125 var list = ''
126126 var y = [ 'Read' , 'Append' , 'Write' , 'Control' ]
127127 for ( var i = 0 ; i < 4 ; i ++ ) {
@@ -145,8 +145,7 @@ UI.aclControl.ACLControlBox5 = function (subject, dom, noun, kb, callback) {
145145 }
146146 }
147147
148- //
149- var agentTriage = function ( uri ) {
148+ function agentTriage ( uri ) {
150149 var ns = UI . ns
151150 var obj = $rdf . sym ( uri )
152151 var types = kb . findTypeURIs ( obj )
@@ -208,7 +207,7 @@ UI.aclControl.ACLControlBox5 = function (subject, dom, noun, kb, callback) {
208207 } )
209208 }
210209
211- var renderCombo = function ( byCombo , combo ) {
210+ function renderCombo ( byCombo , combo ) {
212211 var row = box . appendChild ( dom . createElement ( 'tr' ) )
213212 row . combo = combo
214213 row . setAttribute ( 'style' , 'color: ' +
@@ -299,95 +298,47 @@ UI.aclControl.ACLControlBox5 = function (subject, dom, noun, kb, callback) {
299298 syncCombo ( combo )
300299 }
301300
302- if ( options . modify ) {
303- // see http://html5demos.com/drag-anything
304- row . addEventListener ( 'dragover' , function ( e ) {
305- e . preventDefault ( ) // Neeed else drop does not work [sic]
306- e . dataTransfer . dropEffect = 'copy'
307- // console.log('dragover event') // millions of them
308- } )
309-
310- row . addEventListener ( 'dragenter' , function ( e ) {
311- console . log ( 'dragenter event dropEffect: ' + e . dataTransfer . dropEffect )
312- this . style . backgroundColor = '#ccc'
313- e . dataTransfer . dropEffect = 'link'
314- console . log ( 'dragenter event dropEffect 2: ' + e . dataTransfer . dropEffect )
315- } )
316- row . addEventListener ( 'dragleave' , function ( e ) {
317- console . log ( 'dragleave event dropEffect: ' + e . dataTransfer . dropEffect )
318- this . style . backgroundColor = 'white'
319- } )
320-
321- row . addEventListener ( 'drop' , function ( e ) {
322- if ( e . preventDefault ) e . preventDefault ( ) // stops the browser from redirecting off to the text.
323- console . log ( 'Drop event. dropEffect: ' + e . dataTransfer . dropEffect )
324- console . log ( 'Drop event. types: ' + ( e . dataTransfer . types ? e . dataTransfer . types . join ( ', ' ) : 'NOPE' ) )
325-
326- var uris = null
327- var text
328- var thisEle = this
329- if ( e . dataTransfer . types ) {
330- for ( var t = 0 ; t < e . dataTransfer . types . length ; t ++ ) {
331- var type = e . dataTransfer . types [ t ]
332- if ( type === 'text/uri-list' ) {
333- uris = e . dataTransfer . getData ( type ) . split ( '\n' ) // @ ignore those starting with #
334- console . log ( 'Dropped text/uri-list: ' + uris )
335- } else if ( type === 'text/plain' ) {
336- text = e . dataTransfer . getData ( type )
337- }
338- }
339- if ( uris === null && text && text . slice ( 0 , 4 ) === 'http' ) {
340- uris = text
341- console . log ( "Waring: Poor man's drop: using text for URI" ) // chrome disables text/uri-list??
342- }
343- } else {
344- // ... however, if we're IE, we don't have the .types property, so we'll just get the Text value
345- uris = [ e . dataTransfer . getData ( 'Text' ) ]
346- console . log ( '@@ WARNING non-standrad drop event: ' + uris [ 0 ] )
301+ function handleDroppedURI ( u ) {
302+ var saveAndRestoreUI = function ( ) {
303+ if ( ! ( combo in byCombo ) ) {
304+ byCombo [ combo ] = [ ]
347305 }
348- console . log ( 'Dropped URI list (2): ' + uris )
349- if ( uris ) {
350- uris . map ( function ( u ) {
351- var saveAndRestoreUI = function ( ) {
352- if ( ! ( combo in byCombo ) ) {
353- byCombo [ combo ] = [ ]
354- }
355- removeAgentFromCombos ( u ) // Combos are mutually distinct
356- byCombo [ combo ] . push ( [ res . pred , res . obj . uri ] )
357- console . log ( 'ACL: setting access to ' + subject + ' by ' + res . pred + ': ' + res . obj )
358- box . saveBack ( function ( ok , error ) {
359- if ( ok ) {
360- thisEle . style . backgroundColor = 'white' // restore look to before drag
361- syncPanel ( )
362- } else {
363- alert ( error )
364- }
365- } )
366- }
306+ removeAgentFromCombos ( u ) // Combos are mutually distinct
307+ byCombo [ combo ] . push ( [ res . pred , res . obj . uri ] )
308+ console . log ( 'ACL: setting access to ' + subject + ' by ' + res . pred + ': ' + res . obj )
309+ box . saveBack ( function ( ok , error ) {
310+ if ( ok ) {
311+ row . style . backgroundColor = 'white' // restore look to before drag
312+ syncPanel ( )
313+ } else {
314+ alert ( error )
315+ }
316+ } )
317+ }
367318
368- var res = agentTriage ( u ) // eg 'agent', 'origin', agentClass'
319+ var res = agentTriage ( u ) // eg 'agent', 'origin', agentClass'
320+ if ( ! res ) {
321+ console . log ( ' looking up dropped thing ' + u )
322+ kb . fetcher . nowOrWhenFetched ( u , function ( ok , mess ) {
323+ if ( ! ok ) {
324+ console . log ( 'Error looking up dropped thing ' + u + ': ' + mess )
325+ } else {
326+ res = agentTriage ( u )
369327 if ( ! res ) {
370- console . log ( ' looking up dropped thing ' + u )
371- kb . fetcher . nowOrWhenFetched ( u , function ( ok , mess ) {
372- if ( ! ok ) {
373- console . log ( 'Error looking up dropped thing ' + u + ': ' + mess )
374- } else {
375- res = agentTriage ( u )
376- if ( ! res ) {
377- console . log ( 'Error: Drop fails to drop appropriate thing! ' + u )
378- } else {
379- saveAndRestoreUI ( )
380- }
381- }
382- } )
328+ console . log ( 'Error: Drop fails to drop appropriate thing! ' + u )
383329 } else {
384330 saveAndRestoreUI ( )
385331 }
386- } )
387- }
388- return false
389- } )
390- } // if modify
332+ }
333+ } )
334+ } else {
335+ saveAndRestoreUI ( )
336+ }
337+ } // handleDroppedURI
338+
339+ if ( options . modify ) {
340+ UI . widgets . makeDropTarget ( row , handleDroppedURI )
341+ }
391342 }
392343 var syncPanel = function ( ) {
393344 var kids = box . children
0 commit comments