source: branches/testa-x/js/bookmarkmenu.js @ 80

Last change on this file since 80 was 29, checked in by anonymous, 6 years ago

add js

File size: 2.5 KB
Line 
1class BookmarkMenu {
2    constructor(num, part) {
3        this.num = num
4        this.part = part
5        this.bookmark_op_sel = Globalx[part].bookmark_op_sel
6        this.bookmark_mgr = Globalx[part].bookmark_mgr
7        this.bookmark_sel = Globalx[part].bookmark_sel
8        this.key_sel = Globalx[part].key_sel
9        this.editor = Globalx[part].editor
10        this.textarea_sel = Globalx[part].textarea_sel
11        this.menu_sel = Globalx[part].menu_sel
12    }
13
14    add_bookmark() {
15        $( '#bookmark_displayname' ).val( Globalx[this.part].bookmark_mgr.get_restricted_display_name( Globalx[this.part].key ) )
16        $( '#bookmark_path' ).val( Globalx[this.part].key )
17        $( '#bookmarkDlg' ).dialog("open")
18    }
19
20    remove_bookmark() {
21        this.bookmark_mgr.remove( Globalx[this.part].key )
22        this.rebuild_bookmark_menu()
23    }
24
25    bookmark_op() {
26        if( $( this.bookmark_op_sel ).is(':checked') == true ){
27            this.add_bookmark()
28        }
29        else{
30            this.remove_bookmark()
31        }
32    }
33
34    set_click_handler() {
35        console.log( "set_click_handler() part=" + this.part + " num=" + this.num )
36        $( this.bookmark_op_sel ).on( 'click' , () => { this.bookmark_op() } )
37    }
38
39    register_bookmark_( path, displayname ) {
40        this.bookmark_mgr.add( path , displayname )
41        this.rebuild_bookmark_menu()
42    }
43
44    rebuild_bookmark_menu() {
45        $( this.bookmark_sel ).empty()
46
47        const array = this.bookmark_mgr.get_paths()
48
49        array.map( ( path ) => {
50            const display_name = this.bookmark_mgr.display_name( path )
51            content = `<li><a href="#" onclick="this.bookmark_action( '${this.part}' , '${this.path}' )">${display_name}</a></li>`;
52            $( this.bookmark_sel ).append(content);
53        })
54    }
55
56    bookmark_action = ( part, key ) => {
57        if( key === null || key === "" ){
58            alert("illeagal key=" + key )
59            return
60        }
61        if(key === Globalx[part].key){
62            return
63        }
64
65        let realData = Globalx.remotex.get_filelist( this.num )
66        Globalx[part].key = key
67        Globalx[part].key_indicate_file = false;
68
69        this.set_globalx_item_name( part, key )
70        $( this.key_sel ).val( key )
71
72        if( realData[Globalx[part].key].length == 0 ){
73            Globalx[part].key_indicate_file = true;
74            Globalx.remotex.get_content( this.num, this.part, Globalx[part].key , (content) => {
75                this.editor.getSession().setValue( content );
76                $( this.textarea_sel ).val( content );
77            });
78        }
79        else{
80            Globalx[part].key_indicate_file = false
81            this.editor.getSession().setValue( "" );
82            $( this.textarea_sel ).val( "" );
83        }
84        const bookmark_cb = $( this.bookmark_op_sel )
85        bookmark_cb.prop('checked', true)
86
87        $( this.menu_sel ).empty()
88
89        this.rebuild_bookmark_menu()
90        // this.make_menu_item_list(realData, Globalx[part].key)
91    }
92}
Note: See TracBrowser for help on using the repository browser.