includes/clientside/static/rank-manager.js
author Dan
Fri, 21 Aug 2009 15:39:34 -0400
changeset 1097 4252e4d83102
parent 823 4596c40aaa94
child 1227 bdac73ed481e
permissions -rw-r--r--
A bit of work on tutorial content, more still needed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
563
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
     1
/**
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
     2
 * Creates a control that can be used to edit a rank.
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
     3
 */
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
     4
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
     5
var RankEditorControl = function(rankdata)
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
     6
{
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
     7
  this.rankdata = ( typeof(rankdata) == 'object' ) ? rankdata : {};
651
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
     8
  if ( !this.rankdata.rank_style )
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
     9
  {
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
    10
    this.rankdata.rank_style = '';
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
    11
  }
563
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    12
  
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    13
  // have the browser parse CSS for us and use an anchor to be as close
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    14
  // as possible in calculating CSS
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    15
  
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    16
  // this is kind of a hack as it relies on setAttribute/getAttribute in
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    17
  // order to obtain stringified versions of CSS data
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    18
  var cssobj = document.createElement('a');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    19
  cssobj.setAttribute('style', this.rankdata.rank_style);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    20
  
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    21
  this.style_sim_obj = cssobj;
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    22
  
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    23
  // figure out if we're editing or creating
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    24
  this.editing = ( typeof(this.rankdata.rank_id) == 'number' );
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    25
  
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    26
  this.render = function()
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    27
  {
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    28
    var editor = document.createElement('div');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    29
    editor.className = 'tblholder';
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    30
    // stash this editor instance in the parent div for later function calls
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    31
    editor.editor = this;
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    32
    this.wrapperdiv = editor;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    33
    editor.style.width = '100%';
563
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    34
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    35
    // tables suck.
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    36
    var table = document.createElement('table');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    37
    table.setAttribute('cellspacing', '1');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    38
    table.setAttribute('cellpadding', '4');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    39
    table.setAttribute('width', '100%');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    40
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    41
    // heading: "Edit rank: foo" or "Create a new rank"
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    42
    var tr_head = document.createElement('tr');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    43
    var th_head = document.createElement('th');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    44
    th_head.setAttribute('colspan', '2');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    45
    if ( this.editing )
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    46
    {
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    47
      var th_head_string = 'acpur_th_edit_rank';
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    48
      var th_head_data = { rank_title: $lang.get(this.rankdata.rank_title) };
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    49
    }
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    50
    else
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    51
    {
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    52
      var th_head_string = 'acpur_th_create_rank';
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    53
      var th_head_data = { };
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    54
    }
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    55
    th_head.appendChild(document.createTextNode($lang.get(th_head_string, th_head_data)));
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    56
    tr_head.appendChild(th_head);
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    57
    this.th_head = th_head;
563
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    58
    table.appendChild(tr_head);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    59
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    60
    // row: rank title
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    61
    var tr_title = document.createElement('tr');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    62
    var td_title_l = document.createElement('td');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    63
    var td_title_f = document.createElement('td');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    64
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    65
    td_title_l.className = td_title_f.className = 'row1';
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    66
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    67
    td_title_l.appendChild(document.createTextNode($lang.get('acpur_field_rank_title')));
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    68
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    69
    // field: rank title
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    70
    var f_rank_title = document.createElement('input');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    71
    f_rank_title.type = 'text';
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    72
    f_rank_title.size = '30';
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    73
    f_rank_title.value = ( this.editing ) ? this.rankdata.rank_title : '';
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    74
    f_rank_title.editor = this;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    75
    f_rank_title.onkeyup = function()
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    76
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    77
      this.editor.renderPreview();
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
    78
    }
563
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    79
    this.f_rank_title = f_rank_title;
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    80
    td_title_f.appendChild(f_rank_title);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    81
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    82
    tr_title.appendChild(td_title_l);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    83
    tr_title.appendChild(td_title_f);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    84
    table.appendChild(tr_title);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    85
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    86
    // row: basic style options
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    87
    var tr_basic = document.createElement('tr');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    88
    var td_basic_l = document.createElement('td');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    89
    var td_basic_f = document.createElement('td');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    90
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    91
    td_basic_l.className = td_basic_f.className = 'row2';
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    92
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    93
    td_basic_l.appendChild(document.createTextNode($lang.get('acpur_field_style_basic')));
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    94
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    95
    // fieldset: basic style options
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    96
    // field: bold
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    97
    var l_basic_bold = document.createElement('label');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    98
    var f_basic_bold = document.createElement('input');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
    99
    f_basic_bold.type = 'checkbox';
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   100
    f_basic_bold.checked = ( this.style_sim_obj.style.fontWeight == 'bold' ) ? true : false;
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   101
    f_basic_bold.editor = this;
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   102
    f_basic_bold.onclick = function()
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   103
    {
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   104
      this.editor.style_sim_obj.style.fontWeight = ( this.checked ) ? 'bold' : null;
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   105
      this.editor.renderPreview();
563
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   106
    }
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   107
    l_basic_bold.style.fontWeight = 'bold';
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   108
    l_basic_bold.appendChild(f_basic_bold);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   109
    l_basic_bold.appendChild(document.createTextNode(' '));
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   110
    l_basic_bold.appendChild(document.createTextNode($lang.get('acpur_field_style_basic_bold')));
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   111
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   112
    // field: italic
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   113
    var l_basic_italic = document.createElement('label');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   114
    var f_basic_italic = document.createElement('input');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   115
    f_basic_italic.type = 'checkbox';
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   116
    f_basic_italic.checked = ( this.style_sim_obj.style.fontStyle == 'italic' ) ? true : false;
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   117
    f_basic_italic.editor = this;
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   118
    f_basic_italic.onclick = function()
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   119
    {
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   120
      this.editor.style_sim_obj.style.fontStyle = ( this.checked ) ? 'italic' : null;
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   121
      this.editor.renderPreview();
563
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   122
    }
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   123
    l_basic_italic.style.fontStyle = 'italic';
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   124
    l_basic_italic.appendChild(f_basic_italic);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   125
    l_basic_italic.appendChild(document.createTextNode(' '));
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   126
    l_basic_italic.appendChild(document.createTextNode($lang.get('acpur_field_style_basic_italic')));
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   127
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   128
    // field: underline
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   129
    var l_basic_underline = document.createElement('label');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   130
    var f_basic_underline = document.createElement('input');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   131
    f_basic_underline.type = 'checkbox';
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   132
    f_basic_underline.checked = ( this.style_sim_obj.style.textDecoration == 'underline' ) ? true : false;
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   133
    f_basic_underline.editor = this;
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   134
    f_basic_underline.onclick = function()
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   135
    {
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   136
      this.editor.style_sim_obj.style.textDecoration = ( this.checked ) ? 'underline' : null;
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   137
      this.editor.renderPreview();
563
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   138
    }
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   139
    l_basic_underline.style.textDecoration = 'underline';
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   140
    l_basic_underline.appendChild(f_basic_underline);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   141
    l_basic_underline.appendChild(document.createTextNode(' '));
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   142
    l_basic_underline.appendChild(document.createTextNode($lang.get('acpur_field_style_basic_underline')));
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   143
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   144
    // finish up formatting row#1
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   145
    td_basic_f.appendChild(l_basic_bold);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   146
    td_basic_f.appendChild(document.createTextNode(' '));
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   147
    td_basic_f.appendChild(l_basic_italic);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   148
    td_basic_f.appendChild(document.createTextNode(' '));
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   149
    td_basic_f.appendChild(l_basic_underline);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   150
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   151
    tr_basic.appendChild(td_basic_l);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   152
    tr_basic.appendChild(td_basic_f);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   153
    table.appendChild(tr_basic);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   154
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   155
    // row: rank color
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   156
    var tr_color = document.createElement('tr');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   157
    var td_color_l = document.createElement('td');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   158
    var td_color_f = document.createElement('td');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   159
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   160
    td_color_l.className = td_color_f.className = 'row1';
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   161
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   162
    td_color_l.appendChild(document.createTextNode($lang.get('acpur_field_style_color')));
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   163
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   164
    // field: rank color
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   165
    var f_rank_color = document.createElement('input');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   166
    f_rank_color.type = 'text';
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   167
    f_rank_color.size = '7';
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   168
    f_rank_color.value = ( this.editing ) ? this.rgb2hex(this.style_sim_obj.style.color) : '';
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   169
    f_rank_color.style.backgroundColor = this.style_sim_obj.style.color;
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   170
    f_rank_color.editor = this;
563
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   171
    this.f_rank_color = f_rank_color;
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   172
    f_rank_color.onkeyup = function(e)
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   173
    {
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   174
      if ( !e.keyCode )
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   175
        e = window.event;
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   176
      if ( !e )
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   177
        return false;
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   178
      var chr = (String.fromCharCode(e.keyCode)).toLowerCase();
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   179
      this.value = this.value.replace(/[^a-fA-F0-9]/g, '');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   180
      if ( this.value.length > 6 )
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   181
      {
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   182
        this.value = this.value.substr(0, 6);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   183
      }
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   184
      if ( this.value.length == 6 || this.value.length == 3 )
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   185
      {
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   186
        this.style.backgroundColor = '#' + this.value;
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   187
        this.editor.style_sim_obj.style.color = '#' + this.value;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   188
        this.style.color = '#' + this.editor.determineLightness(this.value);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   189
        this.editor.renderPreview();
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   190
      }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   191
      else if ( this.value.length == 0 )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   192
      {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   193
        this.style.backgroundColor = null;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   194
        this.editor.style_sim_obj.style.color = null;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   195
        this.editor.renderPreview();
563
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   196
      }
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   197
    }
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   198
    td_color_f.appendChild(f_rank_color);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   199
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   200
    tr_color.appendChild(td_color_l);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   201
    tr_color.appendChild(td_color_f);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   202
    table.appendChild(tr_color);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   203
    
651
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   204
    // field: additional CSS
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   205
    var tr_css = document.createElement('tr');
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   206
    
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   207
    var td_css_l = document.createElement('td');
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   208
    td_css_l.className = 'row2';
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   209
    td_css_l.appendChild(document.createTextNode($lang.get('acpur_field_style_css')));
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   210
    tr_css.appendChild(td_css_l);
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   211
    
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   212
    var td_css_f = document.createElement('td');
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   213
    td_css_f.className = 'row2';
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   214
    var f_css = document.createElement('input');
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   215
    f_css.type = 'text';
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   216
    f_css.value = this.stripBasicCSSAttributes(this.rankdata.rank_style);
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   217
    f_css.style.width = '98%';
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   218
    f_css.editor = this;
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   219
    f_css.onkeyup = function()
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   220
    {
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   221
      if ( !(trim(this.value)).match(/^((([a-z-]+):(.+?);)+)?$/) )
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   222
        return;
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   223
      var newcss = this.editor.stripExtendedCSSAttributes(String(this.editor.style_sim_obj.getAttribute('style'))) + ' ' + this.value;
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   224
      this.editor.preview_div.setAttribute('style', 'font-size: x-large; ' + newcss);
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   225
      this.editor.style_sim_obj.setAttribute('style', newcss);
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   226
    }
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   227
    this.f_css = f_css;
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   228
    td_css_f.appendChild(f_css);
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   229
    tr_css.appendChild(td_css_f);
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   230
    table.appendChild(tr_css);
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   231
    
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   232
    // "field": preview
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   233
    var tr_preview = document.createElement('tr');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   234
    var td_preview_l = document.createElement('td');
651
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   235
    td_preview_l.className = 'row1';
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   236
    td_preview_l.appendChild(document.createTextNode($lang.get('acpur_field_preview')));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   237
    tr_preview.appendChild(td_preview_l);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   238
    
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   239
    var td_preview_f = document.createElement('td');
651
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   240
    td_preview_f.className = 'row1';
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   241
    var div_preview = document.createElement('a');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   242
    this.preview_div = div_preview;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   243
    div_preview.style.fontSize = 'x-large';
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   244
    div_preview.appendChild(document.createTextNode(''));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   245
    div_preview.firstChild.nodeValue = ( this.editing ) ? this.rankdata.rank_title : '';
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   246
    td_preview_f.appendChild(div_preview);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   247
    tr_preview.appendChild(td_preview_f);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   248
    
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   249
    table.appendChild(tr_preview);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   250
    
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   251
    // submit button
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   252
    var tr_submit = document.createElement('tr');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   253
    var th_submit = document.createElement('th');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   254
    th_submit.className = 'subhead';
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   255
    th_submit.setAttribute('colspan', '2');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   256
    var btn_submit = document.createElement('input');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   257
    btn_submit.type = 'submit';
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   258
    btn_submit.value = ( this.editing ) ? $lang.get('acpur_btn_save') : $lang.get('acpur_btn_create_submit');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   259
    btn_submit.editor = this;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   260
    btn_submit.style.fontWeight = 'bold';
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   261
    btn_submit.onclick = function(e)
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   262
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   263
      this.editor.submitEvent(e);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   264
    }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   265
    this.btn_submit = btn_submit;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   266
    th_submit.appendChild(btn_submit);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   267
    
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   268
    // delete button
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   269
    if ( this.editing )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   270
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   271
      var btn_delete = document.createElement('input');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   272
      btn_delete.type = 'button';
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   273
      btn_delete.value = $lang.get('acpur_btn_delete');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   274
      btn_delete.editor = this;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   275
      btn_delete.onclick = function(e)
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   276
      {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   277
        this.editor.deleteEvent(e);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   278
      }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   279
      th_submit.appendChild(document.createTextNode(' '));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   280
      th_submit.appendChild(btn_delete);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   281
    }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   282
    
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   283
    tr_submit.appendChild(th_submit);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   284
    
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   285
    table.appendChild(tr_submit);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   286
    
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   287
    // render preview
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   288
    this.renderPreview();
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   289
    
563
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   290
    // finalize the editor table
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   291
    editor.appendChild(table);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   292
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   293
    // stash rendered editor
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   294
    this.editordiv = editor;
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   295
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   296
    // send output
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   297
    return editor;
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   298
  }
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   299
  
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   300
  /**
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   301
   * Takes the existing editor div and transforms the necessary elements so that it goes from "create" mode to "edit" mode
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   302
   * @param object Edit data - same format as the rankdata parameter to the constructor, but we should only need rank_id
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   303
   */
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   304
  
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   305
  this.transformToEditor = function(rankdata)
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   306
  {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   307
    // we need a rank ID
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   308
    if ( typeof(rankdata.rank_id) != 'number' )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   309
      return false;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   310
    
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   311
    if ( this.editing )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   312
      return false;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   313
    
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   314
    this.editing = true;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   315
    
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   316
    this.rankdata = rankdata;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   317
    this.rankdata.rank_title = this.f_rank_title.value;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   318
    this.rankdata.rank_style = this.getCSS();
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   319
    
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   320
    // transform various controls
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   321
    this.th_head.firstChild.nodeValue = $lang.get('acpur_th_edit_rank', {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   322
        rank_title: $lang.get(this.rankdata.rank_title)
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   323
      });
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   324
    this.btn_submit.value = $lang.get('acpur_btn_save');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   325
    
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   326
    // add the delete button
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   327
    var th_submit = this.btn_submit.parentNode;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   328
    
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   329
    var btn_delete = document.createElement('input');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   330
    btn_delete.type = 'button';
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   331
    btn_delete.value = $lang.get('acpur_btn_delete');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   332
    btn_delete.editor = this;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   333
    btn_delete.onclick = function(e)
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   334
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   335
      this.editor.deleteEvent(e);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   336
    }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   337
    th_submit.appendChild(document.createTextNode(' '));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   338
    th_submit.appendChild(btn_delete);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   339
    
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   340
    return true;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   341
  }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   342
  
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   343
  /**
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   344
   * Takes a hex color, averages the three channels, and returns either 'ffffff' or '000000' depending on the luminosity of the color.
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   345
   * @param string
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   346
   * @return string
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   347
   */
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   348
  
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   349
  this.determineLightness = function(hexval)
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   350
  {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   351
    var rgb = this.hex2rgb(hexval);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   352
    var lumin = ( rgb[0] + rgb[1] + rgb[2] ) / 3;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   353
    return ( lumin > 60 ) ? '000000' : 'ffffff';
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   354
  }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   355
  
