source: branches/testa-single-bookmark/js/bookmarkmgr.js @ 103

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

hide unused menu by css

File size: 1.6 KB
RevLine 
[23]1class BookmarkMgr {
[36]2    constructor( max_display_name_length , parts ) {
3        this.paths = {}
4
5        this.parts = parts
6        this.parts.map( (part) => {
7            this.paths[part] = []
8        } )
[23]9        this.items = {}
[36]10        this.parts.map( (part) => {
11            this.items[part] = {}
12        } )
[23]13        this.max_display_name_length = max_display_name_length
14    }
15
[36]16    add( part, path , display_name = null){
17console.log("BookmarkMgr add part=" + part + " path="+ path)
18        let result = this.paths[part].indexOf( path )
[23]19        if( result < 0 ){
[36]20            this.paths[part].push( path )
21            this.items[part][ path ] = new Bookmark( path , this.max_display_name_length , display_name )
[23]22        }
[36]23        return this.items[part][ path ]
[23]24    }
25
[36]26    remove( part, path ){
27        let result = this.paths[part].indexOf( path )
[23]28        if( result >= 0 ){
[36]29            delete this.items[part][ path ]
30            delete this.paths[part][ result ]
[23]31        }
32    }
33
[36]34    get( part, path ){
[25]35        let ret = null
[36]36        let result = this.paths[part].indexOf( path )
[25]37        if( result >= 0 ){
[36]38            ret = this.items[part][ path ]
[25]39        }
40        return ret
41    }
42
[36]43    display_name( part, path ){
44        let result = this.paths[part].indexOf( path )
[23]45        let disp = null
46        if( result >= 0 ){
[36]47            disp = this.items[part][ path ].display_name
[23]48        }
49        return disp
50    }
51
[36]52    get_paths(part){
53        return this.paths[part]
[23]54    }
55
[36]56    get_display_names(part, path){
57        const array = thils.paths[part]
[23]58        return array.map( function( path ){
[36]59            return this.items[part][ path ].display_name
[23]60        } )
61    }
62
63    get_restricted_display_name( path ){
[36]64        return path.substr( -(this.max_display_name_length) )
[23]65    }
[25]66
[36]67    get_items(part) {
68        return this.items[part]
[25]69    }
70
71    max_display_name_length(){
72        return this.max_display_name_length
73    }
[23]74}
Note: See TracBrowser for help on using the repository browser.