WebAdmin update PkgConfList to apt system
[enigma2-plugins.git] / webadmin / src / web-data / handler.js
1 var AbstractAdminContentHandler = Class.create(AbstractContentHandler,  {
2         show: function(data){
3                 this.data = data;
4                 adminTemplateEngine.process(this.tpl, data, this.target, this.finished.bind(this));
5         }
6 });
7
8 /**
9  * PkgNavHandler
10  */
11 var ScriptListHandler  = Class.create(AbstractAdminContentHandler, {
12         initialize: function($super, target){
13                 $super('tplScriptList', target);
14                 this.provider = new ScriptListProvider(this.show.bind(this));
15                 this.ajaxload = true;
16         }
17 });
18
19 /**
20  * PkgNavHandler
21  */
22 var PkgConfListHandler  = Class.create(AbstractAdminContentHandler, {
23         initialize: function($super, target){
24                 $super('tplPkgSettings', target);
25                 this.provider = new PkgConfListProvider(this.show.bind(this));
26                 this.ajaxload = true;
27         }
28 });
29
30 /**
31  * PkgListHandler
32  */
33 var PkgListHandler  = Class.create(AbstractAdminContentHandler, {
34         initialize: function($super, target){
35                 $super('tplPkgList', target);
36                 this.provider = new PkgListProvider(this.show.bind(this));
37                 this.ajaxload = true;
38                 this.fakeprovider = new PkgFakeProvider(this.show.bind(this));
39         },
40                                                                    
41         loadPkg: function(sel, needle){
42                 this.provider.setSelection(sel, needle);
43                 if (this.provider.packages.length != 0) {
44                         this.requestStarted();
45                         this.fakeprovider.setList(this.provider.getSelected());
46                         this.fakeprovider.load();
47                 }
48                 else
49                         this.load();
50                 
51         },
52                                                                    
53         loadAll: function(){
54                 this.loadPkg(this.provider.ALL);
55         },
56                                                                    
57         loadUpgradable: function(){
58                 this.loadPkg(this.provider.UPGRADE);
59         },
60                                                                    
61         loadInstalled: function(){
62                 this.loadPkg(this.provider.INST);
63         },
64
65         loadFilter: function(needle){
66                 this.loadPkg(this.provider.SEARCH, needle);
67         }
68 });
69
70 /**
71  * PkgNavHandler
72  */
73 var PkgNavHandler = Class.create(AbstractAdminContentHandler,{
74         initialize: function($super, target){
75                 $super('tplNavPkgs', target);
76         },
77
78         load: function(){
79                 data = {};
80                 core.setAjaxLoad('navContent');
81                 this.show(data);
82         }
83 });
84
85 /**
86  * SwitchFeedHandler
87  * 
88  */
89 var SwitchFeedHandler  = Class.create(AbstractAdminContentHandler, {
90         initialize: function(){
91                 this.provider = new SimpleRequestProvider();
92         },
93                                                                           
94         load: function(url, parms){
95                 this.provider.simpleResultQuery(
96                                 url,
97                                 parms,
98                                 this.simpleResultCallback.bind(this)
99                         );
100         },
101
102         showSimpleResult: function(result){
103                 id = result.getStateText();
104                 element = document.getElementById(id.replace('.off','') + "-pic");
105                 hiddenInput  = document.getElementById(id.replace('.off','') + "-name");
106                 if (result.getState()) {
107                         if (id.endsWith('.list')) {
108                                 element.alt='disable';
109                                 element.src = '/web-data/img/minus.png';
110                                 var title = 'enable ' + id;
111                                 element.up('.sPkgConfFeedsLink').title='disable ' + id;
112                                 
113                         }       
114                         else {
115                                 element.alt='enable';
116                                 element.src = '/web-data/img/plus.png';
117                                 var title = 'enable ' + id.replace('.off','');
118                                 element.up('.sPkgConfFeedsLink').title='enable ' + id.replace('.off','');
119                         }
120                         hiddenInput.value=id;
121                 }
122                 else {
123                         alert(id);
124                 };
125         },
126 });
127
128 /**
129  * MemoryHandler
130  * 
131  */
132
133 var MemoryHandler  = Class.create(AbstractAdminContentHandler, {
134         initialize: function(){
135                 this.provider = new MemoryProvider(this.show.bind(this));
136         },
137                                                                           
138         load: function(url, parms){
139                 this.provider.simpleResultQuery(
140                                 url,
141                                 parms,
142                                 this.simpleResultCallback.bind(this)
143                         );
144         },
145
146         getMem: function(){
147                 this.load('/webadmin/web/getmemory');
148         },
149
150         showSimpleResult: function(result){
151                 str = result.getStateText();
152                 if (result.getState()) {
153                         document.getElementById('memContent').innerHTML=result.getStateText() + " MB free";
154                 }
155                 else {
156                         alert(str);
157                 };
158         },
159 });
160
161 /**
162  * SimpleWebAdminPageHandler
163  * 
164  */
165
166 var templateEngine2 = new TemplateEngine('/webadmin/tpl/');
167
168 var SimpleWebAdminPageHandler = Class.create(AbstractContentHandler,{
169         initialize: function($super, target){
170                 $super(null, target);
171         },
172
173         show: function(tpl, data){
174                 templateEngine2.process(tpl, data, this.target, this.finished.bind(this));
175         }
176 });