OSDN Git Service

Improved the method of opening a dialog.
[mtpm/PluginManager.git] / tmpl / pm_package_list.tmpl
1 <mt:setvarblock name="page_title"><__trans phrase="Plugin Manager"> - <__trans phrase="Add/Remove Plugin" /></mt:setvarblock>
2
3 <mt:setvarblock name="system_msg">
4     <div id="msg-container">
5     <mt:if name="updated">
6                 <mtapp:statusmsg
7                         id="updated"
8                         class="success"
9                 >
10                         <__trans phrase="Package list has been updated.">
11                 </mtapp:statusmsg>
12         </mt:if>
13         </div>
14 </mt:setvarblock>
15
16 <mt:setvarblock name="related_content">
17         <mt:include name="include/pm_menus.tmpl">
18 </mt:setvarblock>
19
20 <mt:setvarblock name="html_head" append="1">
21 <script type="text/javascript">
22 jQuery.noConflict();
23 jQuery(function() {
24         $ = jQuery;
25         var upgrade = null;
26         var upgrade_status = {};
27         var ftp_password = null;
28
29         function process(task, callback) {
30                 var finish = true;
31                 $.each(task, function() {
32                         var t = this;
33                         if (! t.process) {
34                                 t.process = 'not_yet';
35                         }
36                         if (! finish || t.process == 'done') {
37                                 return;
38                         }
39
40                         $(t.list_item).
41                                 removeClass('not_yet').
42                                 addClass('doing');
43                         t.process = 'doing';
44
45                         if (finish && t.tasks) {
46                                 process(t.tasks, function() {
47                                         $(t.list_item).removeClass('doing').addClass('done');
48                                         t.process = 'done';
49                                         process(task, callback);
50                                 });
51                         }
52
53                         if (finish && t.action) {
54                                 if (ftp_password) {
55                                         t.action += '&ftp_password=' + ftp_password;
56                                 }
57
58                                 $.get(t.action, function(data) {
59                                         var ret = eval('(' + data + ')');
60                                         if (! ret.error) {
61                                                 $(t.list_item).removeClass('doing').addClass('done');
62                                                 t.process = 'done';
63                                                 upgrade_status = ret;
64                                                 process(task, callback);
65                                         }
66                                         else {
67                                                 alert(ret.error);
68                                         }
69                                 });
70                         }
71
72                         finish = false;
73                 });
74
75                 if (finish && callback) {
76                         callback();
77                 }
78         }
79
80         $('#do_upgrade, #do_remove').click(function(ev) {
81                 ev.preventDefault();
82                 ev.stopPropagation();
83
84                 var command = this.id;
85                 if (command == 'do_remove') {
86                         var confirmed = window.confirm('<__trans phrase="Are you sure you want to remove the selected plugin?" />');
87                         if (! confirmed) {
88                                 return false;
89                         }
90                 }
91
92                 if (<mt:Var name="writable" /> == 1) {
93                         $('#' + this.id).trigger('process');
94                         return false;
95                 }
96
97                 jQuery.fn.mtDialog.open(
98                         ScriptURI + '?' + '__mode=pluginmanager&' +
99                         'op=ftp_prompt&blog_id=0&id=' + this.id
100                 );
101         }).
102         bind('process', function(ev, ftp_pass) {
103                 var command = this.id;
104
105                 var param = {
106                         packages: []
107                 };
108                 var form = $('#do_upgrade_form');
109                 form.find('input[name="packages"]:checked').each(function(m) {
110                         param.packages.push(this.value);
111                         if (command == 'do_upgrade') {
112                                 param[this.value] = form.
113                                         find('input[name="' + this.value + '"]').
114                                         val();
115                         }
116                 });
117                 if (ftp_pass) {
118                         ftp_password = param['ftp_password'] = ftp_pass;
119                 }
120
121                 //$('#package_list').hide();
122                 $('#package_list').remove();
123                 $('#upgrade_progress').show();
124
125                 $.get('<mt:var name="link_upgrade">', param, function(data) {
126                         $('#upgrade_progress_loading').hide();
127
128                         upgrade = eval('(' + data + ')');
129                         var ul0 = document.createElement('ul');
130                         $.each(upgrade.tasks, function() {
131                                 var li = document.createElement('li');
132                                 li.appendChild(document.createTextNode(this.name));
133                                 $(li).addClass('not_yet');
134                                 this.list_item = li;
135
136                                 var ul = document.createElement('ul');
137                                 li.appendChild(ul);
138
139                                 $.each(this.tasks, function() {
140                                         var li = document.createElement('li');
141
142                                         li.innerHTML = this.name;
143                                         $(li).addClass('not_yet');
144                                         this.list_item = li;
145                                         ul.appendChild(li);
146                                 });
147
148                                 ul0.appendChild(li);
149                                 $('#upgrade_progress_progress').append(ul0);
150                         });
151
152                         var li = document.createElement('li');
153                         li.appendChild(document.createTextNode('<__trans phrase="Complete">'));
154                         $(li).addClass('not_yet');
155                         ul0.appendChild(li);
156
157                         process(upgrade.tasks, function() {
158                                 $(li).addClass('done');
159                                 if (upgrade_status.upgrade_required) {
160                                         $(li).append('<ul><li><a href="' + upgrade.upgrade_script + '" target="_blank"><__trans phrase="Upgrade Now"></a></li></ul>');
161                                 }
162                                 setTimeout(function() {
163                                         if (command == 'do_upgrade') {
164                                                 alert('<__trans phrase="Installation/Upgrade successful." />');
165                                         }
166                                         else {
167                                                 alert('<__trans phrase="Removing successful." />');
168                                         }
169                                 }, 0);
170                         });
171                 });
172                 return false;
173         });
174
175 /*
176         $('#do_close_window').click(function() {
177                 $('#package_list').show();
178                 $('#upgrade_progress').hide();
179
180                 $('#upgrade_progress_progress').empty();
181                 return false;
182         });
183 */
184 });
185 </script>
186 <style type="text/css">
187 #plugin_manager_contents {
188         position: relative;
189 }
190
191 #plugin_manager_contents ul {
192         margin: 0px 0px 0px 20px;
193 }
194
195 #plugin_manager_contents li.not_yet {
196         font-weight: normal;
197         color: #ccc;
198 }
199 #plugin_manager_contents li.doing {
200         font-weight: bold;
201         color: #000;
202 }
203 #plugin_manager_contents li.done {
204         font-weight: normal;
205         color: #000;
206 }
207
208 #upgrade_progress_loading {
209         text-align: center;
210 }
211 </style>
212 </mt:setvarblock>
213
214 <mt:include name="include/header.tmpl">
215
216 <div id="plugin_manager_contents">
217         <div id="package_list">
218                 <mt:include name="include/pm_package_list_table.tmpl">
219         </div>
220         <div id="upgrade_progress" style="display: none">
221                 <div id="upgrade_progress_loading">
222                         <img src="<mt:StaticWebPath />images/loadingAnimation.gif" />
223                 </div>
224                 <div id="upgrade_progress_progress">
225                 </div>
226                 <div id="upgrade_progress_buttons">
227                         <a href="<mt:var name="link_package_list">"><__trans phrase="Back To List"></a>
228                 </div>
229         </div>
230 </div>
231
232 <mt:include name="include/footer.tmpl">