[ Index ]

PHP Cross Reference of MyBB 1.8.38

title

Body

[close]

/jscripts/ -> inline_moderation.js (source)

   1  var inlineModeration = {
   2      init: function()
   3      {
   4          $(function(){
   5              if($("#inlinemoderation_options_selector").length !== 0) {
   6                  $("#inlinemoderation_options_selector").on('change', function() {
   7                      $("#inlinemoderation_options").trigger('submit');
   8                  });
   9  
  10                  $("#inlinemoderation_options").on('submit', function(){
  11                      if($("#inlinemoderation_options_selector").val() == "") {
  12                          $.jGrowl(lang.select_tool, {theme:'jgrowl_error'});
  13                          return false;
  14                      } else if($('input[name^="inlinemod_"]:checked').length === 0) {
  15                          $.jGrowl(lang.selected_nil, {theme:'jgrowl_error'});
  16                          return false;
  17                      }
  18                  });
  19              }
  20          });
  21          
  22          if(!inlineType || !inlineId)
  23          {
  24              return false;
  25          }
  26  
  27          inlineModeration.cookieName = 'inlinemod_'+inlineType+inlineId;
  28          var inputs = $('input');
  29  
  30          if(!inputs.length)
  31          {
  32              return false;
  33          }
  34  
  35          var inlineIds = inlineModeration.getCookie(inlineModeration.cookieName);
  36          var removedIds = inlineModeration.getCookie(inlineModeration.cookieName+'_removed');
  37          var allChecked = true;
  38  
  39          $(inputs).each(function() {
  40              var element = $(this);
  41              if((element.attr('name') != 'allbox') && (element.attr('type') == 'checkbox') && (element.attr('id')) && (element.attr('id').split('_')[0] == 'inlinemod'))
  42              {
  43                  $(element).on('click', inlineModeration.checkItem);
  44              }
  45  
  46              if(element.attr('id'))
  47              {
  48                  var inlineCheck = element.attr('id').split('_');
  49                  var id = inlineCheck[1];
  50  
  51                  if(inlineCheck[0] == 'inlinemod')
  52                  {
  53                      if(inlineIds.indexOf(id) != -1 || (inlineIds.indexOf('ALL') != -1 && removedIds.indexOf(id) == -1))
  54                      {
  55                          element.prop('checked', true);
  56                          var post = element.parents('.post');
  57                          var thread = element.parents('.inline_row');
  58                          var fieldset = element.parents('fieldset');
  59                          if(post.length)
  60                          {
  61                              post.addClass('trow_selected');
  62                          }
  63                          else if(thread.length)
  64                          {
  65                              thread.addClass('trow_selected');
  66                          }
  67                          
  68                          if(fieldset.length)
  69                          {
  70                              fieldset.addClass('inline_selected');
  71                          }
  72  
  73                      }
  74                      else
  75                      {
  76                          element.prop('checked', false);
  77                          var post = element.parents('.post');
  78                          var thread = element.parents('.inline_row');
  79                          if(post.length)
  80                          {
  81                              post.removeClass('trow_selected');
  82                          }
  83                          else if(thread.length)
  84                          {
  85                              thread.removeClass('trow_selected');
  86                          }
  87                      }
  88                      allChecked = false;
  89                  }
  90              }
  91          });
  92  
  93          inlineModeration.updateCookies(inlineIds, removedIds);
  94  
  95          if(inlineIds.indexOf('ALL') != -1 && removedIds.length == 0)
  96          {
  97              var allSelectedRow = $('#allSelectedrow');
  98              if(allSelectedRow)
  99              {
 100                  allSelectedRow.show();
 101              }
 102          }
 103          else if(inlineIds.indexOf('ALL') == -1 && allChecked == true)
 104          {
 105              var selectRow = $('#selectAllrow');
 106              if(selectRow)
 107              {
 108                  selectRow.show();
 109              }
 110          }
 111          return true;
 112      },
 113  
 114      checkItem: function()
 115      {
 116          var element = $(this);
 117  
 118          if(!element || !element.attr('id'))
 119          {
 120              return false;
 121          }
 122  
 123          var inlineCheck = element.attr('id').split('_');
 124          var id = inlineCheck[1];
 125  
 126          if(!id)
 127          {
 128              return false;
 129          }
 130  
 131          var inlineIds = inlineModeration.getCookie(inlineModeration.cookieName);
 132          var removedIds = inlineModeration.getCookie(inlineModeration.cookieName+'_removed');
 133  
 134          if(element.prop('checked') == true)
 135          {
 136              if(inlineIds.indexOf('ALL') == -1)
 137              {
 138                  inlineIds = inlineModeration.addId(inlineIds, id);
 139              }
 140              else
 141              {
 142                  removedIds = inlineModeration.removeId(removedIds, id);
 143                  if(removedIds.length == 0)
 144                  {
 145                      var allSelectedRow = $('#allSelectedrow');
 146                      if(allSelectedRow)
 147                      {
 148                          allSelectedRow.show();
 149                      }
 150                  }
 151              }
 152              var post = element.parents('.post');
 153              var thread = element.parents('.inline_row');
 154              if(post.length)
 155              {
 156                  post.addClass('trow_selected');
 157              }
 158              else if(thread.length)
 159              {
 160                  thread.addClass('trow_selected');
 161              }
 162          }
 163          else
 164          {
 165              if(inlineIds.indexOf('ALL') == -1)
 166              {
 167                  inlineIds = inlineModeration.removeId(inlineIds, id);
 168                  var selectRow = $('#selectAllrow');
 169                  if(selectRow)
 170                  {
 171                      selectRow.hide();
 172                  }
 173              }
 174              else
 175              {
 176                  removedIds = inlineModeration.addId(removedIds, id);
 177                  var allSelectedRow = $('#allSelectedrow');
 178                  if(allSelectedRow)
 179                  {
 180                      allSelectedRow.hide();
 181                  }
 182              }
 183              var post = element.parents('.post');
 184              var thread = element.parents('.inline_row');
 185              if(post.length)
 186              {
 187                  post.removeClass('trow_selected');
 188              }
 189              else if(thread.length)
 190              {
 191                  thread.removeClass('trow_selected');
 192              }
 193          }
 194  
 195          inlineModeration.updateCookies(inlineIds, removedIds);
 196  
 197          return true;
 198      },
 199  
 200      clearChecked: function()
 201      {
 202          $('#selectAllrow').hide();
 203          $('#allSelectedrow').hide();
 204  
 205          var inputs = $('input');
 206  
 207          if(!inputs.length)
 208          {
 209              return false;
 210          }
 211  
 212          $(inputs).each(function() {
 213              var element = $(this);
 214              if(!element.val()) return;
 215              if(element.attr('type') == 'checkbox' && ((element.attr('id') && element.attr('id').split('_')[0] == 'inlinemod') || element.attr('name') == 'allbox'))
 216              {
 217                  element.prop('checked', false);
 218              }
 219          });
 220  
 221          $('.trow_selected').each(function() {
 222              $(this).removeClass('trow_selected');
 223          });
 224  
 225          $('fieldset.inline_selected').each(function() {
 226              $(this).removeClass('inline_selected');
 227          });
 228  
 229          $('#inline_go').val(go_text+' (0)');
 230          Cookie.unset(inlineModeration.cookieName);
 231          Cookie.unset(inlineModeration.cookieName + '_removed');
 232  
 233          return true;
 234      },
 235  
 236      checkAll: function(master)
 237      {
 238          inputs = $('input');
 239          master = $(master);
 240  
 241          if(!inputs.length)
 242          {
 243              return false;
 244          }
 245  
 246          var inlineIds = inlineModeration.getCookie(inlineModeration.cookieName);
 247          var removedIds = inlineModeration.getCookie(inlineModeration.cookieName+'_removed');
 248  
 249          var newIds = new Array();
 250          $(inputs).each(function() {
 251              var element = $(this);
 252              if(!element.val() || !element.attr('id')) return;
 253              inlineCheck = element.attr('id').split('_');
 254              if((element.attr('name') != 'allbox') && (element.attr('type') == 'checkbox') && (inlineCheck[0] == 'inlinemod'))
 255              {
 256                  var id = inlineCheck[1];
 257                  var changed = (element.prop('checked') != master.prop('checked'));
 258  
 259                  var post = element.parents('.post');
 260                  var fieldset = element.parents('fieldset');
 261                  var thread = element.parents('.inline_row');
 262                  if(post.length)
 263                  {
 264                      if(master.prop('checked') == true)
 265                      {
 266                          post.addClass('trow_selected');
 267                      }
 268                      else
 269                      {
 270                          post.removeClass('trow_selected');
 271                      }
 272                  }
 273                  else if(thread.length)
 274                  {
 275                      if(master.prop('checked') == true)
 276                      {
 277                          thread.addClass('trow_selected');
 278                      }
 279                      else
 280                      {
 281                          thread.removeClass('trow_selected');
 282                      }
 283                  }
 284                  
 285                  if(fieldset.length)
 286                  {
 287                      if(master.prop('checked') == true)
 288                      {
 289                          fieldset.addClass('inline_selected');
 290                      }
 291                      else
 292                      {
 293                          fieldset.removeClass('inline_selected');
 294                      }
 295                  }
 296  
 297                  if(changed)
 298                  {
 299                      element.trigger('click');
 300                      
 301                      if(master.prop('checked') == true)
 302                      {
 303                          if(inlineIds.indexOf('ALL') == -1)
 304                          {
 305                              inlineIds = inlineModeration.addId(inlineIds, id);
 306                          }
 307                          else
 308                          {
 309                              removedIds = inlineModeration.removeId(removedIds, id);
 310                          }
 311                      }
 312                      else
 313                      {
 314                          if(inlineIds.indexOf('ALL') == -1)
 315                          {
 316                              inlineIds = inlineModeration.removeId(inlineIds, id);
 317                          }
 318                          else
 319                          {
 320                              removedIds = inlineModeration.addId(removedIds, id);
 321                          }
 322                      }
 323                  }
 324              }
 325          });
 326  
 327          var count = inlineModeration.updateCookies(inlineIds, removedIds);
 328  
 329          if(count < all_text)
 330          {
 331              var selectRow = $('#selectAllrow');
 332              if(selectRow.length)
 333              {
 334                  if(master.prop('checked') == true)
 335                  {
 336                      selectRow.show();
 337                  }
 338                  else
 339                  {
 340                      selectRow.hide();
 341                  }
 342              }
 343          }
 344  
 345          if(inlineIds.indexOf('ALL') == -1 || removedIds.length != 0)
 346          {
 347              $('#allSelectedrow').hide();
 348          }
 349          else if(inlineIds.indexOf('ALL') != -1 && removedIds.length == 0)
 350          {
 351              $('#allSelectedrow').show();
 352          }
 353      },
 354  
 355      selectAll: function()
 356      {
 357          inlineModeration.updateCookies(new Array('ALL'), new Array());
 358  
 359          $('#selectAllrow').hide();
 360          $('#allSelectedrow').show();
 361      },
 362  
 363      getCookie: function(name)
 364      {
 365          var inlineCookie = Cookie.get(name);
 366  
 367          var ids = new Array();
 368          if(inlineCookie)
 369          {
 370              var inlineIds = inlineCookie.split('|');
 371              $.each(inlineIds, function(index, item) {
 372                  if(item != '' && item != null)
 373                  {
 374                      ids.push(item);
 375                  }
 376              });
 377          }
 378          return ids;
 379      },
 380  
 381      setCookie: function(name, array)
 382      {
 383          if(array.length != 0)
 384          {
 385              var data = '|'+array.join('|')+'|';
 386              Cookie.set(name, data, 60 * 60 * 1000);
 387          }
 388          else
 389          {
 390              Cookie.unset(name);
 391          }
 392      },
 393  
 394      updateCookies: function(inlineIds, removedIds)
 395      {
 396          if(inlineIds.indexOf('ALL') != -1)
 397          {
 398              var count = all_text - removedIds.length;
 399          }
 400          else
 401          {
 402              var count = inlineIds.length;
 403          }
 404          if(count < 0)
 405          {
 406              count = 0;
 407          }
 408          $('#inline_go').val(go_text+' ('+count+')');
 409          if(count == 0)
 410          {
 411              inlineModeration.clearChecked();
 412          }
 413          else
 414          {
 415              inlineModeration.setCookie(inlineModeration.cookieName, inlineIds);
 416              inlineModeration.setCookie(inlineModeration.cookieName+'_removed', removedIds);
 417          }
 418          return count;
 419      },
 420  
 421      addId: function(array, id)
 422      {
 423          if(array.indexOf(id) == -1)
 424          {
 425              array.push(id);
 426          }
 427          return array;
 428      },
 429  
 430      removeId: function(array, id)
 431      {
 432          var position = array.indexOf(id);
 433          if(position != -1)
 434          {
 435              array.splice(position, 1);
 436          }
 437          return array;
 438      }
 439  };
 440  
 441  $(inlineModeration.init);


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref