summaryrefslogtreecommitdiffstats
path: root/install/static/details.js
blob: ee61f0cfeba5e58fd9d601a2b1cf38bad7ca640b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
/*  Authors:
 *    Pavel Zuna <pzuna@redhat.com>
 *    Adam Young <ayoung@redhat.com>
 *    Endi S. Dewata <edewata@redhat.com>
 *
 * Copyright (C) 2010 Red Hat
 * see file 'COPYING' for use and warranty information
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; version 2 only
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

/* IPA Object Details - populating definiton lists from entry data */

/* REQUIRES: ipa.js */

var ipa_details_cache = {};

IPA.is_field_writable = function(rights){
    if (!rights){
        alert('no right');
    }
    return rights.indexOf('w') > -1;
};

function ipa_details_field(spec) {

    spec = spec || {};

    var that = ipa_widget(spec);

    that.create = spec.create || create;
    that.load = spec.load || load;
    that.save = spec.save || save;

    function create(container) {

        var title = that.name;
        var label = '';

        var param_info = ipa_get_param_info(that.entity_name, that.name);
        if (param_info)
            label = param_info['label'];

        if (!label)
            label = that.label;

        $('<dt></dt>', {
            id: that.name,
            title: title,
            html: label + ':'
        }).appendTo(container);
    }

    function load(container, result) {

        var multivalue = false;
        var hint_span = null;
        var dd;

        var dt = $('dt[title='+that.name+']', container);
        if (!dt.length) return;

        var param_info = ipa_get_param_info(that.entity_name, that.name);
        if (param_info) {
            if (param_info['multivalue'] || param_info['class'] == 'List')
                multivalue = true;
            var hint = param_info['hint'];
            if (hint){
                hint_span = $('<span />',{
                    'class': 'attrhint',
                    'html': 'Hint: ' + hint});
            }
        }

        var value = result[that.name];
        var rights = 'rsc';
        if (result.attributelevelrights){
            rights = result.attributelevelrights[this.name] || rights ;
        }
        if (value) {
            dd = ipa_create_first_dd(
                that.name,ipa_create_input(
                    that.entity_name, that.name, value[0],hint_span,rights)
            );
            dt.after(dd);
            var last_dd = dd;
            for (var i = 1; i < value.length; ++i) {
                dd = ipa_create_other_dd(
                    that.name, ipa_create_input(that.entity_name, that.name,
                                                value[i],hint_span,rights)
                );
                last_dd.after(dd);
                last_dd = dd;
            }
            if (multivalue && IPA.is_field_writable(rights) ) {
                dd = ipa_create_other_dd(
                    that.name, _ipa_a_add_template.replace('A', that.name)
                );
                last_dd.after(dd);
            }
        } else {
            if (multivalue  && IPA.is_field_writable(rights)) { 
                dd = ipa_create_first_dd(
                    that.name, _ipa_a_add_template.replace('A', that.name)
                );
                dt.after(dd);
            } else {
                dd = ipa_create_first_dd(
                    that.name, ipa_create_input(
                        that.entity_name, that.name,'',hint_span,rights)
                );
                dt.after(dd);
            }
        }
    }

    function save(container) {
        var values = [];

        var dd = $('dd[title='+that.name+']', container);
        dd.each(function () {
            var input = $('input', $(this));
            if (!input.length) return;

            if (input.is('.strikethrough')) return;

            var value = $.trim(input.val());
            if (!value) value = '';

            values.push(value);
        });

        return values;
    }

    return that;
}

function ipa_details_section(spec){

    spec = spec || {};

    var that = {};

    that.name = spec.name || '';
    that.label = spec.label || '';
    that.template = spec.template;
    that._entity_name = spec.entity_name;

    that.fields = [];
    that.fields_by_name = {};

    that.superior = function(name) {
        var method = that[name];
        return function () {
            return method.apply(that, arguments);
        };
    };

    that.__defineGetter__("entity_name", function(){
        return that._entity_name;
    });

    that.__defineSetter__("entity_name", function(entity_name){
        that._entity_name = entity_name;

        for (var i=0; i<that.fields.length; i++) {
            that.fields[i].entity_name = entity_name;
        }
    });

    that.get_field = function(name) {
        return that.fields_by_name[name];
    };

    that.add_field = function(field) {
        field.entity_name = that.entity_name;
        that.fields.push(field);
        that.fields_by_name[field.name] = field;
    };

    that.create_field = function(spec) {
        var field = ipa_details_field(spec);
        that.add_field(field);
        return field;
    };

    that.create_text = function(spec) {
        var field = ipa_text_widget(spec);
        that.add_field(field);
        return field;
    };

    that.create_radio = function(spec) {
        var field = ipa_radio_widget(spec);
        that.add_field(field);
        return field;
    };

    that.create_textarea = function(spec) {
        var field = ipa_textarea_widget(spec);
        that.add_field(field);
        return field;
    };

    that.create_button = function(spec) {
        var field = ipa_button_widget(spec);
        that.add_field(field);
        return field;
    };

    that.init = function() {
        for (var i=0; i<that.fields.length; i++) {
            var field = that.fields[i];
            field.init();
        }
    };

    that.create = function(container) {

        if (that.template) return;

        var fields = that.fields;
        for (var i = 0; i < fields.length; ++i) {
            var field = fields[i];

            var span = $('<span/>', { 'name': field.name }).appendTo(container);
            field.create(span);
        }
    };

    that.setup = function(container) {

        this.container = container;

        if (that.template) return;

        var fields = that.fields;
        for (var i = 0; i < fields.length; ++i) {
            var field = fields[i];

            var span = $('span[name='+field.name+']', this.container).first();
            field.setup(span);
        }
    };

    that.load = function(result) {

        var fields = that.fields;

        if (that.template) {
            var template = IPA.get_template(that.template);
            this.container.load(
                template,
                function(data, text_status, xhr) {
                    for (var i = 0; i < fields.length; ++i) {
                        var field = fields[i];
                        var span = $('span[name='+field.name+']', this.container).first();
                        field.setup(span);
                        field.load(span, result);
                    }
                }
            );
            return;
        }

        for (var j=0; j<fields.length; j++) {
            var field = fields[j];
            var span = $('span[name='+field.name+']', this.container).first();
            field.load(span, result);
        }
    };

    that.reset = function() {
        for (var i=0; i<that.fields.length; i++) {
            var field = that.fields[i];
            var span = $('span[name='+field.name+']', this.container).first();
            field.reset(span);
        }
    };

    // methods that should be invoked by subclasses
    that.section_create = that.create;
    that.section_setup = that.setup;
    that.section_load = that.load;

    return that;
}

function ipa_details_list_section(spec){

    spec = spec || {};

    var that = ipa_details_section(spec);

    that.create = function(container) {

        // do not call section_create() here

        if (that.template) return;

        var dl = $('<dl/>', {
            'id': that.name,
            'class': 'entryattrs'
        }).appendTo(container);

        var fields = that.fields;
        for (var i = 0; i < fields.length; ++i) {
            var field = fields[i];

            var span = $('<span/>', { 'name': field.name }).appendTo(dl);
            field.create(span);
        }
    };

    /* populate definition lists with the class 'entryattrs' with entry attributes
     *
     * The list has to be specially crafted for this function to work properly:
     * <dt> tags should have the 'title' attribute set to an LDAP attribute name
     * OR to a javascript function name prefixed with 'call_', which will be given
     * the <dt> object and entry_attrs as arguments.
     * Example:
     *   <dl class="entryattrs">
     *     <dt title="givenname">First Name:</dt>
     *     <dt title="call_some_callback">Some Attribute:</dt>
     *   </dl>
     *
     * arguments:
     *   result - 'result' field as returned by ipa *-show commnads
     *                 (basically an associative array with attr:value pairs) */
    that.load = function(result) {
        /* remove all <dd> tags i.e. all attribute values */
        $('dd', that.container).remove();

        /* go through all <dt> tags and pair them with newly created <dd>s */
        that.section_load(result);
    };

    // Deprecated: Used for backward compatibility only.
    function input(spec){
        that.create_field(spec);
        return that;
    }

    that.input = input;

    return that;
}

// Deprecated: Used for backward compatibility only.
function ipa_stanza(spec) {
    return ipa_details_list_section(spec);
}

