~launchpad-pqm/launchpad/devel

10293.2.9 by Edwin Grubbs
Addressed reviewer comments.
1
/* Copyright 2010 Canonical Ltd.  This software is licensed under the
10293.2.1 by Edwin Grubbs
Fixed registry js module names.
2
 * GNU Affero General Public License version 3 (see the file LICENSE).
3
 *
4
 * Dynamically add milestones to an HTML table.
5
 *
10785.1.2 by Brad Crittenden
Move registry JS to lp.registry namespace
6
 * @module Y.lp.registry.milestonetable
10293.2.1 by Edwin Grubbs
Fixed registry js module names.
7
 * @requires node, io-base, substitute, lazr.anim
8
 */
10785.1.2 by Brad Crittenden
Move registry JS to lp.registry namespace
9
YUI.add('lp.registry.milestonetable', function(Y) {
10
    Y.log('loading lp.registry.milestonetable');
11
    var module = Y.namespace('lp.registry.milestonetable');
8602.1.10 by Curtis Hovey
Added unit tests for milestone-table js.
12
8690.5.2 by Curtis Hovey
Added documentation. Extracted JS test CSS rules to a shared file.
13
    // get_milestone_row() needs these when it is called. Other methods
14
    // should get this information passed as an argument.
10293.2.1 by Edwin Grubbs
Fixed registry js module names.
15
    module._milestone_row_uri_template = null;
16
    module._tbody = null;
8602.1.10 by Curtis Hovey
Added unit tests for milestone-table js.
17
10293.2.1 by Edwin Grubbs
Fixed registry js module names.
18
    module._prepend_node = function(parent_node, child_node) {
8690.5.2 by Curtis Hovey
Added documentation. Extracted JS test CSS rules to a shared file.
19
        // Add the child_node to the parent_node as the first item.
8602.1.6 by Curtis Hovey
Completed most of the work to create and add a milestone the project series page via AJAX.
20
        var children = parent_node.get('children');
9942.4.1 by Curtis Hovey
Restore the milestone table on the series +index. Fixed the JS error. The test is
21
        if (children === null) {
8602.1.6 by Curtis Hovey
Completed most of the work to create and add a milestone the project series page via AJAX.
22
            parent_node.appendChild(child_node);
23
        } else {
24
            parent_node.insertBefore(child_node, children.item(0));
8602.1.10 by Curtis Hovey
Added unit tests for milestone-table js.
25
            }
26
        };
27
10293.2.1 by Edwin Grubbs
Fixed registry js module names.
28
    module._ensure_table_is_seen = function(tbody) {
8690.5.2 by Curtis Hovey
Added documentation. Extracted JS test CSS rules to a shared file.
29
        // Remove the 'unseen' class from the table to ensure it is visible.
8602.1.10 by Curtis Hovey
Added unit tests for milestone-table js.
30
        table = tbody.ancestor();
31
        table.removeClass('unseen');
32
        };
33
10293.2.1 by Edwin Grubbs
Fixed registry js module names.
34
    module._clear_add_handlers = function(data) {
8690.5.2 by Curtis Hovey
Added documentation. Extracted JS test CSS rules to a shared file.
35
        // Detach the callback and errorback functions from the Y.io events.
8690.5.4 by Curtis Hovey
Updated comments about detaching callbacks.
36
        // The data has been used. If they are not detached, there will be
37
        // multiple adds for each use of the Create milestone link.
8602.1.10 by Curtis Hovey
Added unit tests for milestone-table js.
38
        data.success_handle.detach();
39
        data.failure_handle.detach();
40
        };
41
10293.2.1 by Edwin Grubbs
Fixed registry js module names.
42
    module._on_add_success = function(id, response, data) {
8690.5.2 by Curtis Hovey
Added documentation. Extracted JS test CSS rules to a shared file.
43
        // Add the milestone to the milestone table on Y.io success.
8602.1.6 by Curtis Hovey
Completed most of the work to create and add a milestone the project series page via AJAX.
44
        var row = Y.Node.create(Y.Lang.trim(response.responseText));
10293.2.1 by Edwin Grubbs
Fixed registry js module names.
45
        module._ensure_table_is_seen(data.tbody);
46
        module._prepend_node(data.tbody, row);
8602.1.6 by Curtis Hovey
Completed most of the work to create and add a milestone the project series page via AJAX.
47
        Y.lazr.anim.green_flash({node: row}).run();
10293.2.1 by Edwin Grubbs
Fixed registry js module names.
48
        module._clear_add_handlers(data);
8602.1.10 by Curtis Hovey
Added unit tests for milestone-table js.
49
        };
8602.1.6 by Curtis Hovey
Completed most of the work to create and add a milestone the project series page via AJAX.
50
10293.2.1 by Edwin Grubbs
Fixed registry js module names.
51
    module._on_add_failure = function(id, response, data) {
8690.5.2 by Curtis Hovey
Added documentation. Extracted JS test CSS rules to a shared file.
52
        // Add the failure message to the milestone table on Y.io failure.
8602.1.6 by Curtis Hovey
Completed most of the work to create and add a milestone the project series page via AJAX.
53
        var row = Y.Node.create(Y.substitute(
54
            '<tr><td colspan="0">' +
55
            'Could not retrieve milestone {name}</td></tr>', data));
10293.2.1 by Edwin Grubbs
Fixed registry js module names.
56
        module._ensure_table_is_seen(data.tbody);
57
        module._prepend_node(data.tbody, row);
8602.1.6 by Curtis Hovey
Completed most of the work to create and add a milestone the project series page via AJAX.
58
        Y.lazr.anim.red_flash({node: row}).run();
10293.2.1 by Edwin Grubbs
Fixed registry js module names.
59
        module._clear_add_handlers(data);
8602.1.10 by Curtis Hovey
Added unit tests for milestone-table js.
60
        };
8602.1.6 by Curtis Hovey
Completed most of the work to create and add a milestone the project series page via AJAX.
61
10293.2.1 by Edwin Grubbs
Fixed registry js module names.
62
    module._setup_milestone_event_data = function(parameters, tbody) {
8690.5.2 by Curtis Hovey
Added documentation. Extracted JS test CSS rules to a shared file.
63
        // Attach the callback to the Y.io event and return their data
8602.1.6 by Curtis Hovey
Completed most of the work to create and add a milestone the project series page via AJAX.
64
        var data = {
65
            name: parameters.name,
8602.1.10 by Curtis Hovey
Added unit tests for milestone-table js.
66
            tbody: tbody
8602.1.6 by Curtis Hovey
Completed most of the work to create and add a milestone the project series page via AJAX.
67
            };
68
        data.success_handle = Y.on(
10293.2.1 by Edwin Grubbs
Fixed registry js module names.
69
            'io:success', module._on_add_success, this, data);
8602.1.6 by Curtis Hovey
Completed most of the work to create and add a milestone the project series page via AJAX.
70
        data.failure_handle = Y.on(
10293.2.1 by Edwin Grubbs
Fixed registry js module names.
71
            'io:failure', module._on_add_failure, this, data);
8602.1.10 by Curtis Hovey
Added unit tests for milestone-table js.
72
        return data;
73
        };
74
8690.5.2 by Curtis Hovey
Added documentation. Extracted JS test CSS rules to a shared file.
75
    /**
76
      * The milestoneoverlay next_step to add the milestone to the page.
77
      *
78
      * This is the callback passed as 'next_step' in milestoneoverlay config.
79
      *
80
      * @method get_milestone_row
81
      * @param {Object} parameters Object literal of config name/value pairs.
82
      *     The form parameters that were submitted to create the milestone.
83
      */
10293.2.1 by Edwin Grubbs
Fixed registry js module names.
84
    module.get_milestone_row = function(parameters) {
85
        module._setup_milestone_event_data(parameters, module._tbody);
8602.1.10 by Curtis Hovey
Added unit tests for milestone-table js.
86
        var milestone_row_uri = Y.substitute(
10293.2.1 by Edwin Grubbs
Fixed registry js module names.
87
            module._milestone_row_uri_template, parameters);
8602.1.6 by Curtis Hovey
Completed most of the work to create and add a milestone the project series page via AJAX.
88
        Y.io(milestone_row_uri);
8602.1.10 by Curtis Hovey
Added unit tests for milestone-table js.
89
        };
8602.1.6 by Curtis Hovey
Completed most of the work to create and add a milestone the project series page via AJAX.
90
8690.5.2 by Curtis Hovey
Added documentation. Extracted JS test CSS rules to a shared file.
91
    /**
92
      * Setup the URL to get the milestone and the table it will be added too.
93
      *
10293.2.7 by Edwin Grubbs
Added milestonetable.js to base-layout-macros.pt.
94
      * @method setup
8690.5.2 by Curtis Hovey
Added documentation. Extracted JS test CSS rules to a shared file.
95
      * @param {Object} parameters Object literal of config name/value pairs.
96
      *     config.milestone_row_uri_template is the Y.substitute template
97
      *         that is used to create the URL to get the milestone row.
98
      *     config.milestone_rows_id is the id the the tbody that the
99
      *         milestone row will be added too.
100
      */
10293.2.1 by Edwin Grubbs
Fixed registry js module names.
101
    module.setup =  function(config) {
8602.1.6 by Curtis Hovey
Completed most of the work to create and add a milestone the project series page via AJAX.
102
        if (config === undefined) {
103
            throw new Error(
104
                "Missing setup config for milestonetable.");
8602.1.10 by Curtis Hovey
Added unit tests for milestone-table js.
105
            }
8602.1.6 by Curtis Hovey
Completed most of the work to create and add a milestone the project series page via AJAX.
106
        if (config.milestone_row_uri_template === undefined ||
107
            config.milestone_rows_id === undefined ) {
108
            throw new Error(
8602.1.10 by Curtis Hovey
Added unit tests for milestone-table js.
109
                "Undefined properties in setup config for milestonetable.");
110
            }
10293.2.1 by Edwin Grubbs
Fixed registry js module names.
111
        module._milestone_row_uri_template = config.milestone_row_uri_template;
112
        module._tbody = Y.one(config.milestone_rows_id);
113
        if (module._tbody === null) {
8602.1.10 by Curtis Hovey
Added unit tests for milestone-table js.
114
            throw new Error(
115
                Y.substitute("'{milestone_rows_id}' not in page.", config));
116
            }
117
        };
8602.1.6 by Curtis Hovey
Completed most of the work to create and add a milestone the project series page via AJAX.
118
9929.1.1 by Guilherme Salgado
merge fix from other branch, which was based on db-devel
119
}, "0.1", {"requires": [
120
    "node", "io-base", "substitute", "lazr.anim"
8602.1.6 by Curtis Hovey
Completed most of the work to create and add a milestone the project series page via AJAX.
121
    ]});