source: extensions/AMenuManager/js/amm_randomPictConfig.js @ 14919

Last change on this file since 14919 was 8962, checked in by grum, 13 years ago

release 3.0.0
fix bug:1716, bug:2128, bug:1296, bug:2052, bug:1910, bug:1723, bug:1709, bug:1680, bug:1477, bug:2129
rewrite plugin core, implement ajax interface, optimize JS

  • Property svn:executable set to *
File size: 6.4 KB
Line 
1/**
2 * randomPictConfig
3 *
4 * release 1.0.0
5 */
6function randomPictConfig(opt, keys, token, initValues)
7{
8  var options = {
9          ajaxUrl:'plugins/AMenuManager/amm_ajax.php'
10        },
11      translatedKeys= {
12          g002_setting_randompic_periodicchange_deactivated:'g002_setting_randompic_periodicchange_deactivated',
13          g002_setting_randompic_height_auto:'g002_setting_randompic_height_auto'
14        },
15      properties = {
16          token:token
17        },
18
19
20  /**
21   * submit config
22   */
23  submit = function ()
24    {
25      if(!checkValidity()) return(false);
26
27      displayProcessing(true);
28
29      // build datas
30      var datas = {
31        blockTitles:[],
32        blockHeight:$("#iamm_rp_height_slider").slider('option', 'value'),
33        infosName:$("#iamm_randompicture_showname").inputList('value'),
34        infosComment:$("#iamm_randompicture_showcomment").inputList('value'),
35        freqDelay:$("#iamm_rp_pc_slider").slider('option', 'value')==99?0:$("#iamm_rp_pc_slider").slider('option', 'value'),
36        selectMode:$("#iamm_randompicture_selectedMode").inputRadio('value'),
37        selectCat:$("#iamm_randompicture_selectedCat").categorySelector('value')
38      };
39
40
41
42      list=$('#iamm_randompicture_title').inputText('languagesValues');
43      for(var id in list)
44      {
45        datas.blockTitles.push({id:id, value:list[id]});
46      }
47
48      $.ajax(
49        {
50          type: "POST",
51          url: options.ajaxUrl,
52          async: true,
53          data: { ajaxfct:"admin.randomPict.setConfig", token:properties.token, datas:datas },
54          success:
55            function(msg)
56            {
57              displayProcessing(false);
58
59              returned=msg.split('!');
60
61              if(returned[0]=='OK')
62              {
63                $('#iConfigState')
64                  .html(returned[1])
65                  .removeClass('errors')
66                  .addClass('infos')
67                  .css('display', 'block');
68              }
69              else
70              {
71                $('#iConfigState')
72                  .html(returned[1])
73                  .removeClass('infos')
74                  .addClass('errors')
75                  .css('display', 'block');
76              }
77            }
78        }
79      );
80    },
81
82  /**
83   * check validity of form
84   */
85  checkValidity = function ()
86    {
87      $('.error').removeClass('error');
88      ok=true;
89      $("#iamm_randompicture_selectedCat").categorySelector('isValid', true);
90
91      if($("#iamm_randompicture_selectedMode").inputRadio('value')=='c' &&
92         $("#iamm_randompicture_selectedCat").categorySelector('value').length==0
93        )
94      {
95        ok=false;
96        $("#iamm_randompicture_selectedCat").categorySelector('isValid', false);
97      }
98
99      return(ok);
100    },
101
102  /**
103   * display or hide the processing flower
104   */
105  displayProcessing = function (visible)
106    {
107      if(visible)
108      {
109        $('#iBDProcessing').css("display", "block");
110      }
111      else
112      {
113        $('#iBDProcessing').css("display", "none");
114      }
115    },
116
117  /**
118   * initialize the object and page form
119   */
120  init = function (initValues)
121  {
122    $('#iamm_randompicture_selectedMode').inputRadio(
123      {
124        change:function () { $('#iConfigState').hide(); }
125      }
126    );
127    $('#iamm_randompicture_selectedMode').inputRadio('value', initValues.selectMode);
128
129    $('#iamm_randompicture_selectedCat').categorySelector(
130      {
131        serverUrl:'plugins/GrumPluginClasses/gpc_ajax.php',
132        listMaxWidth:650,
133        listMaxHeight:550,
134        userMode:'public',
135        galleryRoot:false,
136        displayStatus:false,
137        filter:'all',
138        multiple:true,
139        load:
140          function (event)
141          {
142            $(this)
143              .categorySelector('collapse', ':all')
144              .categorySelector('value', initValues.selectCat);
145          },
146        change: function () { $('#iConfigState').hide(); }
147      }
148    );
149
150    $('#iamm_randompicture_showname').inputList(
151      {
152        colsWidth:[300],
153        popupMode:'mouseout',
154        change: function () { $('#iConfigState').hide(); }
155      }
156    ).inputList('value', initValues.infosName);
157    $('#iamm_randompicture_showcomment').inputList(
158      {
159        colsWidth:[300],
160        popupMode:'mouseout',
161        change: function () { $('#iConfigState').hide(); }
162      }
163    ).inputList('value', initValues.infosComment);
164
165
166    $('#islang').inputList(
167      {
168        popupMode:'mouseout',
169        change: function () { $('#iConfigState').hide(); }
170      }
171    );
172
173    $('#iamm_randompicture_title').inputText(
174      {
175        languages:initValues.langs,
176        languagesValues:initValues.blockTitles,
177        currentLanguage:initValues.userLang,
178        languageSelector:'islang',
179        displayChar:50,
180        maxChar:255,
181        change: function () { $('#iConfigState').hide(); }
182      }
183    );
184
185    $('#islang').inputList('value', initValues.userLang);
186
187
188
189    formatDelay(initValues.freqDelay);
190    $("#iamm_rp_pc_slider").slider(
191      {
192        min:0,
193        max:60000,
194        step:50,
195        value:initValues.freqDelay,
196        slide: function(event, ui) { formatDelay(ui.value); },
197        change: function () { $('#iConfigState').hide(); }
198      });
199    $("#iamm_rp_pc_slider a").addClass('gcBgInput');
200
201    formatHeight(initValues.blockHeight);
202    $("#iamm_rp_height_slider").slider(
203      {
204        min:99,
205        max:300,
206        steps:1,
207        value:initValues.blockHeight,
208        slide: function(event, ui) { formatHeight(ui.value); },
209        change: function () { $('#iConfigState').hide(); }
210      });
211    $("#iamm_rp_height_slider a").addClass('gcBgInput');
212  },
213
214  /**
215   * format delay value for display
216   */
217  formatDelay = function(delay)
218  {
219    $("#iamm_randompicture_periodicchange").val(delay);
220    if(delay==0)
221    {
222      $("#iamm_rp_pc_display").html(translatedKeys.g002_setting_randompic_periodicchange_deactivated);
223    }
224    else
225    {
226      $("#iamm_rp_pc_display").html((delay/1000).toFixed(2)+"s");
227    }
228  },
229
230  formatHeight = function(height)
231  {
232    var vheight = (height==99)?0:height;
233
234    $("#iamm_randompicture_height").val(vheight);
235    if(vheight==0)
236    {
237      $("#iamm_rp_height_display").html(translatedKeys.g002_setting_randompic_height_auto);
238    }
239    else
240    {
241      $("#iamm_rp_height_display").html(vheight+"px");
242    }
243  };
244
245
246  $.extend(options, opt);
247  $.extend(translatedKeys, keys);
248
249  this.submit = function () { submit(); };
250
251  init(initValues);
252}
253
254
Note: See TracBrowser for help on using the repository browser.