source: products/quintagroup.referencedatagridfield/branches/plone4/quintagroup/referencedatagridfield/skins/referencedatagridfield/referencedatagridwidget.js @ 2331

Last change on this file since 2331 was 2331, checked in by mylan, 14 years ago

Little clean-up

File size: 2.7 KB
Line 
1// ReferenceDataGridField related functions
2
3dataGridFieldFunctions.addReferenceDataGridRow = function(id) {
4    /* Explitcly add row for given DataGridField,
5           then update row content with reference popup
6           functionality.
7
8           @param id Archetypes field id for the widget
9
10    */
11       
12    // Add row with own DataGridField method
13    this.addRow(id);
14
15    // Find active row and add overlay related processors for active row
16    var active_row = jq("#datagridwidget-tbody-" + id + " tr#datagridwidget-row:last");
17    jq(active_row).prepRefPopup();
18}
19
20dataGridFieldFunctions.addReferenceDataGridRowAfter = function(currnode) {
21    /*
22        Creates a new row before the clicked row with preparation of
23        reference related overlay.
24    */
25       
26    // add row with datagrid original method
27    this.addRowAfter(currnode);
28    // find active row
29    var tbody = jq(currnode).parents("[id^=datagridwidget-tbody-]");
30    var rows = jq("#datagridwidget-row", tbody);
31    var curr_row = jq(currnode).parents("tr#datagridwidget-row");
32    var active_row = rows[rows.index(curr_row)-1];
33    // add overlay related processors for active row
34    jq(active_row).prepRefPopup();
35}
36
37dataGridFieldFunctions.OriginalUpdateOrderIndex = dataGridFieldFunctions.updateOrderIndex;
38dataGridFieldFunctions.updateOrderIndex = function (tbody) {
39    var rows, tr, idx, ov, ov_id, under_idx, new_ov_id
40    // update order index with original method
41    this.OriginalUpdateOrderIndex(tbody);
42    // Update overlay related attributes after rows index updating
43    // for all datagridwidget rows
44    rows = jq("#datagridwidget-row", tbody);
45    for (var i=0; i<rows.length; ++i) {
46        // get working row
47        tr = rows[i];
48        // Update overlay related tags attributes
49        order_tag = jq("input[id^=orderindex__]", tr);
50        idx = order_tag.attr("value");
51        // Update rel attribute for overlay box
52        ov = jq("input.addreference", tr);
53        ov_id = ov.attr("rel");
54        under_idx = ov_id.lastIndexOf("_");
55        base_id = (under_idx >= 0)? ov_id.substring(0, under_idx): "#atrb";
56        new_ov_id = base_id + "_" + idx;
57        ov.attr("rel", new_ov_id);
58        // Update target box id - it must be equal to rel attribute
59        jq("div[id^=atrb_]", tr).attr("id", new_ov_id.substring(1) );
60    }
61   
62}
63
64// Event handlers, used in referencebrowser.js
65
66function triggerTitleClass(e) {
67    var element = jq(e.target);
68    var current = element.attr("value");
69    var initial = element.attr("default_value");
70    if (initial == null || current == null)
71        return;
72
73    if (initial == current) {
74        element.attr("class", "not-changed-title-field");
75    } else {
76        element.attr("class", "changed-title-field")
77    }
78}
79
80function triggerOnFocusStyles(e) {
81    jq(e.target).attr("class",  "changed-title-field")
82}
Note: See TracBrowser for help on using the repository browser.