@@ -6,33 +6,58 @@ jQuery(function () {
66 var $progress = jQuery ( '#sync__progress' ) . progressbar ( { value : false } ) ;
77 var $progress_label = $progress . find ( '.label' ) ;
88
9-
9+ /**
10+ * Show the table of items to sync
11+ *
12+ * @param {object } data
13+ */
1014 function displayTable ( data ) {
1115 console . log ( data ) ;
1216
1317 SYNC_DATA . times = data . times ;
1418
15- if ( data . count === 0 ) {
16- $output . append ( '<p>No data to sync</p>' ) ;
17- $output . append ( finishbutton ( ) ) ;
19+ if ( data . count === 0 ) {
20+ log ( LANG . plugins . sync . insync ) ;
21+ finishbutton ( ) ;
1822 return ;
1923 }
2024
2125 var $table = jQuery ( '<table>' ) ;
26+ $table . append ( headers ( ) ) ;
2227 jQuery . each ( data . list , function ( type , items ) {
2328 jQuery . each ( items , function ( id , item ) {
2429 $table . append ( tr ( type , id , item ) ) ;
2530 } ) ;
2631 } ) ;
2732 $output . append ( $table ) ;
2833
29- var $button = jQuery ( '<button>sync</button> ' ) ;
34+ var $button = jQuery ( '<button>' ) ;
3035 $button . click ( beginsync ) ;
36+ $button . text ( LANG . plugins . sync . btn_start ) ;
3137 $output . append ( $button ) ;
3238
3339 $progress . hide ( ) ;
3440 }
3541
42+ function headers ( ) {
43+ var $tr = jQuery ( '<tr>' ) ;
44+
45+ [ 'file' , 'local' , 'dir' , 'remote' , 'diff' ] . map ( function ( l ) {
46+ var $th = jQuery ( '<th>' ) ;
47+ $th . addClass ( l ) ;
48+ $th . text ( LANG . plugins . sync [ l ] ) ;
49+ $tr . append ( $th ) ;
50+ } ) ;
51+ return $tr ;
52+ }
53+
54+ /**
55+ * Get one table row for the given item
56+ *
57+ * @param {int } type
58+ * @param {string } id
59+ * @param {object } item
60+ */
3661 function tr ( type , id , item ) {
3762 var $tr = jQuery ( '<tr>' ) ;
3863 $tr . html (
@@ -63,6 +88,11 @@ jQuery(function () {
6388 return $tr ;
6489 }
6590
91+ /**
92+ * Get the direction buttons for the given Item
93+ *
94+ * @param {object } item
95+ */
6696 function dir ( item ) {
6797 row ++ ;
6898
@@ -111,6 +141,9 @@ jQuery(function () {
111141 return $html ;
112142 }
113143
144+ /**
145+ * Start the sync process
146+ */
114147 function beginsync ( ) {
115148 SYNC_DATA . items = [ ] ;
116149
@@ -130,20 +163,25 @@ jQuery(function () {
130163 $progress . progressbar ( 'option' , 'max' , SYNC_DATA . items . length ) ;
131164 $progress . show ( ) ;
132165
133- $output . append ( '<p>Syncing ' + SYNC_DATA . items . length + ' files</p>' ) ; // FIXME localize
134-
166+ log ( LANG . plugins . sync . tosync . replace ( / % d / , SYNC_DATA . items . length ) ) ;
135167 sync ( ) ;
136168 }
137169
170+ /**
171+ * Hide the progressbar and output a button for ending the sync
172+ */
138173 function finishbutton ( ) {
139174 $progress . hide ( ) ;
140175 var link = document . createElement ( 'a' ) ;
141176 link . href = DOKU_BASE + '?do=admin&page=sync' ;
142- link . text = 'Okay' ; // FIXME localize
177+ link . text = LANG . plugins . sync . btn_done ;
143178 link . className = 'button' ;
144- return link ;
179+ $output . append ( link ) ;
145180 }
146181
182+ /**
183+ * Finalize the sync process
184+ */
147185 function endsync ( ) {
148186 jQuery . ajax (
149187 DOKU_BASE + 'lib/exe/ajax.php' ,
@@ -155,26 +193,28 @@ jQuery(function () {
155193 ltime : SYNC_DATA . times . ltime ,
156194 rtime : SYNC_DATA . times . rtime
157195 } ,
158- complete : function ( ) {
159- $output . append ( finishbutton ( ) ) ;
160- } ,
196+ complete : finishbutton ( ) ,
161197 error : error
162198 }
163199 ) ;
164200 }
165201
202+ /**
203+ * Sync the next file from the sync list
204+ */
166205 function sync ( ) {
167206 var cur = $progress . progressbar ( 'option' , 'max' ) - SYNC_DATA . items . length ;
168207 $progress . progressbar ( 'option' , 'value' , cur ) ;
169- $progress_label . text = '' ;
208+ $progress_label . text ( '' ) ;
170209
171210 var item = SYNC_DATA . items . pop ( ) ;
172211 if ( ! item ) {
212+ log ( LANG . plugins . sync . syncdone ) ;
173213 endsync ( ) ;
174214 return ;
175215 }
176216
177- $progress_label . text = item [ 0 ] ;
217+ $progress_label . text ( item [ 0 ] ) ;
178218 jQuery . ajax (
179219 DOKU_BASE + 'lib/exe/ajax.php' ,
180220 {
@@ -192,14 +232,30 @@ jQuery(function () {
192232 ) ;
193233 }
194234
195-
196- function error ( data ) {
235+ /**
236+ * Add the given error to the output
237+ *
238+ * @param {string } error
239+ */
240+ function error ( error ) {
197241 var $err = jQuery ( '<div class="error">' ) ;
198- $err . text ( data ) ;
242+ $err . text ( error ) ;
199243 $output . append ( $err ) ;
200244 }
201245
246+ /**
247+ * Output a given log message
248+ *
249+ * @param {string } log
250+ */
251+ function log ( log ) {
252+ var $p = jQuery ( '<p>' ) ;
253+ $p . text = log ;
254+ $output . append ( $p ) ;
255+ }
256+
202257 // main
258+ $progress_label . text ( LANG . plugins . sync . loading ) ;
203259 jQuery . ajax (
204260 DOKU_BASE + 'lib/exe/ajax.php' ,
205261 {
@@ -211,6 +267,6 @@ jQuery(function () {
211267 success : displayTable ,
212268 error : error
213269 }
214- )
270+ ) ;
215271
216272} ) ;
0 commit comments