Skip to content

Instantly share code, notes, and snippets.

@andywenk
Created December 14, 2009 15:41
Show Gist options
  • Save andywenk/256127 to your computer and use it in GitHub Desktop.
Save andywenk/256127 to your computer and use it in GitHub Desktop.
JooseClass("Hotel", {
has: {
formdiv: {is: "rw"},
validate: {is: "ro", init: function() { return new Validate() }}
},
methods: {
search: function (id, site) {
var div = $('hotels_list');
var params = this.get_params_json_and_id(id);
var url = '/regshop/' + site + '/search/id/' + id + '/params/' + encodeURIComponent(params) ;
new Ajax.Request(url, {
method: 'post',
onSuccess: function (transport) {
div.innerHTML = transport.responseText;
}
});
},
search_error: function () {
},
get_params: function() {
var params = {};
this.getFormdiv().each(function(elem) {
params[elem.id] = elem.value;
});
return params;
},
get_params_json_and_id: function(id) {
var params = this.get_params()
params['id'] = id;
params = Object.toJSON(params);
return params;
},
reset: function (id, site) {
this.reset_form_values();
var params = this.get_params_json_and_id(id);
var url = '/regshop/'+site+'/search/id/' + id + '/params/' + encodeURIComponent(params);
new Ajax.Request(url, {
method: 'post',
onSuccess: function (transport) {
$('hotels_list').innerHTML = transport.responseText;
}
});
},
checkbox: function (id, date) {
var i;
for(i = 1; i <= 3; i += 1) {
if(i == id) continue;
$('rooms[' + i + '][' + date + ']').checked = false;
}
},
reset_form_values: function () {
var val;
var params = {};
this.getFormdiv().each(function(val) {
if(val.id.match(/hotel_sorting$/)) {
$(val.id).value = 'name';
} else if(val.id.match(/count_rooms$/)) {
$(val.id).value = '1';
} else {
$(val.id).value = '';
}
});
}
},
before: {
search: function() {
console.info('hallo');
//var valid = this.getValidate();
//valid.reset_message();
}
},
around: {
search: function() {
//var params = this.get_params();
console.info('hallo2');
}
}
});
JooseClass("Validate", {
methods: {
is_empty: function(item) {
return (item == undefined || item == '' || item == null) ? true : false;
},
error_message: function(msg, type) {
this.resetMessage();
return '<strong><span class="' + type + '">' + msg + '</span></strong>';
},
reset_message: function(){
console.info('adfv');
$('msg').innerHTML = 'drgthdr';
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment