1+ window . cls || ( window . cls = { } ) ;
2+
3+ /**
4+ * @constructor
5+ * @extends ViewBase
6+ */
7+ cls . ResourceTestView = function ( id , name , container_class , html , default_handler ) {
8+ if ( cls . ResourceTestView . instance )
9+ {
10+ return cls . ResourceTestView . instance ;
11+ }
12+ cls . ResourceTestView . instance = this ;
13+
14+ // const
15+ var updateThrottleTime = 500 ;
16+
17+ // "private"
18+ this . _service = new cls . ResourceManagerService ( this ) ;
19+ this . _loading = false ;
20+
21+ this . _updateTime = 0 ;
22+ this . _updateThrottled = false ;
23+
24+ // public
25+
26+ this . createView = function ( container )
27+ {
28+ // throttle
29+ var timeSinceLastRender = Date . now ( ) - this . _updateTime ;
30+ if ( timeSinceLastRender < updateThrottleTime )
31+ {
32+ if ( ! this . _updateThrottled )
33+ {
34+ this . _updateThrottled = true ;
35+ setTimeout ( this . update . bind ( this ) , updateThrottleTime - timeSinceLastRender ) ;
36+ }
37+ return ;
38+ }
39+ else
40+ {
41+ this . _updateThrottled = false ;
42+ this . _updateTime = Date . now ( ) ;
43+ }
44+
45+ // createView
46+ var service = this . _service ;
47+ var ctx = this . _service . get_resource_context ( ) ;
48+
49+ if ( ctx && Object . keys ( ctx . resourcesDict ) . length )
50+ {
51+ container . clearAndRender ( templates . resource_tree . update ( ctx ) ) ;
52+ }
53+ else if ( this . _loading )
54+ {
55+ container . clearAndRender (
56+ [ 'div' ,
57+ [ 'p' , "Loading page..." ] ,
58+ 'class' , 'info-box'
59+ ]
60+ ) ;
61+ }
62+ else
63+ {
64+ container . clearAndRender (
65+ [ 'div' ,
66+ [ 'span' ,
67+ 'class' , 'container-button ui-button' ,
68+ 'handler' , 'reload-window' ,
69+ 'tabindex' , '1' ] ,
70+ [ 'p' , ui_strings . S_RESOURCE_CLICK_BUTTON_TO_FETCH_RESOURCES ] ,
71+ 'class' , 'info-box'
72+ ]
73+ ) ;
74+ }
75+ } ;
76+
77+
78+ this . _on_abouttoloaddocument_bound = function ( )
79+ {
80+ this . _loading = true ;
81+ this . update ( ) ;
82+ } . bind ( this ) ;
83+
84+ this . _on_documentloaded_bound = function ( )
85+ {
86+ this . _loading = false ;
87+ this . update ( ) ;
88+ } . bind ( this ) ;
89+
90+
91+
92+ // WIP: this comes straight from the old resource_all_view
93+ this . _type_class_map =
94+ {
95+ image : cls . ImageResourceDetail ,
96+ font : cls . FontResourceDetail ,
97+ script : cls . JSResourceDetail ,
98+ markup : cls . MarkupResourceDetail ,
99+ css : cls . CSSResourceDetail ,
100+ text : cls . TextResourceDetail ,
101+ } ;
102+ this . _open_resource_views = { } ;
103+
104+ this . _open_resource_tab = function ( resource , data )
105+ {
106+ var ui = UI . get_instance ( ) ;
107+
108+ if ( ! this . _open_resource_views [ resource . id ] )
109+ {
110+ var viewclass = this . _type_class_map [ resource . type ] || cls . GenericResourceDetail ;
111+ var view = new viewclass ( resource , this . _service ) ;
112+ this . _open_resource_views [ resource . id ] = view . id ;
113+ }
114+ window . views [ this . _open_resource_views [ resource . id ] ] . data = data
115+
116+ ui . get_tabbar ( "resources" ) . add_tab ( this . _open_resource_views [ resource . id ] ) ;
117+ ui . show_view ( this . _open_resource_views [ resource . id ] ) ;
118+ }
119+
120+
121+ var eh = window . eventHandlers ;
122+ // fixme: this is in the wrong place! Doesn't belong in UI and even if it
123+ // did, the event handler doesn't get added until the view is created
124+ // which means you can't open tabs from elsewhere if you haven't opened
125+ // the resources view first
126+ /*
127+ eh.click["resources-all-open"] = this._handle_open_resource_bound;
128+ eh.click['open-resource-tab'] = function(event, target)
129+ {
130+ var broker = cls.ResourceDisplayBroker.get_instance();
131+ broker.show_resource_for_ele(target);
132+ }
133+ */
134+ var doc_service = window . services [ 'document-manager' ] ;
135+ doc_service . addListener ( "abouttoloaddocument" , this . _on_abouttoloaddocument_bound ) ;
136+ doc_service . addListener ( "documentloaded" , this . _on_documentloaded_bound ) ;
137+
138+ this . init ( id , name , container_class , html , default_handler ) ;
139+ } ;
140+
141+ cls . ResourceTestView . prototype = ViewBase ;
0 commit comments