source: extensions/PublicAdmin/template/picture.tpl @ 24879

Last change on this file since 24879 was 24879, checked in by mistic100, 11 years ago

create plugin PublicAdmin
(only photo:name, photo:comment and photo:author are editable for now)

File size: 2.9 KB
Line 
1{combine_css path=$PUBLICADMIN_PATH|cat:'template/style.css'}
2
3{footer_script}{literal}
4(function($){
5    var editable = {
6        'name': {
7            type: 'text',
8            selector: '.browsePath h2'
9        },
10        'comment': {
11            type: 'textarea',
12            selector: '.imageComment'
13        },
14        'author': {
15            type: 'text',
16            selector: '#Author.imageInfo dd'
17        },
18        'date_available': {
19            type: 'date',
20            selector: '#datepost.imageInfo dd'
21        },
22        'date_creation': {
23            type: 'date',
24            selector: '#datecreate.imageInfo dd'
25        }
26    };
27   
28    {/literal}
29    $('#imageHeaderBar').append('<div id=publicAdmin><span class=edit>{'Edit'|translate}</span><span class=save>{'Save'|translate}</span><span class=cancel>{'Cancel'|translate}</span></div>');
30    {literal}
31   
32    $('#publicAdmin .edit').on('click', function() {
33        $(this).hide().siblings().show();
34       
35        $.each(editable, function(name, item) {
36            var $item = $(item.selector);
37         
38            switch (item.type) {
39            case 'text':
40                $item.after('<input type=text class=publicAdmin name='+ name +' value="'+ $item.html() +'">');
41                break;
42               
43            case 'textarea':
44                $item.after('<textarea class=publicAdmin name='+ name +'>'+ $item.html() +'</textarea>');
45                break;
46               
47            default:
48                return true;
49            }
50           
51            $item.hide();
52        });
53    });
54   
55    $('#publicAdmin .save').on('click', function() {
56        var y = new PwgWS('{/literal}{$ROOT_URL}{literal}'),
57            data = {
58                image_id: {/literal}{$current.id}{literal},
59                single_value_mode: 'replace',
60                name: $(editable['name'].selector).next().val(),
61                comment: $(editable['comment'].selector).next().val()
62            };
63           
64          if ($(editable['author'].selector).length) {
65              data.author = $(editable['author'].selector).next().val();
66          }
67           
68        y.callService('pwg.images.setInfo', data, {
69            method: 'POST',
70            onFailure: function(num, text) {alert(num + " " + text); },
71            onSuccess: function(result) {
72                $('#publicAdmin .cancel').trigger('click');
73               
74                $.each(data, function(name, content) {
75                    if (!editable[name]) return true;
76                    $(editable[name].selector).html(content);
77                });
78            }
79        });
80    });
81   
82    $('#publicAdmin .cancel').on('click', function() {
83      $('.publicAdmin').each(function() {
84        $(this).prev().show();
85        $(this).remove();
86      });
87     
88      $(this).siblings().addBack().hide().filter('.edit').show();
89    });
90
91}(jQuery));
92{/literal}{/footer_script}
Note: See TracBrowser for help on using the repository browser.