function ipa_details_facet(spec) {

    spec = spec || {};

    var that = ipa_facet(spec);

    that.is_dirty = spec.is_dirty || ipa_details_is_dirty;
    that.create = spec.create || ipa_details_create;
    that.setup = spec.setup || ipa_details_setup;
    that.load = spec.load || ipa_details_load;
    that.update = spec.update || ipa_details_update;
    that.reset = spec.reset || ipa_details_reset;
    that.display = spec.display || ipa_details_display;

    that.sections = [];
    that.sections_by_name = {};

    that.__defineGetter__("entity_name", function(){
        return that._entity_name;
    });

    that.__defineSetter__("entity_name", function(entity_name){
        that._entity_name = entity_name;

        for (var i=0; i<that.sections.length; i++) {
            that.sections[i].entity_name = entity_name;
        }
    });

    that.get_section = function(name) {
        return that.sections_by_name[name];
    };

    that.add_section = function(section) {
        section.entity_name = that.entity_name;
        that.sections.push(section);
        that.sections_by_name[section.name] = section;
    };

    that.create_section = function(spec) {
        var section = ipa_details_section(spec);
        that.add_section(section);
        return section;
    };

    that.init = function() {
        for (var i=0; i<that.sections.length; i++) {
            var section = that.sections[i];
            section.init();
        }
    };

    return that;
}

function ipa_button(spec) {

    spec = spec || {};

    var button = $('<a/>', {
        'id': spec.id,
        'html': spec.label,
        'class': 'ui-state-default ui-corner-all input_link'
    });

    if (spec.click) button.click(spec.click);
    if (spec.class) button.addClass(spec.class);
    if (spec.icon) button.append('<span class="ui-icon '+spec.icon+'" ></span> ');

    return button;
}

function ipa_details_is_dirty() {
    var pkey = $.bbq.getState(this.entity_name + '-pkey', true) || '';
    return pkey != this.pkey;
}

function ipa_details_create(container)
{
    var facet = this;

    if (!container) {
        alert('ERROR: ipa_details_create: Missing container argument!');
        return;
    }

    var entity_name = container.attr('id');
    container.attr('title', entity_name);


    var details = $('<div/>', {
        'class': 'content'
    }).appendTo(container);

    var buttons = $('<li/>', {
        'class': 'details-buttons'
    }).prependTo($('.action-panel ul'));

    buttons.append(ipa_button({
        'label': 'Reset',
        'icon': 'ui-icon-refresh',
        'class': 'details-reset',
        'click': function() {
            facet.reset(container);
            return false;
        }
    }));

    var pkey_name = IPA.metadata[facet.entity_name].primary_key;

    buttons.append(ipa_button({
        'label': 'Update',
        'icon': 'ui-icon-check',
        'class': 'details-update',
        'click': function() {
            facet.update(container, ipa_details_cache[facet.entity_name][pkey_name][0]);
            return false;
        }
    }));

    details.append('<br/>');
    details.append('<hr/>');

    for (var i = 0; i < facet.sections.length; ++i) {
        var section = facet.sections[i];

        details.append($('<h2/>',{
            click: function(){_h2_on_click(this)},
            html:"&#8722; "+section.label
        }));

        var div = $('<div/>', {
            'id': facet.entity_name+'-'+facet.name+'-'+section.name,
            'class': 'details-section'
        }).appendTo(details);

        section.create(div);

        details.append('<hr/>');
    }
}

function ipa_details_setup(container) {

    var that = this;

    for (var i = 0; i < that.sections.length; ++i) {
        var section = that.sections[i];

        var div = $(
            '#'+that.entity_name+'-'+that.name+'-'+section.name,
            container
        );

        section.setup(div);
    }
}

function ipa_details_load(container) {

    var that = this;
    var entity = IPA.get_entity(that.entity_name);

    that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
    if (!that.pkey && !entity.default_facet) return;

    function on_success(data, text_status, xhr) {
        var result = data.result.result;

        ipa_details_cache[that.entity_name] = $.extend(true, {}, result);
        for (var i = 0; i < that.sections.length; ++i) {
            var section = that.sections[i];
            section.load(result);
        }
    }

    function on_failure(xhr, text_status, error_thrown) {
        var details = $('.details', container).empty();
        details.append('<p>Error: '+error_thrown.name+'</p>');
        details.append('<p>'+error_thrown.title+'</p>');
        details.append('<p>'+error_thrown.message+'</p>');
    }

    var params = [];
    if (that.pkey) params.push(that.pkey);

    ipa_cmd(
        'show', params, {all: true, rights: true}, on_success, on_failure, that.entity_name
    );
}

