~ya-bo-ng/ubuntu-online-tour/13.10

« back to all changes in this revision

Viewing changes to 13.04/js/softwaresystem.js

  • Committer: Anthony Dillon
  • Date: 2013-10-02 09:35:39 UTC
  • Revision ID: anthony.dillon@canonical.com-20131002093539-ewxr0tx9oi85ppoi
Inishal setup of the 13.10 version of the tour

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* Software Centre System
 
3
*  author: Anthony Dillon
 
4
*/
 
5
 
 
6
function SoftwareSystem($parent){
 
7
        var _this = this;
 
8
        var _parent = $parent;
 
9
        var minified = false;
 
10
        var maximised = false;
 
11
        var _isOpen = false;
 
12
        var currentApp = null;
 
13
        var installedApps = new Array();
 
14
        var thePrice = '';
 
15
        var theName = '';
 
16
        var theSub = '';
 
17
        var theImage = '';
 
18
        var theDescription = '';
 
19
        var theDesctiptionImage = '';
 
20
        
 
21
        this.init = function(){
 
22
                
 
23
                $('#software-centre .loading-bar').hide();
 
24
                $('#software-centre .detailed .price .progress').css('width','0');
 
25
                
 
26
                $('#software-centre .control .close').click(function(){
 
27
                        _this.close();
 
28
                });
 
29
                $('#software-centre  .control .min').click(function(){
 
30
                        _this.min();
 
31
                });
 
32
                
 
33
                $('#software-centre  .control .max').click(function(){
 
34
                        if(maximised){
 
35
                                maximised = false;
 
36
                                $('#software-centre').css('width','800px');
 
37
                                $('#software-centre').css('height','550px');
 
38
                                $('#software-centre').removeClass('fullsize');
 
39
                                _parent.systemSettings.decreaseFullscreen();
 
40
                        }else{
 
41
                                maximised = true;
 
42
                                $('#software-centre').css('width',$(document).width() - 70 + 'px');
 
43
                                $('#software-centre').css('height',$(document).height() - 50 + 'px');
 
44
                                $('#software-centre').addClass('fullsize');
 
45
                                _parent.systemSettings.increaseFullscreen();
 
46
                        }
 
47
                        _this.resize();
 
48
                });
 
49
                
 
50
                $('#software-centre .top-panel .back').bind('click',function(){
 
51
                        if(!$(this).hasClass('disabled')){
 
52
                                $('#software-centre .home').show();
 
53
                                $('#software-centre .detailed').hide();
 
54
                                $(this).addClass('disabled');
 
55
                                $('#software-centre .top-panel .forward').removeClass('disabled');
 
56
                        }
 
57
                });
 
58
                $('#software-centre .top-panel .forward').bind('click',function(){
 
59
                        if(!$(this).hasClass('disabled')){
 
60
                                _this.loadApp();
 
61
                                $(this).addClass('disabled');
 
62
                        }
 
63
                });
 
64
                
 
65
                $('#software-centre .whats-new .app-container div').click(function(){
 
66
                        currentApp = $(this).attr('class');
 
67
                        $('#software-centre .top-panel .forward').addClass('disabled');
 
68
                        _this.loadApp();
 
69
                });
 
70
                this.setupInstall();
 
71
                this.setupTopButtons();
 
72
                this.center();
 
73
        }
 
74
        
 
75
        this.loadApp = function(){
 
76
                var error = false;
 
77
                $('#software-centre .top-panel .back').removeClass('disabled');
 
78
                $('#software-centre .detailed .price .theprice').removeClass('installed');
 
79
                $('#software-centre .detailed .price .button').text(_install_);
 
80
                if(installedApps[currentApp] == true){  _this.installedApp(); }
 
81
                switch(currentApp){
 
82
                                case 'chromium':
 
83
                                        thePrice = _price_free_;
 
84
                                        theName = _chromium_app_;
 
85
                                        theSub = _chromium_sub_;
 
86
                                        theImage = '../img/software-centre/logo-chromium.png';
 
87
                                        theDescription = _chromium_desc_;
 
88
                                        theDesctiptionImage = '../img/software-centre/screenshot-chromium.jpg';
 
89
                                break;
 
90
                                case 'beep':
 
91
                                        thePrice = '$9.99';
 
92
                                        theName = _beep_app_;
 
93
                                        theSub = _beep_sub_;
 
94
                                        theImage = '../img/software-centre/logo-beep.png';
 
95
                                        theDescription = _beep_desc_;
 
96
                                        theDesctiptionImage = '../img/software-centre/screenshot-beep.jpg';
 
97
                                break;
 
98
                                case 'inkscape':
 
99
                                        thePrice = _price_free_;
 
100
                                        theName = _inkscape_app_;
 
101
                                        theSub = _inkscape_sub_;
 
102
                                        theImage = '../img/software-centre/logo-inkscape.png';
 
103
                                        theDescription = _inkscape_desc_;
 
104
                                        theDesctiptionImage = '../img/software-centre/screenshot-inkscape.jpg';
 
105
                                break;
 
106
                                case 'worldofgoo':
 
107
                                        thePrice = '$19.95';
 
108
                                        theName = _world_of_goo_app_;
 
109
                                        theSub = _world_of_goo_sub_;
 
110
                                        theImage = '../img/software-centre/logo-world-of-goo.png';
 
111
                                        theDescription = _world_of_goo_desc_;
 
112
                                        theDesctiptionImage = '../img/software-centre/screenshot-worldofgoo.jpg';
 
113
                                break;
 
114
                                case 'blender':
 
115
                                        thePrice = _price_free_;
 
116
                                        theName = _blender_app_;
 
117
                                        theSub = _blender_sub_;
 
118
                                        theImage = '../img/software-centre/logo-blender.png';
 
119
                                        theDescription = _blender_desc_;
 
120
                                        theDesctiptionImage = '../img/software-centre/screenshot-blender.jpg';
 
121
                                break;
 
122
                                case 'braid':
 
123
                                        thePrice = '$9.99';
 
124
                                        theName = _braid_app_;
 
125
                                        theSub = _braid_sub_;
 
126
                                        theImage = '../img/software-centre/logo-braid.png';
 
127
                                        theDescription = _braid_desc_;
 
128
                                        theDesctiptionImage = '../img/software-centre/screenshot-braid.jpg';
 
129
                                break;
 
130
                                default:
 
131
                                        _parent.errorMessage.open();
 
132
                                        error = true;
 
133
                                        break;  
 
134
                                }
 
135
                        
 
136
                        $('#software-centre .detailed .title h1').text(theName);
 
137
                        $('#software-centre .detailed .title p.subheading').text(theSub);
 
138
                        $('#software-centre .detailed .title img.app-image').attr('src', theImage);
 
139
                        $('#software-centre .detailed .description').html(theDescription);
 
140
                        $('#software-centre .detailed .description-image img').attr('src',theDesctiptionImage);
 
141
                        if($('#software-centre .detailed .price .theprice').hasClass(_installed_)){
 
142
                                $('#software-centre .detailed .price .theprice').text(_installed_);
 
143
                        }else{
 
144
                                $('#software-centre .detailed .price .theprice').text(thePrice);
 
145
                        }
 
146
                        if(!error){
 
147
                                $('#software-centre .home').hide();
 
148
                                $('#software-centre .detailed').show();
 
149
                        }
 
150
        }
 
151
        
 
152
        this.setupInstall = function(){
 
153
                $('#software-centre .detailed .price .button').bind('click',function(){
 
154
                        if(installedApps[currentApp] == true){
 
155
                                _this.removeApp();
 
156
                        }else{
 
157
                                $(this).hide();
 
158
                                $('#software-centre .loading-bar').show();
 
159
                                $('#software-centre .detailed .price .theprice').text(_installing_+'…');
 
160
                                $('#software-centre .loading-bar .progress').animate({
 
161
                                        width: 150
 
162
                                  }, 1500, function() {
 
163
                                        _this.installedApp();
 
164
                                                $('#software-centre .loading-bar').hide();
 
165
                                                $('#software-centre .detailed .price .button').show();
 
166
                                  });
 
167
                                 }
 
168
                });
 
169
        }
 
170
        
 
171
        this.removeApp = function(){
 
172
                $('#software-centre .detailed .price .theprice').text(thePrice);
 
173
                $('#software-centre .detailed .price .theprice').removeClass('installed');
 
174
                $('#software-centre .detailed .price .theprice').css('background-image','none');
 
175
                $('#software-centre .detailed .price .button').text(_install_);
 
176
                _parent.systemOverlay.removeApps(theName);
 
177
                installedApps[currentApp] = false;
 
178
        }
 
179
        
 
180
        this.installedApp = function(){
 
181
                $('#software-centre .detailed .price .theprice').text(_installed_);
 
182
                $('#software-centre .detailed .price .theprice').addClass('installed');
 
183
                $('#software-centre .detailed .price .button').text(_remove_);
 
184
                $('#software-centre .detailed .price .progress').css('width','0');
 
185
                _parent.systemOverlay.totalApps.push({name:theName,image:theImage});
 
186
                installedApps[currentApp] = true;
 
187
        }
 
188
        
 
189
        this.setupTopButtons = function(){
 
190
                $('#software-centre .all-software').bind('click', function(){
 
191
                        $('#software-centre .home').show();
 
192
                        $('#software-centre .detailed').hide();
 
193
                        $('#software-centre .top-panel .back').addClass('disabled');
 
194
                });
 
195
        }
 
196
        
 
197
        this.close = function(){
 
198
                if(_isOpen){
 
199
                        $('#software-centre .home').show();
 
200
                        $('#software-centre .detailed').hide();
 
201
                        if(maximised){ _parent.systemSettings.decreaseFullscreen(); }
 
202
                        $('#software-centre ').hide();
 
203
                        _parent.systemMenu.closeWindow('software');
 
204
                        $('#software-centre ').removeClass('fullsize');
 
205
                        _this.resize();
 
206
                        minified = _isOpen = false;
 
207
                        _this.center();
 
208
                        if($('css3-container').length > 0){
 
209
                        $('#software-centre').prev().css('top', $('#software-centre').css('top'));
 
210
                        $('#software-centre').prev().css('left', $('#software-centre').css('left'));
 
211
                }
 
212
       }
 
213
        }
 
214
        
 
215
        this.min = function(){
 
216
                if(maximised){ _parent.systemSettings.decreaseFullscreen(); }
 
217
                $('#software-centre ').hide();
 
218
                _parent.systemMenu.wiggle('software');
 
219
                minified = true;
 
220
        }
 
221
        
 
222
        this.resize = function(){
 
223
                var containerHeight = $('#software-centre').height() - ($('#software-centre .top-panel').height() + $('#software-centre .control').height() + 6);
 
224
                var appBoxWidth = $('#software-centre').width() - ($('#software-centre .navigation').width() + 50);
 
225
        if(maximised){ containerHeight -= 27; }
 
226
                $('#software-centre .container').css('height',containerHeight);
 
227
                $('#software-centre .container .whats-new').css('width',appBoxWidth);
 
228
        }
 
229
        
 
230
        this.center = function(){
 
231
        var left = ($(document).width() / 2) - ($('#software-centre ').width() / 2);
 
232
                var top = Math.max(24,($(document).height() / 2) - ($('#software-centre ').height() / 2));
 
233
                $('#software-centre ').css('left',left);
 
234
                $('#software-centre ').css('top',top);
 
235
    }
 
236
    
 
237
    this.isMaximised = function(){
 
238
                return maximised;
 
239
        }
 
240
        
 
241
        this.open = function($app){
 
242
                if($app != undefined){ currentApp = $app; this.loadApp(); }
 
243
                this.resize();
 
244
                this.center();
 
245
                $('#software-centre').show();
 
246
                _isOpen = true;
 
247
                _parent.systemMenu.openWindow('software');
 
248
                if($('css3-container').length > 0){
 
249
                $('#software-centre').prev().css('top', $('#software-centre').css('top'));
 
250
                $('#software-centre').prev().css('left', $('#software-centre').css('left'));
 
251
        }
 
252
        }
 
253
}
 
 
b'\\ No newline at end of file'