Changeset 41 for branches


Ignore:
Timestamp:
Aug 30, 2019 7:54:52 AM (6 years ago)
Author:
anonymous
Message:

add bin

Location:
branches/testa-single-bookmark
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/testa-single-bookmark/js/bookmarkmenu.js

    r36 r41  
    66
    77    dlg(){
    8 console.log("BookmarkMenu dlg()")
    98        $( '#bookmark_displayname' ).prop( 'maxlength' , Globalx.bookmark_displayname_max_length)
    109        $('#bookmarkDlg').dialog({
     
    3029    add_bookmark() {
    3130        let part = Globalx.parts[ Globalx.index ]
    32 console.log("add_bookmark part=" + part)
    3331        $( '#bookmark_displayname' ).val( this.bookmark_mgr.get_restricted_display_name( Globalx[part].key ) )
    3432        $( '#bookmark_path' ).val( Globalx[part].key )
     
    3836    remove_bookmark() {
    3937        let part = Globalx.parts[ Globalx.index ]
    40 console.log("remove_bookmark part=" + part)
    4138        this.bookmark_mgr.remove( part, Globalx[part].key )
    4239        this.rebuild_bookmark_menu(part)
     
    4643        let part = Globalx.parts[ Globalx.index ]
    4744        let bookmark_op_sel = Globalx[part].bookmark_op_sel
    48 console.log("bookmark_op part=" + part + " bookmark_op_sel=" + bookmark_op_sel)
    4945        if( $( bookmark_op_sel ).is(':checked') == true ){
    5046            this.add_bookmark()
     
    5854        let bookmark_op_sel = Globalx[part].bookmark_op_sel
    5955
    60         console.log( "set_click_handler() part=" + part + " bookmark_op_sel=" + bookmark_op_sel )
    6156        $( bookmark_op_sel ).on( 'click' , () => {
    6257            console.log("bookmark_op_sel clicked")
     
    7469        let num = Globalx.num
    7570        let bookmark_sel = Globalx[part].bookmark_sel
    76 console.log("BookmarkMenu rebuld_bookmark_menu num="+num+ " part="+part)
    7771        $( bookmark_sel ).empty()
    7872
    7973        const array = this.bookmark_mgr.get_paths(part)
    80 console.log("BookmarkMenu rebuld_bookmark_menu array=" + array )
    8174
    8275        let content = null
     
    8881            $( bookmark_sel ).append( content );
    8982            console.log( "bookmark_sel="+bookmark_sel)
    90             item = $( bookmark_sel ).last()
     83            item = $( bookmark_sel ).children().last()
    9184            console.log( "item=" + item )
    9285            item.on('click' , () => {
     
    10598    }
    10699
    107     bookmark_action = ( part, key ) => {
     100    bookmark_action ( part, key ) {
    108101        if( key === null || key === "" ){
    109102            alert("illeagal key=" + key )
     
    121114
    122115        $( Globalx[part].key_sel ).val( key )
    123 console.log("jsondata=" + jsondata)
    124116        if( jsondata[key].length == 0 ){
    125117            Globalx[part].key_indicate_file = true;
  • branches/testa-single-bookmark/js/main.js

    r36 r41  
    1010function init_globalx_storagex() {
    1111    Globalx.storagex = new Storagex();
     12    Globalx.build = {
     13        'contest2011.md': {
     14            path: '/attempt/contest2011/data/contest2011.md',
     15            target: 'cont',
     16            subtarget: '2011',
     17            category: 'attempt',
     18            output_html: 'contest2011.html',
     19            alias_html: 'contest.html',
     20        }
     21    }
     22
    1223}
     24
    1325
    1426function init_globalx() {
    1527    Globalx.num = 0
    1628    Globalx.index = 0
    17     Globalx.parts = ["data", "output", "setting"]
     29    Globalx.parts = ["data" , "output", "setting"]
    1830    Globalx.bookmark_displayname_max_length = 18
    1931    Globalx.output_url = null
     32    Globalx.remote_filename = 'php/content3.php'
     33    Globalx.build = new Build()
    2034
    2135    tab_init()
    2236    topmenu_init()
    23     Globalx.remotex = new Remotex('php/content.php')
    24     console.log( "init_globalx 1 : Globalx.bookmark_mgr="  + Globalx.bookmark_mgr )
     37    Globalx.remotex = new Remotex( Globalx.remote_filename )
    2538    if( Globalx.bookmark_mgr === null || Globalx.bookmark_mgr === undefined ){
    2639        Globalx.bookmark_mgr = new BookmarkMgr(Globalx.bookmark_displayname_max_length, Globalx.parts)
    2740    }
    28     console.log( "init_globalx 2 : Globalx.bookmark_mgr="  + Globalx.bookmark_mgr )
    2941    Globalx.bookmarkmenu = null
     42
     43    Globalx.build.setup()
    3044}
    3145
    32 async function get_output_url_async( func ){
     46async function update_all_filelist( ) {
     47    Globalx.parts.map( ( part ) => {
     48        Globalx[ part ].sidemenu.update(`#${part}-side`)
     49    } )
     50}
     51
     52async function get_output_url_async( num, func ){
    3353    let realData = Globalx.storagex.get_output_url()
    3454
    3555    if( realData === undefined || realData === null ){
    36         await Globalx.remotex.get_output_url( func )
     56        await Globalx.remotex.get_output_url( num, func )
    3757    }
    3858    else{
    39         const obj = Globalx.storagex.get_output_url( num , part )
     59        const obj = Globalx.storagex.get_output_url( num )
    4060        Globalx.output_url = obj.output_url
    4161        Globalx.storagex.save_as_info_from_globalx()
     
    4464
    4565async function setup(){
    46     get_output_url_async( (text) => {
     66    get_output_url_async( Globalx.num, (text) => {
    4767        let str = text
    4868        let obj
     
    6585    setup()
    6686
    67     console.log("##### Globalx.bookmarkmenu=" + Globalx.bookmarkmenu)
    68     console.log("##### Globalx.bookmark_mgr=" + Globalx.bookmark_mgr)
    6987    Globalx.bookmarkmenu = new BookmarkMenu( Globalx.bookmark_displayname_max_length , Globalx.bookmark_mgr )
    7088    Globalx.bookmarkmenu.dlg()
     
    7391        set_globalx_editor(part)
    7492
     93        Globalx[ part ].menu = null
    7594        Globalx[ part ].sidemenu = new SideMenu( Globalx.num, part )
    7695        Globalx[ part ].sidemenu.setup(`#${part}-side`)
     
    84103    if( need_to_save ){
    85104        // LocalStorageにまだ保存していない場合、ここで保存しておく
    86         //console.log("call save_as_info_from_globalx()")
    87105        Globalx.storagex.save_as_info_from_globalx( (data) => { console.log( "data=" + data ) } )
    88106    }
    89 /*
    90     Object.keys(Globalx).forEach((key) => {
    91         console.log(key)
    92     }) */
    93107}
    94108
     
    130144
    131145      let textarea = $( Globalx[part].textarea_sel )
    132       editor.getSession().on("change", (textarea) => {
    133           textarea.val(editor.getSession().getValue());
     146      editor.getSession().on("change", () => {
     147/*          textarea.val(editor.getSession().getValue()) */
     148          $( Globalx[part].textarea_sel ).val(editor.getSession().getValue())
    134149      });
    135150}
     151
     152function upload_to_host( part ){
     153    Globalx.remotex.upload_to_host( part )
     154}
  • branches/testa-single-bookmark/js/remotex.js

    r36 r41  
    77    }
    88
    9     make_url_params( arrayx ){
     9    make_url_params0( arrayx ){
    1010        let params = new URLSearchParams();
    1111        arrayx.reduce(function(acc, element, index, array) {
     
    1313            return acc;
    1414        }, 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
    1625    }
    1726
    1827    async get_filelist_from_remote( num, part, func ) {
    19         console.log("remotex get_filelist_from_remote num=" + num + " part=" + part )
    2028        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 )
    2230    }
    2331
    2432    async update_filelist( num, part, func ) {
    25         console.log("remotex update_filelist num=" + num + " part=" + part )
    2633        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 )
    2835    }
    2936
    3037    async get_content(num, part, path , func) {
    31         console.log("remotex get_content num=" + num + " part=" + part )
    32         console.log("part=" + part)
    3338        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 )
    3540    }
    3641
    3742    async get_output_url(num, func) {
    38 console.log("get_output_url")
    39         console.log("remotex get_output_url num=" + num )
    4043        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 )
    4245    }
    4346
    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 )
    4749        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));
    5153    }
    5254
     
    5456        if( Globalx[part].key_indicate_file === true ){
    5557            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())
    5759        }
     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);
     104console.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)})
    58119    }
    59120
     
    64125        let req_cmd = document.createElement('input');
    65126        let req_num = document.createElement('input');
     127        let req_part = document.createElement('input');
    66128
    67129        document.body.appendChild(form);
     
    82144        req_num.value = num + '';
    83145       
     146        req_part.type = 'hidden';
     147        req_part.name = 'part';
     148        req_part.value = part;
     149       
    84150        form.appendChild(req_content);
    85151        form.appendChild(req_path);
    86152        form.appendChild(req_cmd);
    87153        form.appendChild(req_num);
     154        form.appendChild(req_part);
    88155       
    89156        // FormDataオブジェクトを作成する
    90157        var form_data = new FormData(form);
    91 
    92         fetch('php/content.php', {
     158console.log("remotex.js filename=" + this.filename )
     159        fetch( this.filename , {
    93160            method: 'POST',
    94161            mode: 'same-origin', /* 'no-cors' 'cors' 'same-origin' */
    95162            body: form_data
    96163        })
    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)});
    100167    }
    101168
  • branches/testa-single-bookmark/js/sidemenu.js

    r36 r41  
    1212    }
    1313
    14     async setup(top_sel){
    15         console.log("SideMenu setup menu_sel=" + this.menu_sel)
    16         let content = `<ul id="${this.menu_id}"></ul>`
    17         $(top_sel).append( content )
    18         this.get_filelist_async( this.num , this.part , (text) => {
    19             console.log("SideMenu setup text=" + text)
    20             let str = text
    21             let obj
    22             if( str.match( /{.*}/ ) === null ){
    23                 obj = {}
    24                 console.log("sidemenu setup 1 num=" + this.num + " part=" + this.part)
    25             }
    26             else {
    27                 obj = JSON.parse( str )
    28                 console.log("sidemenu setup 2 num=" + this.num + " part=" + this.part + " str="+str)
    29             }
    30             console.log( "sidemenu setup this.num=" + this.num + " this.part=" + this.part )
    31             Globalx.storagex.change_cache( obj, this.num , this.part )
    32            
    33             this.make_menu_item_list( obj , Globalx[this.part].key)
    34             $( this.menu_sel ).menu({
     14    display_menu( text ) {
     15        let str = text
     16        let obj
     17        if( str.match( /{.*}/ ) === null ){
     18            console.log("sidemenu 1 num="+ this.num + " part="+ this.part +" str="+str)
     19            obj = {}
     20        }
     21        else {
     22            console.log("sidemenu 2 num="+ this.num +" part="+ this.part +" str="+str)
     23            obj = JSON.parse( str )
     24        }
     25        Globalx.storagex.change_cache( obj, this.num , this.part )
     26
     27        this.setup_menu(obj)
     28    }
     29
     30    setup_menu(obj){
     31        this.make_menu_item_list( obj , Globalx[this.part].key)
     32        if( Globalx[this.part].menu === null ){
     33            Globalx[this.part].menu = $( this.menu_sel ).menu({
    3534                classes: {
    3635                    "ui-menu": "highlight"
    3736                }
    3837            })
    39         })
     38        }
     39    }
     40
     41    menu_init( top_sel ){
     42        $( top_sel ).empty()
     43        let content = `<ul id="${this.menu_id}"></ul>`
     44        $( top_sel ).append( content )
     45    }
     46
     47    async setup( top_sel ){
     48        this.menu_init( top_sel )
     49        this.get_filelist_async( this.num , this.part , (text) => {
     50            this.display_menu(text)
     51        } )
     52    }
     53
     54    async update( top_sel ){
     55        this.menu_init( top_sel )
     56        await Globalx.remotex.update_filelist( this.num, this.part, (text) => {
     57            this.display_menu(text)
     58        } )
    4059    }
    4160
    4261    async get_filelist_async( num , part , func){
    43         if( part == "setting" ){
    44             console.log( "get_filelist_async START part="+ part)
    45         }
    4662        let realData = Globalx.storagex.get_filelist( num , part )
    4763
    48         if( part == "setting" ){
    49             console.log( "get_filelist_async 2 part=" + part)
    50         }
    5164        if( realData === undefined || realData === null ){
    52             if( part == "setting" ){
    53                 console.log( "get_filelist_async 3 part=" + part)
    54             }
    5565            await Globalx.remotex.get_filelist_from_remote( num, part, func )
    56             if( part == "setting" ){
    57                 console.log( "get_filelist_async 4 part=" + part)
    58             }
    5966        }
    6067        else{
    6168            const obj = Globalx.storagex.get_filelist( num , part )
    62             this.make_menu_item_list( obj , Globalx[this.part].key)
    63             $( this.menu_sel ).menu({
    64                 classes: {
    65                     "ui-menu": "highlight"
    66                 }
    67             })
     69            this.setup_menu( obj )
    6870        }
    6971    }
     
    121123            if( jsondata[Globalx[part].key].length == 0 ){
    122124                Globalx[part].key_indicate_file = true;
     125console.log("Globalx[" + part + "].key_indicate_file = " + Globalx[part].key_indicate_file)
    123126                let url = ""
    124127                $( Globalx[part].download_url_sel ).val( Globalx[part].key )
     
    128131                $( Globalx[part].download_partial_url_sel ).attr('href' , url )
    129132                Globalx.remotex.get_content( this.num, this.part, Globalx[part].key , (content) => {
    130                     //console.log("content=" + content)
    131133                    Globalx[part].editor.getSession().setValue( content );
    132134                    $( Globalx[part].textarea_sel ).val( content );
     
    143145        let name = '..(Up)'
    144146        content = `<li class="ui-menu-item"><div class="ui-menu-item-wrapper hasmenu">${name}</div></li>`;
    145         // content = `<li class="ui-menu-item"><div class="ui-menu-item-wrapper hasmenu" onclick="menu_action( '${this.part}', '${this.name}', true)">${name}</div></li>`;
    146         //      content = `<li class="ui-menu-item"><div class="ui-menu-item-wrapper hasmenu" onclick="this.menu_action_2">${name}</div></li>`;
    147147        $( this.menu_sel ).append(content);
    148         item = $( this.menu_sel ).last()
     148        item = $( this.menu_sel ).children().last()
    149149        item.on('click' , () => {
    150150            this.menu_action( key , true )
     
    154154            ary.map( ( item_name ) => {
    155155                content = `<li class="ui-menu-item"><div class="ui-menu-item-wrapper hasmenu">${item_name}</div></li>`;
    156                 // content = `<li class="ui-menu-item"><div class="ui-menu-item-wrapper hasmenu" onclick="menu_action( '${this.part}', '${item_name}' , false)">${item_name}</div></li>`;
    157                 //          content = `<li class="ui-menu-item"><div class="ui-menu-item-wrapper hasmenu" onclick="this.menu_action_2">${item_name}</div></li>`;
    158156                $( this.menu_sel ).append(content);
    159                 item = $( this.menu_sel ).last()
     157                item = $( this.menu_sel ).children().last()
    160158                item.on('click' , () => {
    161159                    this.menu_action( item_name )
     
    165163    }
    166164
    167     set_globalx_item_name( item_name ) {
    168         Globalx[this.part].item_name = item_name
    169         let dl = $( Globalx[ this.part ].download_sel )
    170         dl.attr('download' , Globalx[this.part].item_name)
     165    set_globalx_item_name( part , item_name ) {
     166        Globalx[part].item_name = item_name
     167        let dl = $( Globalx[ part ].download_sel )
     168        dl.attr('download' , Globalx[part].item_name)
    171169        dl.removeAttr('href')
    172170    }
     
    190188}
    191189
    192 /*
    193 function menu_action(part, item_name , up_flag = false) {
    194     Globalx[part].sidemenu.menu_action(item_name , up_flag)
    195 }
    196 */
  • branches/testa-single-bookmark/js/storagex.js

    r36 r41  
    216216    }
    217217
    218     reset_info = () => {
    219         let item_name = 'info'
    220         reset_localstorage(item_name)
     218    reset_info() {
     219        reset_localstorage('info')
    221220    }
    222221   
     
    226225    }
    227226
    228     clear_localstorage = () => {
     227    clear_localstorage() {
    229228        let keys = Object.keys(this._globalStorage)
    230229        keys.map( (v) => { delete this._globalStorage[v] } )
Note: See TracChangeset for help on using the changeset viewer.