function ipa_details_update(container, pkey, on_win, on_fail)
{
    var facet = this;
    var entity_name = facet.entity_name;

    function update_on_win(data, text_status, xhr) {
        if (on_win)
            on_win(data, text_status, xhr);
        if (data.error)
            return;

        var result = data.result.result;
        ipa_details_cache[entity_name] = $.extend(true, {}, result);
        facet.display(result);
    }

    function update_on_fail(xhr, text_status, error_thrown) {
        if (on_fail)
            on_fail(xhr, text_status, error_thrown);
    }

    if (!pkey)
        return;

    var values;
    var modlist = {'all': true, 'setattr': [], 'addattr': [], 'rights': true};
    var attrs_wo_option = {};

    for (var i=0; i<facet.sections.length; i++) {
        var section = facet.sections[i];

        var div = $('#'+facet.entity_name+'-'+facet.name+'-'+section.name, container);

        for (var j=0; j<section.fields.length; j++) {
            var field = section.fields[j];

            var span = $('span[name='+field.name+']', div).first();
            values = field.save(span);

            var param_info = ipa_get_param_info(entity_name, field.name);
            if (param_info) {
                if (param_info['primary_key']) continue;
                if (values.length === 1) {
                    modlist[field.name] = values[0];
                }else if (values.length > 1){
                    modlist[field.name] = values;
                } else if (param_info['multivalue']){
                        modlist[field.name] = [];
                }
            } else {
                if (values.length) attrs_wo_option[field.name] = values;
            }
        }
    }

    for (attr in attrs_wo_option) {
        values = attrs_wo_option[attr];
        modlist['setattr'].push(attr + '=' + values[0]);
        for (var i = 1; i < values.length; ++i)
            modlist['addattr'].push(attr + '=' + values[i]);
    }

    ipa_cmd('mod', [pkey], modlist, update_on_win, null, entity_name);
}


/* HTML templates for ipa_details_display() */
var _ipa_a_add_template =
    '<a href="jslink" onclick="return (_ipa_add_on_click(this))" title="A">Add</a>';
var _ipa_span_doc_template = '<span class="attrhint">Hint: D</span>';
var _ipa_span_hint_template = '<span class="attrhint">Hint: D</span>';



function ipa_details_display(result)
{
    var facet = this;

    for (var i=0; i<facet.sections.length; i++) {
        var section = facet.sections[i];
        section.load(result);
    }
}



function ipa_create_first_dd(field_name, content){
    return $('<dd/>', {
        'class': 'first',
        'title': field_name
    }).append(content);
}

function ipa_create_other_dd(field_name, content){
    return $('<dd/>', {
        'class': 'other',
        'title': field_name
    }).append(content);
}

function ipa_insert_first_dd(jobj, content){
    ipa_insert_dd(jobj, content, "first");
}

function ipa_insert_dd(jobj, content, dd_class){
    jobj.after( $('<dd/>',{
        "class": dd_class
    }).append(content))
}



/* mapping of parameter types to handlers used to create inputs */
var _ipa_param_type_2_handler_map = {
    'Str': _ipa_create_text_input,
    'Int': _ipa_create_text_input,
    'Bool': _ipa_create_text_input,
    'List': _ipa_create_text_input
};

/* create an HTML element for displaying/editing an attribute
 * arguments:
 *   attr - LDAP attribute name
 *   value - the attributes value */
function ipa_create_input(entity_name, attr, value,hint,rights)
{
    var input = $("<label>",{html:value.toString()});
    var param_info = ipa_get_param_info(entity_name, attr);
    if (!param_info) {
        /* no information about the param is available, default to text input */
        input = _ipa_create_text_input(attr, value, null,rights);
        if (hint){
            input.after(hint);
        }
    }else if (param_info['primary_key'] ||
              ('no_update' in param_info['flags'])){
        /* check if the param value can be modified */
        /*  THis is currently a no-op, as we use this logic for the
            default case as well */
    }else{
        /* call handler by param class */
        var handler = _ipa_param_type_2_handler_map[param_info['class']];
        if (handler) {
            input = handler(attr, value, param_info,rights);
            if ((param_info['multivalue'] ||
                 param_info['class'] == 'List') &&
                IPA.is_field_writable(rights)){
                input.append( _ipa_create_remove_link(attr, param_info));
            }
            if (hint){
                input.after(hint);
            }
        }
    }
    return input;
}


/* creates a Remove link for deleting attribute values */
function _ipa_create_remove_link(attr, param_info)
{
    if (!param_info)
        return (_ipa_a_remove_template.replace('A', attr));

    /* check if the param is required or of the Password type
     * if it is, then we don't want people to be able to remove it */
    if ((param_info['required']) || (param_info['class'] == 'Password'))
        return ('');

    return $('<a/>',{
        href:"jslink",
        click: function (){return (_ipa_remove_on_click(this))},
        title: attr,
        text: 'Remove'});

}


/* creates a input box for editing a string attribute */
function _ipa_create_text_input(attr, value, param_info, rights)
{

    function calculate_dd_index(jobj){
        var index = 0;
        var dd = jobj.parents('dd').slice(0, 1)[0];
        dd = dd.previousElementSibling;

        while(dd.nodeName.toUpperCase() === 'DD'){
            dd = dd.previousElementSibling;
            index += 1;
            if (index > 100 )
                break;
        }
        return index;
    }

    function validate_input(text, param_info,error_link){
        if(param_info && param_info.pattern){
            var regex = new RegExp( param_info.pattern );
            if (!text.match(regex)) {
                error_link.style.display ="block";
                if ( param_info.pattern_errmsg){
                    error_link.innerHTML =  param_info.pattern_errmsg;
                }
            }else{
                error_link.style.display ="none";
            }
        }
    }

    var span = $("<Span />");
    var input = $("<input/>",{
        type:"text",
        name:attr,
        value:value.toString(),
        keyup: function(){
            var undo_link=this.nextElementSibling;
            undo_link.style.display ="inline";
            var error_link = undo_link.nextElementSibling;

            var text = $(this).val();
            validate_input(text, param_info,error_link);
        }
    }).appendTo(span) ;

    if (!IPA.is_field_writable(rights)){
        input.attr('disabled', 'disabled');
    }

    span.append($("<a/>",{
        html:"undo",
        "class":"ui-state-highlight ui-corner-all",
        style:"display:none",
        click: function(){
            var key = this.previousElementSibling.name;
            var entity_divs = $(this).parents('.entity-container');
            var entry_attrs = ipa_details_cache[entity_divs[0].id];

            index = calculate_dd_index($(this));

            var previous_value = entry_attrs[key] || "";
            if (index >= previous_value.length){
                previous_value = '';
            }else{
                previous_value= previous_value[index];
            }

            this.previousElementSibling.value =  previous_value;
            this.style.display = "none";
            var error_link = this.nextElementSibling;
            validate_input(previous_value, param_info,error_link);
        }
    }));
    span.append($("<span/>",{
        html:"Does not match pattern",
        "class":"ui-state-error ui-corner-all",
        style:"display:none"
    }));
    return span;
}

function ipa_details_reset(container)
{
    var that = this;
    var entity_name = that.entity_name;

    if (ipa_details_cache[entity_name]){
        that.display(ipa_details_cache[entity_name]);
    }

    for (var i=0; i<that.sections.length; i++) {
        var section = that.sections[i];
        section.reset();
    }
}

/* Event handlers */

function _ipa_add_on_click(obj)
{
    var jobj = $(obj);
    var attr = jobj.attr('title');
    var par = jobj.parent();
    var obj_name = jobj.closest('.entity-container').attr('title');

    var param_info = ipa_get_param_info(obj_name, '');
    //TODO rights need to be inherited
    //And used to control  presnece of the add link 
    var input = _ipa_create_text_input(attr, '', param_info, 'rswco');

    par.prepend(input);
    jobj.next('input').focus();
    jobj.remove();
    par.after( ipa_create_other_dd(attr,_ipa_a_add_template.replace('A', attr)));

    return (false);
}




function _ipa_remove_on_click(obj)
{
    var jobj = $(obj);
    var attr = jobj.attr('title');
    var par = jobj.parent();

    var input = par.find('input');

    if (input.is('.strikethrough')){
        input.removeClass('strikethrough');
        jobj.text("Remove");
    }else{
        input.addClass('strikethrough');
        jobj.text("Undo");
    }
    return (false);
}

function _h2_on_click(obj)
{
    var jobj = $(obj);
    var txt = jobj.text().replace(/^\s*/, '');
    if (txt.charCodeAt(0) == 8722) {
        obj.dl = jobj.next().detach();
        jobj.text('+' + txt.substr(1));
    } else {
        if (obj.dl)
            obj.dl.insertAfter(obj);
        jobj.text(
            String.fromCharCode(8722) + txt.substr(1)
        );
    }
}