Changeset 41 for branches/testa-single-bookmark/js/remotex.js
- Timestamp:
- Aug 30, 2019 7:54:52 AM (6 years ago)
- File:
-
- 1 edited
-
branches/testa-single-bookmark/js/remotex.js (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/testa-single-bookmark/js/remotex.js
r36 r41 7 7 } 8 8 9 make_url_params ( arrayx ){9 make_url_params0( arrayx ){ 10 10 let params = new URLSearchParams(); 11 11 arrayx.reduce(function(acc, element, index, array) { … … 13 13 return acc; 14 14 }, params) 15 return params; 15 return params.toString(); 16 } 17 18 make_url_params( arrayx , num ){ 19 let params = new URLSearchParams(); 20 for(let i=0; i<num; i++ ){ 21 params.append(arrayx[i][0], arrayx[i][1]) 22 } 23 const pa = params.toString() 24 return pa 16 25 } 17 26 18 27 async get_filelist_from_remote( num, part, func ) { 19 console.log("remotex get_filelist_from_remote num=" + num + " part=" + part )20 28 let param_array = [['cmd', 'get_filelistx'], ['num', num ], ['part', part ]] 21 await this.fetchx( this.filename , param_array, func )29 await this.fetchx( this.filename , param_array, 3, func ) 22 30 } 23 31 24 32 async update_filelist( num, part, func ) { 25 console.log("remotex update_filelist num=" + num + " part=" + part )26 33 let param_array = [['cmd', 'update_filelistx'], ['num', num ], ['part', part ]] 27 await this.fetchx( this.filename , param_array, func )34 await this.fetchx( this.filename , param_array, 3, func ) 28 35 } 29 36 30 37 async get_content(num, part, path , func) { 31 console.log("remotex get_content num=" + num + " part=" + part )32 console.log("part=" + part)33 38 let param_array = [['cmd', 'get_content'], ['num', num ], ['part', part ], ['path', path]] 34 await this.fetchx( this.filename , param_array, func )39 await this.fetchx( this.filename , param_array, 4, func ) 35 40 } 36 41 37 42 async get_output_url(num, func) { 38 console.log("get_output_url")39 console.log("remotex get_output_url num=" + num )40 43 let param_array = [['cmd', 'get_output_url'], ['num', num ] ] 41 await this.fetchx( this.filename , param_array, func )44 await this.fetchx( this.filename , param_array, 2, func ) 42 45 } 43 46 44 async fetchx( filename, param_array, func) { 45 console.log("fetchx func" + func) 46 let params = this.make_url_params( param_array ) 47 async fetchx( filename, param_array, num, func) { 48 let params = this.make_url_params( param_array , num ) 47 49 fetch(`${filename}?${params}`) 48 .then((response) => response.text())49 .then((text) => { console.log(func) ; if( func !== undefined ){func(text)} else { console.log("func=undefined")}})50 .catch((error) => console.log( error));50 .then((response) => { return response.text() }) 51 .then((text) => { func(text) }) 52 .catch((error) => console.log("error=" + error)); 51 53 } 52 54 … … 54 56 if( Globalx[part].key_indicate_file === true ){ 55 57 let textarea = $( Globalx[part].textarea_sel ) 56 upload_content(Globalx.num, part, Globalx[part].key, textarea.val())58 this.upload_content(Globalx.num, part, Globalx[part].key, textarea.val()) 57 59 } 60 } 61 62 async build( cmd, num, part, path, content, func = null ) { 63 await this.upload_file( cmd, num, part, path, content, func = null ) 64 } 65 66 async upload_file(cmd, num, part, path, content, func = null) { 67 let form = document.createElement('form') 68 let req_cmd = document.createElement('input') 69 let req_num = document.createElement('input') 70 let req_part = document.createElement('input') 71 let req_path = document.createElement('input') 72 let req_content = document.createElement('input') 73 74 document.body.appendChild(form) 75 76 req_cmd.type = 'hidden' 77 req_cmd.name = 'cmd' 78 req_cmd.value = cmd 79 80 req_num.type = 'hidden' 81 req_num.name = 'num' 82 req_num.value = num + '' 83 84 req_part.type = 'hidden' 85 req_part.name = 'part' 86 req_part.value = part 87 88 req_path.type = 'hidden' 89 req_path.name = 'path' 90 req_path.value = path 91 92 req_content.type = 'hidden' 93 req_content.name = 'mytext' 94 req_content.value = content 95 96 form.appendChild(req_cmd) 97 form.appendChild(req_num) 98 form.appendChild(req_part) 99 form.appendChild(req_path) 100 form.appendChild(req_content) 101 102 // FormDataオブジェクトを作成する 103 var form_data = new FormData(form); 104 console.log("remotex.js filename=" + this.filename ) 105 fetch( this.filename , { 106 method: 'POST', 107 mode: 'same-origin', /* 'no-cors' 'cors' 'same-origin' */ 108 body: form_data 109 }) 110 .then((response) => { 111 return response.text() 112 }) 113 .then((data) => {console.log( "data=" + data) 114 if( func !== null ){ 115 func(data) 116 } 117 }) 118 .catch((error) => {console.log("error=" + error)}) 58 119 } 59 120 … … 64 125 let req_cmd = document.createElement('input'); 65 126 let req_num = document.createElement('input'); 127 let req_part = document.createElement('input'); 66 128 67 129 document.body.appendChild(form); … … 82 144 req_num.value = num + ''; 83 145 146 req_part.type = 'hidden'; 147 req_part.name = 'part'; 148 req_part.value = part; 149 84 150 form.appendChild(req_content); 85 151 form.appendChild(req_path); 86 152 form.appendChild(req_cmd); 87 153 form.appendChild(req_num); 154 form.appendChild(req_part); 88 155 89 156 // FormDataオブジェクトを作成する 90 157 var form_data = new FormData(form); 91 92 fetch( 'php/content.php', {158 console.log("remotex.js filename=" + this.filename ) 159 fetch( this.filename , { 93 160 method: 'POST', 94 161 mode: 'same-origin', /* 'no-cors' 'cors' 'same-origin' */ 95 162 body: form_data 96 163 }) 97 .then((response) => response.text())98 .then((data) => console.log(data))99 .catch((error) => console.log(error));164 .then((response) => { return response.text()}) 165 .then((data) => {console.log( "data=" + data)}) 166 .catch((error) => {console.log("error=" + error)}); 100 167 } 101 168
Note: See TracChangeset
for help on using the changeset viewer.
![(trac.ini の [header_logo] セクションを設定してください)](/python/trac/Flist/chrome/common/trac_logo_mini.png)