Dotclear

source: admin/js/_index.js @ 3614:1872eef9be30

Revision 3614:1872eef9be30, 3.7 KB checked in by franck <carnet.franck.paul@…>, 8 years ago (diff)

Dotclear news are now displayed in async way by js (via services.php)

Line 
1$(function() {
2     var f = $('#quick-entry');
3     if (f.length > 0) {
4          if ($.isFunction(jsToolBar)) {
5               var contentTb = new jsToolBar($('#post_content',f)[0]);
6               contentTb.switchMode($('#post_format',f).val());
7          }
8
9          $('input[name=save]',f).click(function() {
10               quickPost(f,-2);
11               return false;
12          });
13
14          if ($('input[name=save-publish]',f).length > 0) {
15               var btn = $('<input type="submit" value="' + $('input[name=save-publish]',f).val() + '" />');
16               $('input[name=save-publish]',f).remove();
17               $('input[name=save]',f).after(btn).after(' ');
18               btn.click(function() {
19                    quickPost(f,1);
20                    return false;
21               });
22          }
23
24          function quickPost(f,status) {
25               if ($.isFunction('jsToolBar') && (contentTb.getMode() == 'wysiwyg')) {
26                    contentTb.syncContents('iframe');
27               }
28
29               var params = {
30                    f: 'quickPost',
31                    xd_check: dotclear.nonce,
32                    post_title: $('#post_title',f).val(),
33                    post_content: $('#post_content',f).val(),
34                    cat_id: $('#cat_id',f).val(),
35                    post_status: status,
36                    post_format: $('#post_format',f).val(),
37                    post_lang: $('#post_lang',f).val(),
38                    new_cat_title: $('#new_cat_title',f).val(),
39                    new_cat_parent: $('#new_cat_parent',f).val()
40               }
41
42               $('p.qinfo',f).remove();
43
44               $.post('services.php',params,function(data) {
45                    if ($('rsp[status=failed]',data).length > 0) {
46                         var msg = '<p class="qinfo"><strong>' + dotclear.msg.error +
47                         '</strong> ' + $('rsp',data).text() + '</p>';
48                    } else {
49                         var msg = '<p class="qinfo">' + dotclear.msg.entry_created +
50                         ' - <a href="post.php?id=' + $('rsp>post',data).attr('id') + '">' +
51                         dotclear.msg.edit_entry + '</a>';
52                         if ($('rsp>post',data).attr('post_status') == 1) {
53                              msg += ' - <a href="' + $('rsp>post',data).attr('post_url') + '">' +
54                              dotclear.msg.view_entry + '</a>';
55                         }
56                         msg += '</p>';
57                         $('#post_title',f).val('');
58                         $('#post_content',f).val('');
59                         $('#post_content',f).change();
60                         if ($.isFunction('jsToolBar') &&  (contentTb.getMode() == 'wysiwyg')) {
61                              contentTb.syncContents('textarea');
62                         }
63                         $('#cat_id',f).val('0');
64                         $('#new_cat_title',f).val('');
65                         $('#new_cat_parent',f).val('0');
66                    }
67
68                    $('fieldset',f).prepend(msg);
69               });
70          }
71          $('#new_cat').toggleWithLegend($('#new_cat').parent().children().not('#new_cat'), {
72               // no cookie on new category as we don't use this every day
73               legend_click: true
74          });
75     }
76
77     // allow to hide quick entry div, and remember choice
78     $('#quick h3').toggleWithLegend($('#quick').children().not('h3'),{
79          legend_click: true,
80          user_pref: 'dcx_quick_entry'
81     });
82
83     // check if core update available
84     var params = {
85          f: 'checkCoreUpdate',
86          xd_check: dotclear.nonce
87     };
88     $.post('services.php',params,function(data) {
89          if ($('rsp[status=failed]',data).length > 0) {
90               // Silently fail as a forced checked my be done with admin update page
91          } else {
92               if ($('rsp>update',data).attr('check') == 1) {
93                    // Something has to be displayed
94                    xml = $('rsp>update',data).attr('ret');
95                    $('#content h2').after(xml);
96               }
97          }
98     });
99
100     // check if some news are available
101     var params = {
102          f: 'checkNewsUpdate',
103          xd_check: dotclear.nonce
104     };
105     $.post('services.php',params,function(data) {
106          if ($('rsp[status=failed]',data).length > 0) {
107               // Silently fail
108          } else {
109               if ($('rsp>news',data).attr('check') == 1) {
110                    // Something has to be displayed
111                    xml = $('rsp>news',data).attr('ret');
112                    if ($('#dashboard-boxes').length == 0) {
113                         // Create the #dashboard-boxes container
114                         $('#dashboard-main').append('<div id="dashboard-boxes"></div>');
115                    }
116                    if ($('#dashboard-boxes div.db-items').length == 0) {
117                         // Create the #dashboard-boxes div.db-items container
118                         $('#dashboard-boxes').prepend('<div class="db-items"></div>');
119                    }
120                    $('#dashboard-boxes div.db-items').prepend(xml);
121               }
122          }
123     });
124});
Note: See TracBrowser for help on using the repository browser.

Sites map