1jQuery('#plugin_move__progress').each(function () {
2    var $this = jQuery(this);
3
4    // initialize the progress bar
5    var $progressbar = $this.find('.progress');
6    $progressbar.html('');
7    $progressbar.progressbar({
8        value: $progressbar.data('progress')
9    });
10
11    /**
12     * Set visibility of buttons according to current error state
13     *
14     * @param isError
15     */
16    var setButtons = function(isError) {
17        $this.find('.ctlfrm-start').addClass('hide');
18
19        if(isError) {
20            $this.find('.ctlfrm-skip').removeClass('hide');
21            $this.find('.ctlfrm-retry').removeClass('hide');
22            $this.find('.ctlfrm-continue').addClass('hide');
23        }else {
24            $this.find('.ctlfrm-skip').addClass('hide');
25            $this.find('.ctlfrm-retry').addClass('hide');
26            $this.find('.ctlfrm-continue').addClass('hide');
27        }
28    };
29
30    /**
31     * Execute the next steps
32     *
33     * @param {bool} skip should an error be skipped?
34     */
35    var nextStep = function(skip) {
36        // clear error output
37        $this.find('.output').html('');
38
39        $this.find('.controls img').removeClass('hide');
40        setButtons(false);
41
42        // execute AJAX
43        jQuery.post(
44            DOKU_BASE + 'lib/exe/ajax.php',
45            {
46                call: 'plugin_move_progress',
47                skip: skip
48            },
49            function (data) {
50                $progressbar.progressbar('option', 'value', data.progress);
51                $this.find('.controls img').addClass('hide');
52
53                if (data.error) {
54                    $this.find('.output').html('<p><div class="error">' + data.error + '</div></p>');
55                    setButtons(true);
56                } else if (data.complete) {
57                    $progressbar.progressbar('option', 'value', 100);
58                    // redirect to start page
59                    alert(LANG.plugins.move.complete);
60                    window.location.href = DOKU_BASE;
61                } else {
62                    // do it again
63                    nextStep(skip);
64                }
65            }
66        );
67    };
68
69
70
71    // attach AJAX actions to buttons
72    $this.find('.ctl-continue').click(function (e) {
73        e.preventDefault();
74
75        // move in progress, no more preview
76        jQuery('#plugin_move__preview').remove();
77
78        // should the next error be skipped?
79        var skip = e.target.form.skip.value;
80
81        // step on it
82        nextStep(skip);
83    });
84
85});
86
87
88// hide preview list on namespace move
89jQuery('#plugin_move__preview').each(function () {
90    var $this = jQuery(this);
91    $this.find('ul').hide();
92    $this.find('span')
93        .click(function () {
94            $this.find('ul').dw_toggle();
95            $this.find('span').toggleClass('closed');
96        })
97        .addClass('closed');
98});
99