Вход Регистрация
Файл: js/al/profile_edit_mil.js
Строк: 369
<?php
var ProfileEditorMil = {

  
init: function() {
    
cur.globalCounter 0;
    
cur.militariesCount 0;

    
selectsData.setCountries(cur.selData.countries_list);

    if (!
isVisible('militaries')) {
      
cur.militariesCount cur.militaries.length;
      if (
cur.militariesCount) {
        for (var 
0cur.militaries.length; ++i) {
          
ge('militaries').appendChild(this.genMilitaryRow(cur.militaries[i].id));
          
cur.militaries[i] = this.initMilitaryRow(cur.militaries[i]);
        }
      } else {
        
this.addMilitary();
      }
      
show('militaries');
    }

    if (
cur.militariesCount >= 5) {
      
hide('add_military_link');
    } else {
      
show('add_military_link');
    }
  },

  
genOneRow: function(fieldidlabelparamsadditional) {
    var 
key field id;
    if (!
params) {
      
params '';
    }
    if (!
additional) {
      
additional '';
    }
    return 
'<div class="pedit_edu_row" id="row_' key '">' +
              
'<div class="label fl_l ta_r">' label '</div>' +
              
'<div class="labeled fl_l"><input id="' key '" name="' key '" ' params '/></div>' +
           
additional '</div>';
  },

  
genMilitaryRow: function(military_id) {
    return 
ce('div', {
      
className'pedit_edu_big_row',
      
id'military' military_id,
      
innerHTML'<div id="content' military_id '">' +
        
this.genOneRow('country'military_idgetLang('select_country'), '',
        
'<img src="/images/upload.gif" id="progress' military_id '" />' +
        
'<a class="fl_r" onclick="ProfileEditorMil.deleteMilitary(' military_id ')">' getLang('global_delete') + '</a>') +
        
'<div id="details' military_id '" style="display: none">' +
          
this.genOneRow('unit'military_idgetLang('select_military_unit')) +
        
'<div id="all' military_id '" style="display: none">' +
          
this.genOneRow('start'military_idgetLang('select_military_start')) +
          
this.genOneRow('finish'military_idgetLang('select_military_finish')) +
        
'</div></div></div>' +
        
'<div class="deleted" id="deleted' military_id '"><div></div>' +
          
'<a class="fl_r" onclick="ProfileEditorMil.restoreMilitary(' military_id ')">' getLang('global_dont_delete') + '</a>' +
        
'</div><div class="separator"><div></div></div>'
    
}, {display'none'});
  },

  
get_by_id: function(elemid) {
    if (
elem.id == id) {
      return 
elem;
    }
    for (var 
0elem.childNodes.length; ++i) {
      var 
result this.get_by_id(elem.childNodes[i], id);
      if (
result) {
        return 
result;
      }
    }
    return 
false;
  },

  
initMilitaryRow: function(militaryelem) {
    var 
elem ? function(id) { return ProfileEditorMil.get_by_id(elemid); } : ge;
    
military.uiStart = new Dropdown(g('start' military.id), [[0getLang('select_year_not_selected')]].concat(cur.selData.from_years), {
      
width200,
      
autocompletetrue,
      
placeholdergetLang('select_year_not_selected'),
      
placeholderColor'#000',
      
noResultgetLang('select_year_not_found'),
      
onChange: function(value) {
        
value intval(value);
        var 
new_finish_data = [];
        if (!
value) {
          
military.uiStart.clear();
          
new_finish_data cur.selData.until_years;
        } else {
          var 
finish_value intval(military.uiFinish.val());
          if (
finish_value && finish_value value) {
            
military.uiFinish.val(value);
          }
          for (var 
0cur.selData.until_years.length; ++i) {
            if (
cur.selData.until_years[i][0] >= value) {
              
new_finish_data.push(cur.selData.until_years[i]);
            }
          }
        }
        
military.uiFinish.setOptions({defaultItems: [[0getLang('select_year_not_selected')]].concat(new_finish_data)});
        
military.uiFinish.setData(new_finish_data);
      }
    });
    
military.uiStart.setData(cur.selData.from_years);
    
military.uiFinish = new Dropdown(g('finish' military.id), [[0getLang('select_year_not_selected')]].concat(cur.selData.until_years), {
      
width200,
      
autocompletetrue,
      
placeholdergetLang('select_year_not_selected'),
      
placeholderColor'#000',
      
noResultgetLang('select_year_not_found'),
      
onChange: function(value) {
        
value intval(value);
        var 
new_start_data = [];
        if (!
value) {
          
military.uiFinish.clear();
          
new_start_data cur.selData.from_years;
        } else {
          var 
start_value intval(military.uiStart.val());
          if (
start_value && start_value value) {
            
military.uiStart.val(value);
          }
          for (var 
0cur.selData.from_years.length; ++i) {
            if (
cur.selData.from_years[i][0] <= value) {
              
new_start_data.push(cur.selData.from_years[i]);
            }
          }
        }
        
military.uiStart.setOptions({defaultItems: [[0getLang('select_year_not_selected')]].concat(new_start_data)});
        
military.uiStart.setData(new_start_data);
      }
    });
    
military.uiFinish.setData(cur.selData.until_years);

    
military.uiStart.val(military.starttrue);
    
military.uiFinish.val(military.finishtrue);

    
military.uiUnit = new Selector(g('unit' military.id), 'select_ajax.php?act=a_get_units&country=' military.country, {
      
width200,
      
multiselectfalse,
      
placeholdergetLang('select_military_unit_not_selected'),
      
placeholderColor'#000',
      
noResultgetLang('select_military_unit_select'),
      
introTextgetLang('select_military_unit_select'),
      
selectedItems: [military.unit_val],
      
dropdownfalse,
      
enableCustomtrue,
      
progressBar'progress' military.id,
      
onChange: function(value) {
        if (!
intval(value)) {
          
military.uiUnit.clear();
          
hide('all' military.id);
        } else {
          
show('all' military.id);
        }
        
military.uiStart.val(0true);
        
military.uiFinish.val(0true);
      }
    });

    
military.uiCountry = new CountrySelect(g('country' military.id), g('row_country' military.id), {
      
width200,
      
progressBar'progress' military.id,
      
countrymilitary.country_val,
      
onChange: function(value) {
        if (
intval(value)) {
          
show('details' military.id);
          
military.uiUnit.setURL('select_ajax.php?act=a_get_units&country=' value);
        } else {
          
hide('details' military.id);
        }
      }
    });

    
g('military' military.id).style.display 'block';
    if (
intval(military.country)) {
      
g('details' military.id).style.display 'block';
    }
    if (
intval(military.unit)) {
      
g('all' military.id).style.display 'block';
    }

    return 
military;
  },

  
addMilitary: function() {
    if (
cur.militariesCount >= 5) {
      return 
false;
    }
    var 
new_military = {
      
id: -(++cur.globalCounter),
      
countrycur.selData.mem.country,
      
country_valcur.selData.mem.country_val,
      
unit0,
      
unit_val'',
      
start0,
      
finish0
    
};
    
ge('militaries').appendChild(this.genMilitaryRow(new_military.id));
    
new_military this.initMilitaryRow(new_military);
    
cur.militaries.push(new_military);
    ++
cur.militariesCount;
    if (
cur.militariesCount >= 5) {
      
hide('add_military_link');
    }
    return 
false;
  },

  
getIndex: function(dataid) {
    for (var 
0data.length; ++i) {
      if (
data[i].id == id) {
        return 
i;
      }
    }
    return 
false;
  },

  
deleteMilitary: function(id) {
    --
cur.militariesCount;
    
show('add_military_link');
    if (
intval(ge('unit' id).value)) {
      
hide('content' id);
      
ge('deleted' id).firstChild.innerHTML getLang('profileEdit_military_will_be_deleted');
      
show('deleted' id);
    } else {
      var 
index this.getIndex(cur.militariesid);
      
cur.militaries[index] = cur.militaries[cur.militaries.length 1];
      
cur.militaries.pop();
      
ge('military' id).parentNode.removeChild(ge('military' id));
      if (
cur.militaries.length == 0) {
        
this.addMilitary();
      }
    }
    return 
false;
  },

  
restoreMilitary: function(id) {
    if (
cur.militariesCount >= 5) {
      return 
false;
    }
    
hide('deleted' id);
    
show('content' id);
    ++
cur.militariesCount;
    if (
cur.militariesCount >= 5) {
      
hide('add_military_link');
    }
    return 
false;
  },

  
addFields: function() {
    var 
params arguments[0];
    var 
id arguments[1];
    var 
index arguments[2];
    for (var 
3arguments.length; ++i) {
      if (
intval(ge(arguments[i] + id).value)) {
        
params[arguments[i] + index] = ge(arguments[i] + id).value;
      }
    }
    return 
params;
  },

  
saveMilitaries: function(btn) {
    var 
params = {act'a_save_military'hashge('hash').value};
    for (var 
0cur.militaries.length; ++i) {
      var 
id cur.militaries[i].id;
      
params['id' i] = id;
      if (
isVisible('content' id) && intval(ge('unit' id).value)) {
        
params this.addFields(paramsidi'country''unit''start''finish');
        if (
ge('unit' id '_custom').value.length) {
          
params['unit' '_custom'] = ge('unit' id '_custom').value;
        }
      } else {
        
params['deleted' i] = 1;
      }
    }

    var 
doneHandler = function(response) {
      var 
to_remove = [];
      for (var 
0cur.militaries.length; ++i) {
        var 
new_military_id response['res' i];
        if (
intval(new_military_id)) {
          
cur.militaries[i] = this.updateMilitary(cur.militaries[i], new_military_idge('militaries'));
        } else {
          
to_remove.push(i);
        }
      }
      for (var 
0to_remove.length; ++i) {
        var 
index to_remove[i];
        
ge('military' cur.militaries[index].id).parentNode.removeChild(ge('military' cur.militaries[index].id));
        
cur.militaries[index] = cur.militaries[cur.militaries.length 1];
        for (var 
1to_remove.length; ++j) {
          if (
to_remove[j] == cur.militaries.length 1) {
            
to_remove[j] = index;
          }
        }
        
cur.militaries.pop();
      }
      
cur.militariesCount cur.militaries.length;
      if (
cur.militariesCount >= 5) {
        
hide('add_military_link');
      } else {
        
show('add_military_link');
      }
      if (!
cur.militariesCount) {
        
this.addMilitary();
      }
    }

    
ajax.post('al_profileEdit.php'params, {
      
onDone: function (mil_data) {
        
doneHandler.call(ProfileEditorMilmil_data);
        
ProfileEditor.showMsg(getLang('profileEdit_military_saved'));
      },
      
showProgresslockButton.pbind(btn),
      
hideProgressunlockButton.pbind(btn)
    });
    return 
false;
  },

  
updateMilitary: function(old_militarynew_military_idparent) {
    
old_military.country old_military.uiCountry.val();
    
old_military.country_val old_military.uiCountry.val_full();
    
old_military.unit old_military.uiUnit.val();
    
old_military.unit_val old_military.uiUnit.val_full();
    
old_military.start old_military.uiStart.val();
    
old_military.finish old_military.uiFinish.val();

    var 
new_elem this.genMilitaryRow(new_military_id);
    var 
old_elem ge('military' old_military.id);
    
old_military.id new_military_id;
    
new_military this.initMilitaryRow(old_militarynew_elem);
    
parent.replaceChild(new_elemold_elem);

    return 
new_military;
  },

  
militaryChanged: function(military) {
    return !
isVisible('content' military.id) ||
           
military.country != military.uiCountry.val() || military.unit != military.uiUnit.val() ||
           
military.start != military.uiStart.val() || military.finish != military.uiFinish.val();
  }
};

try{
stManager.done('profile_edit_mil.js');}catch(e){}
?>
Онлайн: 1
Реклама