651
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   356
  /**
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   357
   * Strips out basic CSS attributes (color, font-weight, font-style, text-decoration) from a snippet of CSS.
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   358
   * @param string
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   359
   * @return string
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   360
   */
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   361
  
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   362
  this.stripBasicCSSAttributes = function(css)
563
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   363
  {
651
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   364
    return trim(css.replace(/(color|font-weight|font-style|text-decoration): ?([A-z0-9# ,\(\)]+);/g, ''));
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   365
  }
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   366
  
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   367
  /**
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   368
   * Strips out all but basic CSS attributes.
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   369
   * @param string
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   370
   * @return string
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   371
   */
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   372
  
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   373
  this.stripExtendedCSSAttributes = function(css)
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   374
  {
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   375
    var match;
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   376
    var final_css = '';
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   377
    var basics = ['color', 'font-weight', 'font-style', 'text-decoration'];
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   378
    while ( match = css.match(/([a-z-]+):(.+?);/) )
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   379
    {
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   380
      if ( in_array(match[1], basics) )
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   381
      {
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   382
        final_css += ' ' + match[0] + ' ';
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   383
      }
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   384
      css = css.replace(match[0], '');
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   385
    }
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   386
    final_css = trim(final_css);
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   387
    return final_css;
563
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   388
  }
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   389
  
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   390
  this.getCSS = function()
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   391
  {
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   392
    return this.style_sim_obj.getAttribute('style');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   393
  }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   394
  
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   395
  this.renderPreview = function()
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   396
  {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   397
    if ( !this.preview_div )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   398
      return false;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   399
    var color = ( this.style_sim_obj.style.color ) ? '#' + this.rgb2hex(this.style_sim_obj.style.color) : null;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   400
    this.preview_div.style.color = color;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   401
    this.preview_div.style.fontWeight = this.style_sim_obj.style.fontWeight;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   402
    this.preview_div.style.fontStyle = this.style_sim_obj.style.fontStyle;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   403
    this.preview_div.style.textDecoration = this.style_sim_obj.style.textDecoration;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   404
    this.preview_div.firstChild.nodeValue = $lang.get(this.f_rank_title.value);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   405
  }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   406
  
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   407
  this.submitEvent = function(e)
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   408
  {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   409
    if ( this.onsubmit )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   410
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   411
      this.onsubmit(e);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   412
    }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   413
    else
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   414
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   415
      window.console.error('RankEditorControl: no onsubmit event specified');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   416
    }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   417
  }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   418
  
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   419
  this.deleteEvent = function(e)
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   420
  {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   421
    if ( this.ondelete )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   422
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   423
      this.ondelete(e);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   424
    }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   425
    else
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   426
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   427
      window.console.error('RankEditorControl: no ondelete event specified');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   428
    }
563
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   429
  }
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   430
  
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   431
  /**
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   432
   * Converts a parenthetical color specification (rgb(x, y, z)) to hex form (xxyyzz)
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   433
   * @param string
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   434
   * @return string
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   435
   */
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   436
  
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   437
  this.rgb2hex = function(rgb)
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   438
  {
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   439
    var p = rgb.match(/^rgb\(([0-9]+), ([0-9]+), ([0-9]+)\)$/);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   440
    if ( !p )
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   441
      return rgb.replace(/^#/, '');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   442
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   443
    var r = parseInt(p[1]).toString(16), g = parseInt(p[2]).toString(16), b = parseInt(p[3]).toString(16);
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   444
    if ( r.length < 2 )
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   445
      r = '0' + r;
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   446
    if ( g.length < 2 )
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   447
      g = '0' + g;
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   448
    if ( b.length < 2 )
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   449
      b = '0' + b;
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   450
    
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   451
    return r + g + b;
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   452
  }
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   453
  
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   454
  /**
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   455
   * Get red, green, and blue values for the given hex color
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   456
   * @param string
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   457
   * @return array (numbered, e.g. not an object
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   458
   */
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   459
  
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   460
  this.hex2rgb = function(hex)
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   461
  {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   462
    hex = hex.replace(/^#/, '');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   463
    if ( hex.length != 3 && hex.length != 6 )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   464
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   465
      return hex;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   466
    }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   467
    if ( hex.length == 3 )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   468
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   469
      // is there a better way to do this?
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   470
      hex = hex.charAt(0) + hex.charAt(0) + hex.charAt(1) + hex.charAt(1) + hex.charAt(2) + hex.charAt(2);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   471
    }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   472
    hex = [ hex.substr(0, 2), hex.substr(2, 2), hex.substr(4, 2) ];
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   473
    var red = parseInt(hex[0], 16);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   474
    var green = parseInt(hex[1], 16);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   475
    var blue = parseInt(hex[2], 16);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   476
    return [red, green, blue];
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   477
  }
