@@ -17,24 +17,24 @@ interface FormElements {
1717 // These typings were created post-hoc, so I'm not sure if that was intentional.
1818 // Thus, this union type should be considered as descriptive rather than prescriptive.
1919 origin : ( undefined | NamedNode | HTMLInputElement ) ;
20- } ;
20+ }
2121
2222export function renderTrustedApplicationsOptions ( dom : HTMLDocument ) {
23- var div = dom . createElement ( 'div' )
23+ const div = dom . createElement ( 'div' )
2424 div . classList . add ( 'trusted-applications-pane' )
2525 div . setAttribute ( 'style' , 'border: 0.3em solid ' + thisColor + '; border-radius: 0.5em; padding: 0.7em; margin-top:0.7em;' )
26- var table = div . appendChild ( dom . createElement ( 'table' ) )
27- var main = table . appendChild ( dom . createElement ( 'tr' ) )
28- var bottom = table . appendChild ( dom . createElement ( 'tr' ) )
29- var statusArea = bottom . appendChild ( dom . createElement ( 'div' ) )
26+ const table = div . appendChild ( dom . createElement ( 'table' ) )
27+ const main = table . appendChild ( dom . createElement ( 'tr' ) )
28+ const bottom = table . appendChild ( dom . createElement ( 'tr' ) )
29+ const statusArea = bottom . appendChild ( dom . createElement ( 'div' ) )
3030 statusArea . setAttribute ( 'style' , 'padding: 0.7em;' )
3131
32- var context = { dom : dom , div : main , statusArea : statusArea , me : null }
32+ const context = { dom : dom , div : main , statusArea : statusArea , me : null }
3333 UI . authn . logInLoadProfile ( context ) . then ( ( context : any ) => {
3434 let subject : NamedNode = context . me
3535
36- var profile = subject . doc ( )
37- var editable = UI . store . updater . editable ( profile . uri , kb )
36+ const profile = subject . doc ( )
37+ const editable = UI . store . updater . editable ( profile . uri , kb )
3838
3939 main . appendChild ( createText ( 'h3' , 'Manage your trusted applications' ) )
4040
@@ -62,12 +62,12 @@ export function renderTrustedApplicationsOptions (dom: HTMLDocument) {
6262}
6363
6464function createApplicationTable ( subject : NamedNode ) {
65- var applicationsTable = createElement ( 'table' , {
65+ const applicationsTable = createElement ( 'table' , {
6666 'class' : 'results'
6767 } )
6868
6969 // creating headers
70- var header = createContainer ( 'tr' , [
70+ const header = createContainer ( 'tr' , [
7171 createText ( 'th' , 'Application URL' ) ,
7272 createText ( 'th' , 'Access modes' ) ,
7373 createText ( 'th' , 'Actions' )
@@ -99,7 +99,7 @@ function createApplicationEntry (
9999 appModes : NamedNode [ ] ,
100100 updateTable : ( ) => void
101101) : HTMLTableRowElement {
102- var trustedApplicationState = {
102+ const trustedApplicationState = {
103103 origin,
104104 appModes,
105105 formElements : {
@@ -109,65 +109,78 @@ function createApplicationEntry (
109109 }
110110 return createContainer ( 'tr' , [
111111 createContainer ( 'td' , [
112- createElement ( 'input' , {
113- 'class' : 'textinput' ,
114- placeholder : 'Write new URL here' ,
115- value : origin ? origin . value : ''
116- } , { } , ( element ) => { trustedApplicationState . formElements . origin = element } )
117- ] ) ,
118- createContainer ( 'td' , createModesInput ( trustedApplicationState ) ) ,
119- createContainer ( 'td' , origin
120- ? [
121- createText ( 'button' , 'Update' , {
122- 'class' : 'controlButton' ,
123- style : 'background: LightGreen;'
124- } , {
125- click : ( ) => addOrEditApplication ( )
126- } ) ,
127- createText ( 'button' , 'Delete' , {
128- 'class' : 'controlButton' ,
129- style : 'background: LightCoral;'
130- } , {
131- click : ( ) => removeApplication ( )
112+ createContainer ( 'form' , [
113+ createElement ( 'input' , {
114+ 'class' : 'textinput' ,
115+ placeholder : 'Write new URL here' ,
116+ value : origin ? origin . value : ''
117+ } , { } , ( element ) => {
118+ trustedApplicationState . formElements . origin = element
132119 } )
133- ]
134- : [
135- createText ( 'button' , 'Add' , {
136- 'class' : 'controlButton' ,
137- style : 'background: LightGreen;'
138- } , {
139- click : ( ) => addOrEditApplication ( )
140- } )
141- ] )
120+ ] , { } , {
121+ submit : addOrEditApplication
122+ } )
123+ ] ) ,
124+ createContainer ( 'td' , [
125+ createContainer ( 'form' , createModesInput ( trustedApplicationState ) , { } , {
126+ submit : addOrEditApplication
127+ } )
128+ ] ) ,
129+ createContainer ( 'td' , [
130+ createContainer ( 'form' , origin
131+ ? [
132+ createText ( 'button' , 'Update' , {
133+ 'class' : 'controlButton' ,
134+ style : 'background: LightGreen;'
135+ } ) ,
136+ createText ( 'button' , 'Delete' , {
137+ 'class' : 'controlButton' ,
138+ style : 'background: LightCoral;'
139+ } , {
140+ click : removeApplication
141+ } )
142+ ]
143+ : [
144+ createText ( 'button' , 'Add' , {
145+ 'class' : 'controlButton' ,
146+ style : 'background: LightGreen;'
147+ } )
148+ ] , { } , {
149+ submit : addOrEditApplication
150+ } )
151+ ] )
142152 ] )
143153
144- function addOrEditApplication ( ) {
145- var origin
154+ function addOrEditApplication ( event : Event ) {
155+ event . preventDefault ( )
156+ let origin
146157 try {
147158 origin = sym ( trustedApplicationState . formElements . origin ! . value )
148159 } catch ( err ) {
149160 return alert ( 'Please provide an application URL you want to trust' )
150161 }
151162
152- var modes = trustedApplicationState . formElements . modes
163+ const modes = trustedApplicationState . formElements . modes
153164 . filter ( checkbox => checkbox . checked )
154165 . map ( checkbox => checkbox . value )
155166
156- var deletions = getStatementsToDelete ( origin , subject , kb , ns )
157- var additions = getStatementsToAdd ( origin , generateRandomString ( ) , modes , subject , ns ) ;
167+ console . log ( trustedApplicationState . origin , trustedApplicationState . formElements . origin )
168+ const deletions = getStatementsToDelete ( trustedApplicationState . origin || origin , subject , kb , ns )
169+ const additions = getStatementsToAdd ( origin , generateRandomString ( ) , modes , subject , ns ) ;
158170 ( kb as any ) . updater . update ( deletions , additions , handleUpdateResponse )
159171 }
160172
161- function removeApplication ( ) {
162- var origin
173+ function removeApplication ( event : Event ) {
174+ event . preventDefault ( )
175+ let origin
163176 try {
164177 origin = sym ( trustedApplicationState . formElements . origin ! . value )
165178 } catch ( err ) {
166179 return alert ( 'Please provide an application URL you want to remove trust from' )
167180 }
168181
169- var deletions = getStatementsToDelete ( origin , subject , kb , ns ) ;
170- ( kb as any ) . updater . update ( deletions , null , handleUpdateResponse )
182+ const deletions = getStatementsToDelete ( origin , subject , kb , ns ) ;
183+ ( kb as any ) . updater . update ( deletions , [ ] , handleUpdateResponse )
171184 }
172185
173186 function handleUpdateResponse ( uri : any , success : boolean , errorBody : any ) {
@@ -184,7 +197,7 @@ function createElement<K extends keyof HTMLElementTagNameMap> (
184197 eventListeners : { [ eventName : string ] : EventListener } = { } ,
185198 onCreated : ( null | ( ( createdElement : HTMLElementTagNameMap [ K ] ) => void ) ) = null
186199) {
187- var element = document . createElement ( elementName )
200+ const element = document . createElement ( elementName )
188201 if ( onCreated ) {
189202 onCreated ( element )
190203 }
@@ -204,7 +217,7 @@ function createContainer<K extends keyof HTMLElementTagNameMap> (
204217 eventListeners = { } ,
205218 onCreated = null
206219) {
207- var element = createElement ( elementName , attributes , eventListeners , onCreated )
220+ const element = createElement ( elementName , attributes , eventListeners , onCreated )
208221 children . forEach ( child => element . appendChild ( child ) )
209222 return element
210223}
@@ -216,14 +229,14 @@ function createText<K extends keyof HTMLElementTagNameMap> (
216229 eventListeners = { } ,
217230 onCreated = null
218231) {
219- var element = createElement ( elementName , attributes , eventListeners , onCreated )
232+ const element = createElement ( elementName , attributes , eventListeners , onCreated )
220233 element . textContent = textContent
221234 return element
222235}
223236
224237function createModesInput ( { appModes, formElements } : { appModes : NamedNode [ ] , formElements : FormElements } ) {
225238 return [ 'Read' , 'Write' , 'Append' , 'Control' ] . map ( mode => {
226- var isChecked = appModes . some ( appMode => appMode . value === ns . acl ( mode ) . value )
239+ const isChecked = appModes . some ( appMode => appMode . value === ns . acl ( mode ) . value )
227240 return createContainer ( 'label' , [
228241 createElement ( 'input' , {
229242 type : 'checkbox' ,
0 commit comments