[ Index ]

PHP Cross Reference of MyBB 1.8.28

title

Body

[close]

/jscripts/ -> usercp.js (source)

   1  var UserCP = {
   2      init: function()
   3      {
   4          $(function()
   5          {
   6              $(document).on('keydown', function(e)
   7              { 
   8                  if (e.keyCode == 27 && $('#buddyselect_container').is(':visible'))
   9                  { 
  10                      $('#buddyselect_container').hide();
  11                  }
  12              });
  13          });
  14      },
  15  
  16      regenBuddySelected: function()
  17      {
  18          var selectedBuddies = [];
  19          $('input[id^=checkbox_]').each(function()
  20          {
  21              if($(this).is(':checked'))
  22              {
  23                  selectedBuddies.push($(this).parent().text().trim());
  24              }
  25          })
  26          $("#buddyselect_buddies").text(selectedBuddies.join(', '));
  27      },
  28  
  29      openBuddySelect: function(field)
  30      {
  31          if(!$("#"+field).length)
  32          {
  33              return false;
  34          }
  35          this.buddy_field = '#'+field;
  36          if($("#buddyselect_container").length)
  37          {
  38              UserCP.buddySelectLoaded();
  39              return false;
  40          }
  41          if(use_xmlhttprequest == 1)
  42          {
  43              $.ajax(
  44              {
  45                  url: 'xmlhttp.php?action=get_buddyselect',
  46                  async: true,
  47                  complete: function (request)
  48                  {
  49                      UserCP.buddySelectLoaded(request);
  50                  }
  51              });
  52          }
  53      },
  54  
  55      buddySelectLoaded: function(request)
  56      {
  57          var buddyselect_container = $("#buddyselect_container");
  58          // Using new copy
  59          if(request)
  60          {
  61              try {
  62                  var json = JSON.parse(request.responseText);
  63                  if(json.hasOwnProperty("errors"))
  64                  {
  65                      $.each(json.errors, function(i, message)
  66                      {
  67                        $.jGrowl(lang.buddylist_error + message, {theme:'jgrowl_error'});
  68                      });
  69                      return false;
  70                  }
  71              } catch (e) {
  72                  if(request.responseText)
  73                  {
  74                      if(buddyselect_container.length)
  75                      {
  76                          buddyselect_container.remove();
  77                      }
  78                      var container = $("<div />");
  79                      container.attr("id", "buddyselect_container").html(request.responseText).hide();
  80                      $("body").append(container);
  81                  }
  82              }
  83          }
  84  
  85          // Center it on the page (this should be in usercp.css)
  86          $("#buddyselect_container").css({"top": "50%", "left": "50%", "position": "fixed", "display": "block", "z-index": "1000", "text-align": "left", "transform": "translate(-50%, -50%)"});
  87          
  88          // Reset all checkboxes initially
  89          $('input[id^=checkbox_]').prop('checked', false);
  90  
  91          var listedBuddies = $(this.buddy_field).select2("data");
  92          $.each(listedBuddies, function()
  93          {
  94              var username = this.text;            
  95              $('input[id^=checkbox_]').each(function()
  96              {
  97                  if($(this).parent().text().trim() == username)
  98                  {
  99                      $(this).prop('checked', true);
 100                  }
 101              });
 102          });
 103  
 104          UserCP.regenBuddySelected();
 105      },
 106  
 107      // Deprecated function since MyBB 1.8.27
 108      selectBuddy: function(uid, username)
 109      {
 110          UserCP.regenBuddySelected();
 111      },
 112  
 113      closeBuddySelect: function(canceled)
 114      {
 115          if(canceled != true)
 116          {
 117              var buddies = $("#buddyselect_buddies").text().split(","), newbuddies = [];
 118              $.each(buddies, function(index, buddy)
 119              {
 120                  buddy = buddy.trim();
 121                  if(buddy !== "")
 122                  {
 123                      newbuddies.push({ id: buddy, text: buddy });
 124                  }
 125              });
 126              $(this.buddy_field).select2("data", newbuddies).select2("focus");
 127          }
 128          $("#buddyselect_container").hide();
 129      },
 130  
 131      addBuddy: function(type)
 132      {
 133          var type_submit = $("#"+type+"_submit");
 134          var type_add_username = $("#"+type+"_add_username");
 135  
 136          if(type_add_username.val().length == 0)
 137          {
 138              return false;
 139          }
 140          if(use_xmlhttprequest != 1)
 141          {
 142              return true;
 143          }
 144  
 145          var old_value = type_submit.val();
 146  
 147          type_add_username.attr("disabled", true);
 148          type_submit.attr("disabled", true);
 149  
 150          if(type == "ignored")
 151          {
 152              type_submit.attr("value", lang.adding_ignored);
 153              var list = "ignore";
 154          }
 155          else
 156          {
 157              type_submit.attr("value", lang.adding_buddy);
 158              var list = "buddy";
 159          }
 160  
 161          $.ajax(
 162          {
 163              type: 'post',
 164              url: 'usercp.php?action=do_editlists&my_post_key='+my_post_key+'&manage='+type,
 165              data: { ajax: 1, add_username: type_add_username.val() },
 166              async: true,
 167              complete: function (request)
 168              {
 169                  if(request.responseText.indexOf("buddy_count") >= 0 || request.responseText.indexOf("ignored_count") >= 0)
 170                  {
 171                       $("#"+list+"_list").html(request.responseText);
 172                  }
 173                  else
 174                  {
 175                      $("#sentrequests").html(request.responseText);
 176                  }
 177                  
 178                  type_submit.prop("disabled", false);
 179                  type_add_username.prop("disabled", false);
 180                  type_submit.attr("value", old_value);
 181                  type_add_username.val("");
 182                  type_add_username.trigger('focus');
 183                  type_add_username.select2('data', null);
 184              }
 185          });
 186  
 187          return false;
 188      },
 189  
 190      removeBuddy: function(type, uid)
 191      {
 192          if(type == "ignored")
 193          {
 194              var message = lang.remove_ignored;
 195          }
 196          else
 197          {
 198              var message = lang.remove_buddy;
 199          }
 200  
 201          MyBB.prompt(message, {
 202              buttons:[
 203                      {title: yes_confirm, value: true},
 204                      {title: no_confirm, value: false}
 205              ],
 206              submit: function(e,v,m,f){
 207                  if(v == true)
 208                  {
 209                      $.ajax(
 210                      {
 211                          type: 'post',
 212                          url: 'usercp.php?action=do_editlists&my_post_key='+my_post_key+'&manage='+type+'&delete='+uid,
 213                          data: { ajax: 1 },
 214                          async: true
 215                      });
 216                  }
 217              }
 218          });
 219  
 220          return false;
 221      }
 222  };
 223  
 224  UserCP.init();


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