563
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   478
}
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   479
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   480
/**
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   481
 * Perform request for editable rank data and draw editor
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   482
 */
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   483
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   484
function ajaxInitRankEdit(rank_id)
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   485
{
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   486
  load_component('messagebox');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   487
  var json_packet = {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   488
    mode: 'get_rank',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   489
    rank_id: rank_id
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   490
  };
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   491
  json_packet = ajaxEscape(toJSONString(json_packet));
823
4596c40aaa94 AJAX core library: possible breaking change, readystatechange functions are now called with the XHR instance as the first parameter, to allow requests to run in parallel. This means much better stability but may break some applets (compatibility hack is included)
Dan
parents: 794
diff changeset
   492
  ajaxPost(makeUrlNS('Admin', 'UserRanks/action.json'), 'r=' + json_packet, function(ajax)
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   493
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   494
      if ( ajax.readyState == 4 && ajax.status == 200 )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   495
      {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   496
        var response = String(ajax.responseText + '');
651
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   497
        if ( !check_json_response(response) )
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   498
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   499
          handle_invalid_json(ajax.responseText);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   500
          return false;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   501
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   502
        try
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   503
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   504
          var response = parseJSON(ajax.responseText);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   505
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   506
        catch(e)
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   507
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   508
          handle_invalid_json(ajax.responseText);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   509
        }
794
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   510
        if ( response.error )
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   511
        {
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   512
          if ( response.error == 'need_auth_to_admin' )
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   513
          {
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   514
            load_component('login');
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   515
            var rid = rank_id;
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   516
            ajaxDynamicReauth(function()
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   517
              {
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   518
                ajaxInitRankEdit(rid);
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   519
              });
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   520
          }
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   521
          else
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   522
          {
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   523
            alert(response.error);
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   524
          }
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   525
          return false;
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   526
        }
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   527
        var editor = new RankEditorControl(response);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   528
        editor.onsubmit = ajaxRankEditHandleSaveExisting;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   529
        editor.ondelete = ajaxRankEditHandleDelete;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   530
        var container = document.getElementById('admin_ranks_container_right');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   531
        container.innerHTML = '';
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   532
        container.appendChild(editor.render());
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   533
      }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   534
    }, true);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   535
}
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   536
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   537
function ajaxInitRankCreate()
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   538
{
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   539
  load_component('messagebox');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   540
  var editor = new RankEditorControl();
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   541
  editor.onsubmit = ajaxRankEditHandleSaveNew;
563
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   542
  var container = document.getElementById('admin_ranks_container_right');
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   543
  container.innerHTML = '';
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   544
  container.appendChild(editor.render());
0103428e2179 First test of rank manager interface, not currently capable of doing anything interesting (fills form with placeholder data); strings are in an earlier commit
Dan
parents:
diff changeset
   545
}
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   546
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   547
function ajaxRankEditHandleSave(editor, switch_new)
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   548
{
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   549
  var whitey = whiteOutElement(editor.wrapperdiv);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   550
  
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   551
  // pack it up, ...
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   552
  var json_packet = {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   553
    mode: ( switch_new ) ? 'create_rank' : 'save_rank',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   554
    rank_title: editor.f_rank_title.value,
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   555
    rank_style: editor.getCSS()
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   556
  }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   557
  if ( !switch_new )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   558
  {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   559
    json_packet.rank_id = editor.rankdata.rank_id;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   560
  }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   561
  /// ... pack it in
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   562
  var json_packet = ajaxEscape(toJSONString(json_packet));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   563
  
823
4596c40aaa94 AJAX core library: possible breaking change, readystatechange functions are now called with the XHR instance as the first parameter, to allow requests to run in parallel. This means much better stability but may break some applets (compatibility hack is included)
Dan
parents: 794
diff changeset
   564
  ajaxPost(makeUrlNS('Admin', 'UserRanks/action.json'), 'r=' + json_packet, function(ajax)
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   565
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   566
      if ( ajax.readyState == 4 && ajax.status == 200 )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   567
      {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   568
        var response = String(ajax.responseText + '');
651
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   569
        if ( !check_json_response(response) )
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   570
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   571
          handle_invalid_json(ajax.responseText);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   572
          return false;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   573
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   574
        try
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   575
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   576
          var response = parseJSON(ajax.responseText);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   577
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   578
        catch(e)
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   579
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   580
          handle_invalid_json(ajax.responseText);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   581
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   582
        if ( response.mode == 'success' )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   583
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   584
          whiteOutReportSuccess(whitey);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   585
          if ( switch_new )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   586
          {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   587
            //
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   588
            // we have a few more things to do with a newly created rank.
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   589
            //
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   590
            
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   591
            // 1. transform editor
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   592
            editor.transformToEditor(response);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   593
            editor.onsubmit = ajaxRankEditHandleSaveExisting;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   594
            editor.ondelete = ajaxRankEditHandleDelete;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   595
            
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   596
            // 2. append the new rank to the list
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   597
            var create_link = document.getElementById('rankadmin_createlink');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   598
            if ( create_link )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   599
            {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   600
              var parent = create_link.parentNode;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   601
              var edit_link = document.createElement('a');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   602
              edit_link.href = '#rank_edit:' + response.rank_id;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   603
              edit_link.className = 'rankadmin-editlink';
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   604
              edit_link.setAttribute('style', editor.getCSS());
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   605
              edit_link.id = 'rankadmin_editlink_' + response.rank_id;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   606
              edit_link.rank_id = response.rank_id;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   607
              edit_link.appendChild(document.createTextNode($lang.get(editor.f_rank_title.value)));
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   608
              parent.insertBefore(edit_link, create_link);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   609
              edit_link.onclick = function()
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   610
              {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   611
                ajaxInitRankEdit(this.rank_id);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   612
              }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   613
            }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   614
          }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   615
          else
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   616
          {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   617
            // update the rank title on the left
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   618
            var edit_link = document.getElementById('rankadmin_editlink_' + editor.rankdata.rank_id);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   619
            if ( edit_link )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   620
            {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   621
              edit_link.firstChild.nodeValue = $lang.get(editor.f_rank_title.value);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   622
              edit_link.setAttribute('style', editor.getCSS());
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   623
            }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   624
          }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   625
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   626
        else
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   627
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   628
          whitey.parentNode.removeChild(whitey);
794
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   629
          if ( response.error == 'need_auth_to_admin' )
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   630
          {
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   631
            load_component('login');
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   632
            ajaxDynamicReauth(function()
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   633
              {
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   634
                ajaxRankEditHandleSave(editor, switch_new);
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   635
              });
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   636
          }
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   637
          else
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   638
          {
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   639
            miniPromptMessage({
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   640
                title: $lang.get('acpur_err_save_failed_title'),
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   641
                message: response.error,
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   642
                buttons: [
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   643
                  {
794
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   644
                    text: $lang.get('etc_ok'),
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   645
                    color: 'red',
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   646
                    style: {
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   647
                      fontWeight: 'bold'
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   648
                    },
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   649
                    onclick: function()
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   650
                    {
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   651
                      miniPromptDestroy(this);
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   652
                    }
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   653
                  }
794
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   654
                ]
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   655
            });
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   656
          }
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   657
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   658
      }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   659
    }, true);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   660
}
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   661
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   662
var ajaxRankEditHandleSaveExisting = function()
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   663
{
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   664
  ajaxRankEditHandleSave(this, false);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   665
}
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   666
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   667
var ajaxRankEditHandleSaveNew = function()
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   668
{
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   669
  ajaxRankEditHandleSave(this, true);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   670
}
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   671
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   672
var ajaxRankEditHandleDelete = function()
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   673
{
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   674
  var mp = miniPromptMessage({
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   675
      title: $lang.get('acpur_msg_rank_delete_confirm_title'),
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   676
      message: $lang.get('acpur_msg_rank_delete_confirm_body'),
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   677
      buttons: [
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   678
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   679
          text: $lang.get('acpur_btn_delete'),
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   680
          color: 'red',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   681
          style: {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   682
            fontWeight: 'bold'
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   683
          },
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   684
          onclick: function()
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   685
          {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   686
            var parent = miniPromptGetParent(this);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   687
            var editor = parent.editor;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   688
            setTimeout(function()
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   689
              {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   690
                ajaxRankEditDeleteConfirmed(editor);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   691
              }, 1000);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   692
            miniPromptDestroy(parent);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   693
          }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   694
        },
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   695
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   696
          text: $lang.get('etc_cancel'),
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   697
          onclick: function()
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   698
          {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   699
            miniPromptDestroy(this);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   700
          }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   701
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   702
      ]
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   703
    });
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   704
  console.debug(mp);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   705
  mp.editor = this;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   706
}
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   707
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   708
function ajaxRankEditDeleteConfirmed(editor)
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   709
{
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   710
  var whitey = whiteOutElement(editor.wrapperdiv);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   711
  
779
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 699
diff changeset
   712
  load_component(['jquery', 'jquery-ui']);
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   713
  
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   714
  var json_packet = {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   715
    mode: 'delete_rank',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   716
    rank_id: editor.rankdata.rank_id
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   717
  };
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   718
  var rank_id = editor.rankdata.rank_id;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   719
  
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   720
  json_packet = ajaxEscape(toJSONString(json_packet));
823
4596c40aaa94 AJAX core library: possible breaking change, readystatechange functions are now called with the XHR instance as the first parameter, to allow requests to run in parallel. This means much better stability but may break some applets (compatibility hack is included)
Dan
parents: 794
diff changeset
   721
  ajaxPost(makeUrlNS('Admin', 'UserRanks/action.json'), 'r=' + json_packet, function(ajax)
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   722
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   723
      if ( ajax.readyState == 4 && ajax.status == 200 )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   724
      {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   725
        var response = String(ajax.responseText + '');
651
ce9d78d7251d Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents: 628
diff changeset
   726
        if ( !check_json_response(response) )
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   727
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   728
          handle_invalid_json(ajax.responseText);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   729
          return false;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   730
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   731
        try
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   732
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   733
          var response = parseJSON(ajax.responseText);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   734
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   735
        catch(e)
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   736
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   737
          handle_invalid_json(ajax.responseText);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   738
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   739
        if ( response.mode == 'success' )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   740
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   741
          // the deletion was successful, report success and kill off the editor
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   742
          whiteOutReportSuccess(whitey);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   743
          setTimeout(function()
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   744
            {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   745
              // nuke the rank title on the left
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   746
              var edit_link = document.getElementById('rankadmin_editlink_' + editor.rankdata.rank_id);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   747
              if ( edit_link )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   748
              {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   749
                edit_link.parentNode.removeChild(edit_link);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   750
              }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   751
              // collapse and destroy the editor
699
c7d737202d59 Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents: 651
diff changeset
   752
              $(editor.wrapperdiv).hide("blind", {}, 500, function()
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   753
                  {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   754
                    // when the animation finishes, nuke the whole thing
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   755
                    var container = document.getElementById('admin_ranks_container_right');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   756
                    container.innerHTML = $lang.get('acpur_msg_select_rank');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   757
                  }
699
c7d737202d59 Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents: 651
diff changeset
   758
                );
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   759
            }, 1500);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   760
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   761
        else
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   762
        {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   763
          whitey.parentNode.removeChild(whitey);
794
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   764
          if ( response.error == 'need_auth_to_admin' )
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   765
          {
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   766
            load_component('login');
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   767
            ajaxDynamicReauth(function()
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   768
              {
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   769
                ajaxRankEditDeleteConfirmed(editor);
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   770
              });
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   771
          }
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   772
          else
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   773
          {
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   774
            miniPromptMessage({
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   775
                title: $lang.get('acpur_err_delete_failed_title'),
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   776
                message: response.error,
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   777
                buttons: [
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   778
                  {
794
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   779
                    text: $lang.get('etc_ok'),
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   780
                    color: 'red',
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   781
                    style: {
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   782
                      fontWeight: 'bold'
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   783
                    },
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   784
                    onclick: function()
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   785
                    {
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   786
                      miniPromptDestroy(this);
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   787
                    }
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   788
                  }
794
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   789
                ]
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   790
            });
720516162012 Added support for re-auth on submit to rank manager when session goes bad; still more to come
Dan
parents: 779
diff changeset
   791
          }
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   792
        }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   793
      }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   794
    }, true);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 563
diff changeset
   795
}