source: branches/testa-single-bookmark/js/sidemenu.js @ 38

Last change on this file since 38 was 36, checked in by anonymous, 6 years ago

hide unused menu by css

File size: 6.0 KB
Line 
1class SideMenu {
2    constructor (num , part){
3        this.part = part
4        this.num = num
5        this.menu_sel = Globalx[part].menu_sel
6        this.menu_id = Globalx[part].menu_id
7        this.textarea_sel = Globalx[part].textarea_sel
8        this.bookmark_op_sel = Globalx[part].bookmark_op_sel
9    }
10    set_editor( editor ){
11        this.editor = editor /* Globalx[part].editor */
12    }
13
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({
35                classes: {
36                    "ui-menu": "highlight"
37                }
38            })
39        })
40    }
41
42    async get_filelist_async( num , part , func){
43        if( part == "setting" ){
44            console.log( "get_filelist_async START part="+ part)
45        }
46        let realData = Globalx.storagex.get_filelist( num , part )
47
48        if( part == "setting" ){
49            console.log( "get_filelist_async 2 part=" + part)
50        }
51        if( realData === undefined || realData === null ){
52            if( part == "setting" ){
53                console.log( "get_filelist_async 3 part=" + part)
54            }
55            await Globalx.remotex.get_filelist_from_remote( num, part, func )
56            if( part == "setting" ){
57                console.log( "get_filelist_async 4 part=" + part)
58            }
59        }
60        else{
61            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            })
68        }
69    }
70
71    menu_action( item_name , up_flag = false ) {
72        let part = this.part
73        let jsondata = Globalx.storagex.get_filelist( Globalx.num , part)
74
75        Globalx[part].key_indicate_file = false;
76        if( up_flag ){
77            this.set_globalx_item_name(part, "")
78            Globalx[part].editor.getSession().setValue( "" );
79            $( this.textarea_sel ).val( "" );
80            if( Globalx[part].key != '/' ){
81                let array = Globalx[part].key.split("/")
82                array.pop()
83                if( array.length > 1 ){
84                    Globalx[part].key_type = false;
85                    this.set_globalx_item_name( part, array[array.length - 1] )
86
87                    Globalx[part].key = array.join('/')
88                    $( Globalx[part].menu_sel ).empty()
89                }
90                else {
91                    Globalx[part].key = '/'
92                    this.set_globalx_item_name( part, "" )
93                }
94            }
95        }
96        else{
97            if( Globalx[part].key == '/' ){
98                Globalx[part].key = Globalx[part].key + item_name
99            }
100            else{
101                Globalx[part].key = Globalx[part].key + '/' + item_name
102            }
103        }
104        this.set_globalx_item_name(part, item_name)
105
106        const bookmark_cb = $( this.bookmark_op_sel )
107        if( Globalx[part].bookmarks.indexOf( Globalx[part].key ) >= 0 ){
108            bookmark_cb.prop('checked', true)
109        }
110        else{
111            bookmark_cb.prop('checked', false)
112        }
113
114        $( Globalx[part].key_sel ).val( Globalx[part].key )
115
116        $( this.menu_sel ).empty()
117
118        this.make_menu_item_list(jsondata, Globalx[part].key)
119
120        if( jsondata !== undefined && jsondata[Globalx[part].key] !== undefined ){
121            if( jsondata[Globalx[part].key].length == 0 ){
122                Globalx[part].key_indicate_file = true;
123                let url = ""
124                $( Globalx[part].download_url_sel ).val( Globalx[part].key )
125                $( Globalx[part].download_url_sel ).attr('href' , url )
126                $( Globalx[part].download_partial_url_sel ).val( Globalx[part].key + "(parial)" )
127                url = url + ".tmp"
128                $( Globalx[part].download_partial_url_sel ).attr('href' , url )
129                Globalx.remotex.get_content( this.num, this.part, Globalx[part].key , (content) => {
130                    //console.log("content=" + content)
131                    Globalx[part].editor.getSession().setValue( content );
132                    $( Globalx[part].textarea_sel ).val( content );
133                });
134            }
135        }
136    }
137
138    make_menu_item_list( realData , key){
139        let content = null
140        let item = null
141        let ary = realData[ key ]
142       
143        let name = '..(Up)'
144        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>`;
147        $( this.menu_sel ).append(content);
148        item = $( this.menu_sel ).last()
149        item.on('click' , () => {
150            this.menu_action( key , true )
151        } )
152
153        if( ary !== undefined ){
154            ary.map( ( item_name ) => {
155                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>`;
158                $( this.menu_sel ).append(content);
159                item = $( this.menu_sel ).last()
160                item.on('click' , () => {
161                    this.menu_action( item_name )
162                } )
163            })
164        }
165    }
166
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)
171        dl.removeAttr('href')
172    }
173
174    contextmenux0( menu_sel ) {
175        $( menu_sel ).contextmenu({
176            delegate: ".hasmenu",
177            menu: [
178                {title: "Copy", cmd: "copy", uiIcon: "ui-icon-copy"},
179                {title: "----"},
180                {title: "More", childern: [
181                    {title: "Sub 1", cmd: "sub1"},
182                    {title: "Sub 2", cmd: "sub1"}
183                ]}
184            ],
185            select: (event, ui) => {
186                alert("select " + ui.cmd + " on " + ui.target.text());
187            }
188        });
189    }
190}
191
192/*
193function menu_action(part, item_name , up_flag = false) {
194    Globalx[part].sidemenu.menu_action(item_name , up_flag)
195}
196*/
Note: See TracBrowser for help on using the repository browser.