Glyde.BuyReceiptWidget=Class.create(Glyde.widgets.Widget,{
MESSAGE_PURCHASE_CANCELLED:'buy_receipt_widget:purchase_cancelled',
UNDO_MESSAGE_DURATION_IN_SECONDS:30,
initialize:function($super,element,server_data,glu,no_share_widget){
$super(element);
if(server_data.html){
this._element.innerHTML=server_data.html;
}
if(server_data.success){
this._purchase_order_id=server_data.purchase_order_id;
var oops_button=this.$$first('.oops_button');
this._oops_button_click_handler=this._handle_undo_clicked.bindAsEventListener(this);
oops_button.observe('click',this._oops_button_click_handler);
var timer_ms=this.UNDO_MESSAGE_DURATION_IN_SECONDS*1000;
this._undo_timer=setTimeout(this._handle_undo_expired.bind(this),timer_ms);
if(!no_share_widget){
var share_widget_node=this.$$first('.share_buttons');
this._share_widget=new Glyde.widgets.ShareButtonsBuyWidget(share_widget_node,glu,server_data.percent_off_msrp);
}
}
},
cancel_timer:function(){
if(this._undo_timer){
clearTimeout(this._undo_timer);
this._undo_timer=null;
}
},
share_buttons_widget:function(){
return this._share_widget;
},
_handle_undo_clicked:function(event){
event.target.stopObserving('click',this._oops_button_click_handler);
var on_complete=function(resp,o){
var data=resp.responseJSON;
if(data.success){
this._show_purchase_cancelled_message();
Glyde.notify.publish(this.MESSAGE_PURCHASE_CANCELLED,{});
}else{
this._show_soft_error_message();
Glyde.page.handle_server_errors(data);
}
}.bind(this);
Glyde.BuyReceiptWidget.send_cancel_request(this._purchase_order_id,
this._purchase_orders_cancel_url(),
on_complete);
},
_purchase_orders_cancel_url:function(){
return'/purchase_orders/cancel';
},
_clear_undo:function(){
clearTimeout(this._undo_timer);
this._hide_undo_button();
},
_hide_undo_button:function(){
var oops_button=this.$$first('.oops_button');
if(oops_button){oops_button.undisplay();}
},
_show_purchase_cancelled_message:function(){
this._clear_undo();
this.$$first('.receipt_header').update('Purchase Cancelled');
this.$$first('.estimated_delivery').vhide();
},
_show_soft_error_message:function(){
this._clear_undo();
this.$$first('.errors_in_oops').display();
},
_handle_undo_expired:function(){
this._hide_undo_button();
}
});
Glyde.BuyReceiptWidget.send_cancel_request=function(purchase_order_id,purchase_orders_cancel_url,on_complete){
var options={
parameters:{id:purchase_order_id},
onComplete:(on_complete||P.emptyFunction)
};
new Ajax.Request(purchase_orders_cancel_url,options);
};
Glyde.PriceAdjuster=Class.create({
increment:25,
interval:{
slow:150,
fast:50,
init_delay:1,
fast_delay:1500
},
timeout_id:null,
start_time:null,
interval_id:null,
interval_fast_id:null,
initialize:function(containing_element,onstop_callback,opts){
this._containing_element=containing_element;
this.value=(opts?opts.starting:null)||500;
this.ceiling=(opts?opts.ceiling:null)||null;
this.floor=(opts?opts.floor:null)||null;
this.uniq_id=(opts?opts.uniq_id_suffix:null)||'';
this.price_span_class=(opts?opts.span_class:null)||'listing_price_text'+this.uniq_id;
this.down_button_class=(opts?opts.down_button_class:null)||'price_down'+this.uniq_id;
this.up_button_class=(opts?opts.up_button_class:null)||'price_up'+this.uniq_id;;
this.onstop=onstop_callback||Prototype.emptyFunction;
this._set_up_button_handlers();
},
set_value:function(new_value,ceiling,floor,hidden_p){
this.value=new_value;
this.ceiling=ceiling||null;
this.floor=floor||null;
if(!hidden_p){
this.display();
}
},
is_at_ceiling:function(){
return this.value==this.ceiling;
},
is_below_ceiling:function(){
return this.value<this.ceiling;
},
is_at_price:function(comparable){
return this.value==comparable;
},
is_below_price:function(comparable){
return this.value<comparable;
},
is_above_price:function(comparable){
return this.value>comparable;
},
is_at_floor:function(){
return this.value==this.floor;
},
text_elem:function(){
return this._containing_element.select('.'+this.price_span_class)[0];
},
start_up:function(){
this.start('up');
},
stop_up:function(){
this.stop('up');
},
start_down:function(){
this.start('down');
},
stop_down:function(){
this.stop('down');
},
start:function(direction){
if(this.is_running())this.kill();
this.start_time=this._now();
this._current_direction=direction;
var method=(direction=='up'?'increase':'decrease');
var fun=function(){
this.interval_id=setInterval(this[method].bind(this),this.interval.slow);
};
this.timeout_id=setTimeout(fun.bind(this),this.interval.init_delay);
},
is_running:function(){
return(this.start_time!=null);
},
kill:function(){
this._clear_interval();
this._clear_fast_interval();
this.start_time=null;
this._current_direction=null;
},
stop:function(direction){
this.kill();
if(this.timeout_id){
clearTimeout(this.timeout_id);
this.timeout_id=null;
if(direction=='up'){
this._increase_with_checks();
}else{
this._decrease_with_checks();
}
}
this.onstop(this.value);
},
increase:function(){
this.timeout_id=null;
this._possibly_accelerate('_increase_with_checks');
this._increase_with_checks();
},
_increase_with_checks:function(){
try{
this._increase();
}catch(e){
if(e.type&&e.type=='increase_exception'){
this.stop('up');
this._open_max_alert();
}else{
throw e;
}
}
},
_up_button:function(){
return this._containing_element.select('.'+this.up_button_class)[0];
},
_open_max_alert:function(){
if(typeof GlydeAlert!='undefined'&&(!this._max_alert||!this._max_alert.is_open())){
var u_b=this._up_button();
this._max_alert=new GlydeAlert('You\'ve hit the maximum price for this item.',u_b,'Max Price Alert',{position_preference:Glyde.Dialog.prototype.POSITION_ABOVE});
}
Glyde.notify.publish(Glyde.PriceAdjuster.MAX_PRICE_EVENT);
},
_increase:function(){
if(this.value+this.increment<=this.ceiling){
this.value+=this.increment;
this.display();
}else{
throw{reason:'hit ceiling',type:'increase_exception'};
}
},
decrease:function(){
this.timeout_id=null;
this._possibly_accelerate('_decrease_with_checks');
this._decrease_with_checks();
},
_decrease_with_checks:function(){
try{
this._decrease();
}catch(e){
if(e.type&&e.type=='decrease_exception'){
this.stop('down');
this._open_min_alert();
}
else throw e;
}
},
_down_button:function(){
return this._containing_element.select('.'+this.down_button_class)[0];
},
_open_min_alert:function(){
if(typeof GlydeAlert!='undefined'&&(!this._min_alert||!this._min_alert.is_open())){
var d_b=this._down_button();
this._min_alert=new GlydeAlert('You\'ve hit the minimum price for this item.',d_b,'Min Price Alert',{position_preference:Glyde.Dialog.prototype.POSITION_BELOW});
}
Glyde.notify.publish(Glyde.PriceAdjuster.MIN_PRICE_EVENT);
},
_decrease:function(){
if(this.value-this.increment>=this.floor){
this.value-=this.increment;
this.display();
}else{
throw{reason:'hit floor',type:'decrease_exception'};
}
},
display:function(){
this.text_elem().firstChild.nodeValue=Glyde.Money.format_cents(this.value);
var e=this._down_button();
if(this.value==0){
this.kill();
e.disabled=true;
}else{
e.disabled=false;
}
},
_doc_mouse_up:function(event){
if(this.is_running()){
this.stop(this._current_direction);
}
},
_up_key_down:function(event){
var foo;
switch(event.keyCode){
case Event.KEY_SPACE:
if(!this._up_space_down){
this._up_space_down=true;
this.start('up');
}
break;
case Event.KEY_TAB:
this.stop('up');
this._up_space_down=false;
break
}
},
_up_key_up:function(event){
if(event.keyCode==Event.KEY_SPACE){
this.stop('up');
this._up_space_down=false;
}
},
_down_key_down:function(event){
var foo;
switch(event.keyCode){
case Event.KEY_SPACE:
if(!this._down_space_down){
this._down_space_down=true;
this.start('down');
}
break;
case Event.KEY_TAB:
this.stop('up');
this._up_space_down=false;
break;
}
},
_down_key_up:function(event){
if(event.keyCode==Event.KEY_SPACE){
this.stop('down');
this._down_space_down=false;
}
},
_clear_interval:function(){
clearInterval(this.interval_id);
this.interval_id=null;
},
_clear_fast_interval:function(){
clearInterval(this.interval_fast_id);
this.interval_fast_id=null;
},
_possibly_accelerate:function(method){
if(this._is_button_still_down()&&!this._is_going_fast()){
if(this._is_time_to_accelerate()){
this._accelerate(method);
}
}
},
_accelerate:function(method){
this._clear_interval();
this.interval_fast_id=setInterval(this[method].bind(this),this.interval.fast);
},
_is_time_to_accelerate:function(){
return(this._now()-this.start_time>this.interval.fast_delay);
},
_is_going_slowly:function(){
return this.interval_id;
},
_is_going_fast:function(){
return this.interval_fast_id;
},
_is_button_still_down:function(){
return this.interval_id;
},
_now:function(){
return new Date().getTime();
},
_set_up_button_handlers:function(){
this._down_button_handlers();
this._up_button_handlers();
Event.observe(document.body,'mouseup',this._doc_mouse_up.bindAsEventListener(this),false);
Event.observe(document.body,'mouseout',this._doc_mouse_up.bindAsEventListener(this),false);
},
_down_button_handlers:function(){
var b=this._down_button();
if(b){
b.onmousedown=this.start_down.bindAsEventListener(this);
b.onmouseup=this.stop_down.bindAsEventListener(this);
b.onkeydown=this._down_key_down.bindAsEventListener(this);
b.onkeyup=this._down_key_up.bindAsEventListener(this);
}
},
_up_button_handlers:function(){
var b=this._up_button();
if(b){
b.onmousedown=this.start_up.bindAsEventListener(this);
b.onmouseup=this.stop_up.bindAsEventListener(this);
b.onkeydown=this._up_key_down.bindAsEventListener(this);
b.onkeyup=this._up_key_up.bindAsEventListener(this);
}
}
});
Glyde.PriceAdjuster.MAX_PRICE_EVENT='price_adjuster:max_price_event';
Glyde.PriceAdjuster.MIN_PRICE_EVENT='price_adjuster:min_price_event';
Glyde.widgets.ConditionSelectorWidget=Class.create(Glyde.widgets.Widget,{
DOM_CLASS:'condition_selector_widget',
legend_elem_id:'condition_legend',
initialize:function($super,element,on_change_callback,condition_type,default_condition,description_function){
$super(element);
this._instance_id=Glyde.widgets.ConditionSelectorWidget.instance_id++;
this._radio_input_name='sku[condition_id]_'+this._instance_id;
this._condition_type=condition_type;this._description_function=description_function||'new_listing_desc';
this._on_change_callback=on_change_callback||Glyde.empty_function;
this._render();
if(default_condition){
this.select(default_condition,condition_type);
}
},
_set_click_handlers:function(){
$$('.radio_box').each(function(el){
el.observe('click',this._on_container_click.bindAsEventListener(this,el));
}.bind(this));
},
_on_container_click:function(event,container_elem){
var input_element=container_elem.select('.radio_input')[0];
input_element.checked=true;
this._on_change_callback();
},
_set_mouse_hover_handlers:function(){
var hover_class_name='radio_box_hover';
var self=this;
$A(this._elements()).each(function(el){
var container_element=el.parentNode.parentNode;
container_element.observe('mouseover',function(){
$(container_element).addClassName(hover_class_name);
this.$$('.description_box')[0].update(this.render_description_box(this._by_id(this._get_condition_id_from_element(container_element))));
}.bindAsEventListener(self));
container_element.observe('mouseout',function(){
$(container_element).removeClassName(hover_class_name);
this.$$('.description_box')[0].update(this.render_description_box(this._by_id(this.selected_id())));
}.bindAsEventListener(self));
});
},
_render:function(){
if(this._condition_type){
this._element.update(this.to_html());
this._set_click_handlers();
this._set_mouse_hover_handlers();
}
},
_get_condition_id_from_element:function(element){
return parseInt(element.className.match(/[0-9]./)[0]);
},
_set_text:function(){
if(!this._condition_type)return;
this._render();
this._description_elements().each(function(el){
var cond_id_class=$w(el.className).find(function(selector){
return selector.match(/condition_description_/);
});
var cond_id=parseInt(cond_id_class.replace(/condition_description_/,''));
var cond=this._by_id(cond_id);
var desc=cond[this._description_function].realEscapeHTML(true);
}.bind(this));
},
selected_value:function(){
return $A(this._elements()).detect(function(el){
return el.checked;
}).value;
},
selected_to_s:function(){
return this._by_id(this.selected_id()).name;
},
highlight_selected:function(id){
var selected_class_name='radio_box_selected';
if(this._current_selected_class){
var el=this.$$(this._current_selected_class)[0];
el.removeClassName(selected_class_name);
}
this._current_selected_class='.radio_box_'+(id||this.selected_id());
this.$$(this._current_selected_class)[0].addClassName(selected_class_name);
},
select:function(id,condition_type){
if(id&&condition_type){
this._condition_type=condition_type;
this._set_text();
this.$$('.sku_condition_id_'+id)[0].checked=true;
this.highlight_selected(id);
this.$$('.description_box')[0].update(this.render_description_box(this._by_id(this.selected_id())));
}
},
selected_id:function(){
return parseInt(this.selected_value());
},
set_title:function(title){
this.$$('.header')[0].innerHTML=title;
},
_conditions:function(){
return Glyde.Sku.conditions(this._condition_type);
},
_by_id:function(id){
return this._conditions().detect(function(cond){return cond.id==id;});
},
_elements:function(){
return this.$$('[name = "'+this._radio_input_name+'"]');
},
_description_elements:function(){
return this.$$('.radio_box .condition_description');
}
});
Glyde.widgets.ConditionSelectorWidget.instance_id=0;
Glyde.widgets.ConditionSelectorWidget.prototype.to_html=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="header"');_j.s('>Condition');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="contents"');_j.s('>');
var cond_html=this._conditions().inject('',function(acc,cond){
acc+=this.render_condition(cond);
return acc;
}
.bind(this));
_j.ns(cond_html);
_j.ns('<div');_j.s(' class="description_box"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
Glyde.widgets.ConditionSelectorWidget.prototype.render_condition=function(condition){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="'+('radio_box radio_box_'+condition.id)+'"');_j.s('>');
_j.ns('<div');_j.s(' class="radio_input_box"');_j.s('>');
_j.ns('<input');_j.s(' class="'+('radio_input sku_condition_id_'+condition.id)+'"');_j.s(' type="'+('radio')+'"');_j.s(' name="'+(this._radio_input_name)+'"');_j.s(' value="'+(condition.id)+'"');_j.s('>');
_j.ns('</input>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="label_and_description"');_j.s('>');
_j.ns('<div');_j.s(' class="'+('condition_label condition_label_'+condition.id)+'"');_j.s('>');
_j.ns(condition.name);
_j.ns('</div>');
_j.ns('<div');_j.s(' class="'+('condition_description condition_description_'+condition.id)+'"');_j.s('>');
_j.ns(condition[this._description_function].realEscapeHTML(true));
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
Glyde.widgets.ConditionSelectorWidget.prototype.render_description_box=function(condition){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="condition_name"');_j.s('>'+(condition.name+' Condition'));
_j.ns('</div>');
_j.ns('<div');_j.s(' class="condition_description"');_j.s('>'+(condition[this._description_function].escapeHTML(true)));
_j.ns('</div>');
return _j.v();
};
Glyde.widgets.PriceSelector=Class.create({
initialize:function(containing_element,glu,start_cents,start_condition_id){
this.transaction_fee_perc=10;
this._containing_element=containing_element;
this._adjuster=new Glyde.PriceAdjuster(containing_element,this._on_adjuster_stop.bind(this));
Glyde.AnchorButton.create_all_under('price_buttons');
this.reset(glu,start_cents,start_condition_id);
},
reset:function(glu,cents,condition_id,is_for_sale){
this._glu=glu;
this.cents=cents||0;
this._start_cents=cents||null;
this._start_condition_id=condition_id||null;
this._listing_is_for_sale=is_for_sale||false;
},
on_condition_change:function(cond_id){
if(!this._glu.is_sellable)return true;
this._cond_id=cond_id;
this._best_price=this._best_price_for_condition();this._sku=this._sku_for_condition();this._set_price(cond_id==this._start_condition_id);
this._set_text();
},
market_price_cents:function(){
return this._sku.market_price.cents;
},
_best_price_for_condition:function(){
var sku=this._best_sku_for_condition();
return sku?sku.best_price:null;
},
_best_sku_for_condition:function(){
var skus=this._skus_with_legit_best_prices_among(this._skus_with_good_enough_condition());
return(skus.length>0?skus.inject(skus[0],this._better_sku.bind(this)):null);
},
_skus_with_legit_best_prices_among:function(skus){
return skus.reject(function(s){return s.best_price.quantity<1;});
},
_better_sku:function(s1,s2){
switch(Glyde.cmp(s1.best_price.cents,s2.best_price.cents)){
case-1:return s1;
case 1:return s2;
default:return(s1.condition_id<s2.condition_id)?s1:s2;
}
},
_skus_with_good_enough_condition:function(){
return this._glu.skus.select(function(s){
return s.condition_id<=this._cond_id;}.bind(this));
},
_sku_for_condition:function(){
if(this._glu){
return this._glu.skus.detect(function(sku){
return(sku.condition_id==this._cond_id);
}.bind(this));
}else{
return null;
}
},
_on_adjuster_stop:function(new_cents){
this.cents=new_cents;
this._set_text();
},
_set_price:function(use_start_cents){
if(this._start_cents&&this._listing_is_for_sale&&use_start_cents){
this.cents=this._start_cents;
}else{
this.cents=this._cents_from_suggested();
}
this._set_adjuster();
},
_cents_from_suggested:function(){
return parseInt(this._sku.suggested_price.price.cents);
},
_num_listings_at_price:function(price){
var apc=this._sku.ask_price_counts.detect(function(a){
return(a.cents==price);
});
return apc?apc.count:0;
},
_set_adjuster:function(){
this._adjuster.set_value(this.cents,
this._sku.suggested_price.ceiling.cents,
this._sku.floor_price.cents);
},
_best_price_elem:function(){
return this._containing_element.select('.best_price')[0];
},
_set_text:function(){
this.market_price=this._sku.market_price.cents;
var bp_elem=this._best_price_elem();
if(bp_elem){
this._set_text_for_diff_prices();
}
this._change_color_of_price_adjuster_price_if_necessary();
},
_change_color_of_price_adjuster_price_if_necessary:function(){
if(this._adjuster.is_above_price(this.market_price)){
this._adjuster.text_elem().addClassName('above_market_price');
}else{
this._adjuster.text_elem().removeClassName('above_market_price');
}
},
_num_asks_below_at_and_above:function(cents){
var above=0;
var below=0;
var at=0;
this._sku.ask_price_counts.each(function(apc){
var ask_cents=apc.cents;
var ask_count=apc.count;
switch(Glyde.cmp(ask_cents,cents)){
case 1:above+=ask_count;break;
case-1:below+=ask_count;break;
default:at+=ask_count;
}
});
var curr_cents=this._start_cents;
if(this._listing_is_for_sale&&this._sku.condition_id==this._start_condition_id){
switch(Glyde.cmp(curr_cents,cents)){
case 1:above-=1;break;
case-1:below-=1;break;
default:at-=1;
}
}
return{
above:above,
below:below,
at:at
};
},
_set_text_for_diff_prices:function(){
var bp_elem=this._best_price_elem();
if(bp_elem){
bp_elem.innerHTML=this._price_legend();
}
},
_ordinalize:function(num){
num=parseInt(num);
if(num=='NaN')return null;
if(num==1)return"first";
var mod_100=num%100;
switch(mod_100){
case 11:
case 12:
case 13:
return(num+'th');
default:
var mod_10=num%10;
switch(mod_10){
case 1:return num+'st';
case 2:return num+'nd';
case 3:return num+'rd';
default:return num+'th';
}
}
},
_price_legend:function(){
this.sp=this._sku.suggested_price.price.cents;
this.sp_asks=this._num_asks_below_at_and_above(this.sp);
this.total_asks=this._num_asks_below_at_and_above(this.cents);
this.mp_asks=this._num_asks_below_at_and_above(this.market_price);
this._at_or_below=this.total_asks.at+this.total_asks.below;
this._sp_at_or_below=this.sp_asks.at+this.sp_asks.below;
this._mp_at_or_below=this.mp_asks.at+this.mp_asks.below;
this._current_price_difference_from_market=Math.abs(this.market_price-this.cents);
this.set_v_sug=Glyde.cmp(this._adjuster.value,this.sp);
this.set_v_market=Glyde.cmp(this._adjuster.value,this.market_price);
var any_in_sku=(this.total_asks.at+this.total_asks.below+this.total_asks.above)>0;
if(!this._has_any_other_listings()){
return this._no_asks();
}else if(this.sp==this.market_price){
return this._sp_equals_mp();
}else if(any_in_sku&&this.sp<this.market_price){
if(this.cents>this.market_price){
return this._above_market();
}else if(this.cents==this.market_price){
return this._at_market();
}else if(this.cents==this.sp){
return this._at_sugg();
}else if(this.cents<this.sp){
return this._below_sugg();
}
}else{
return this._default_language();
}
},
_render_mailer_cost:function(){
return'$'+Glyde.Money.format_cents(this._mailer_cost());
},
_render_transaction_fee:function(){
return'$'+Glyde.Money.format_cents(Math.floor(((this.transaction_fee_perc/100)*this.cents)));
},
_mailer_cost:function(){
return this._sku.mailer_cost.cents;
},
_render_proceeds:function(){
var proceeds=this._proceeds_cents();
return'$'+Glyde.Money.format_cents(proceeds);
},
_proceeds_info_title:function(){
var html='$'+Glyde.Money.format_cents(this.cents)+' -  '+this._render_transaction_fee()+'(10% fee) - '+this._render_mailer_cost()+'(mailer cost) = '+this._render_proceeds();
return html;
},
_proceeds_cents:function(){
return this.cents-Math.floor(((this.transaction_fee_perc/100)*this.cents))-this._mailer_cost();
},
_has_any_other_listings:function(){
return(this._sku&&this._sku.ask_price_counts.any(function(apc){
return apc.count>0;
}));
},
_be:function(num){
return(num==1?'is':'are');
},
_plural:function(num,word){
return(num==1?word:word+'s');
},
_item_s:function(num){
return this._plural(num,'item');
}
});
Glyde.widgets.PriceSelector.prototype._no_asks=function(){
var _j=new Jaml();
var c=(this.set_v_sug==1)?'above_market_text':'';
_j.ns('<ul');_j.s(' class="market_price_list_text '+(c)+'"');_j.s('>');
_j.ns(this._first_line());
switch(this.set_v_sug){
case 0:{
_j.ns(this._first_to_sell_text());
break;
}
case 1:{
_j.ns(this._above_market_text());
break;
}
default:{
_j.ns(this._first_to_sell_text());
break;
}
}
_j.ns(this._render_proceeds_info());
_j.ns('</ul>');
return _j.v();
};
Glyde.widgets.PriceSelector.prototype._sp_equals_mp=function(){
var _j=new Jaml();
var c=(this.set_v_sug==1)?'above_market_text':'';
_j.ns('<ul');_j.s(' class="market_price_list_text '+(c)+'"');_j.s('>');
_j.ns(this._first_line());
if(this._mp_at_or_below==0){
switch(this.set_v_sug){
case 0:{
_j.ns(this._first_to_sell_text());
break;
}
case 1:{
_j.ns(this._above_market_text());
break;
}
default:{
_j.ns(this._first_to_sell_text());
break;
}
}
}
else{
switch(this.set_v_sug){
case 0:{
_j.ns('<li');_j.s('>');
_j.ns('Currently there');
_j.ns(this._be(this._mp_at_or_below));
_j.ns(this._mp_at_or_below);
_j.ns(this._item_s(this._mp_at_or_below));
_j.ns('ahead of you at this price.');
_j.ns('</li>');
break;
}
case 1:{
_j.ns(this._above_market_text(this._mp_at_or_below));
break;
}
default:{
if(this._at_or_below==0){
_j.ns(this._first_to_sell_text());
}
else{
_j.ns('<li');_j.s('>');
_j.ns('Currently there');
_j.ns(this._be(this._at_or_below));
_j.ns(this._at_or_below);
_j.ns(this._item_s(this._at_or_below));
_j.ns('ahead of you at this price.');
_j.ns('</li>');
}
break;
}
}
}
_j.ns(this._render_proceeds_info());
_j.ns('</ul>');
return _j.v();
};
Glyde.widgets.PriceSelector.prototype._above_suggested_text=function(at_or_below){
var _j=new Jaml();
_j.ns('<li');_j.s('>');
_j.ns('<span');_j.s(' class="above_market_text"');_j.s('>');
_j.ns('Your item may not sell.');
_j.ns(this._lower_to_recommended_text());
_j.ns('</span>');
_j.ns('</li>');
return _j.v();
};
Glyde.widgets.PriceSelector.prototype._lower_to_recommended_text=function(at_or_below){
var _j=new Jaml();
_j.ns('Lower Your Price to the Recommended Price of');
_j.ns('$'+Glyde.Money.format_cents(this.sp));
_j.ns('and it will be the');
_j.ns(at_or_below>0?this._ordinalize(at_or_below+1):'first');
_j.ns('to sell.');
return _j.v();
};
Glyde.widgets.PriceSelector.prototype._currently_text=function(at_or_below){
var _j=new Jaml();
_j.ns('<li');_j.s('>');
_j.ns('Currently there');
_j.ns(this._be(at_or_below));
_j.ns(this._at_or_below);
_j.ns(this._item_s(at_or_below));
_j.ns('ahead of you at this price.');
_j.ns(this._lower_to_recommended_text(at_or_below));
_j.ns('</li>');
return _j.v();
};
Glyde.widgets.PriceSelector.prototype._above_market=function(){
var _j=new Jaml();
_j.ns('<ul');_j.s(' class="market_price_list_text above_market_text"');_j.s('>');
_j.ns(this._first_line());
_j.ns(this._above_suggested_text(this._sp_at_or_below));
_j.ns(this._render_proceeds_info());
_j.ns('</ul>');
return _j.v();
};
Glyde.widgets.PriceSelector.prototype._at_market=function(){
var _j=new Jaml();
_j.ns('<ul');_j.s(' class="market_price_list_text"');_j.s('>');
_j.ns(this._first_line());
_j.ns(this._currently_text(this._sp_at_or_below));
_j.ns(this._render_proceeds_info());
_j.ns('</ul>');
return _j.v();
};
Glyde.widgets.PriceSelector.prototype._at_sugg=function(){
var _j=new Jaml();
_j.ns('<ul');_j.s(' class="market_price_list_text"');_j.s('>');
_j.ns(this._first_line());
_j.ns(this._at_suggested_text(this._at_or_below));
_j.ns(this._render_proceeds_info());
_j.ns('</ul>');
return _j.v();
};
Glyde.widgets.PriceSelector.prototype._below_sugg=function(){
var _j=new Jaml();
_j.ns('<ul');_j.s(' class="market_price_list_text"');_j.s('>');
_j.ns(this._first_line());
if(this._at_or_below==0){
_j.ns(this._first_to_sell_text());
}
else{
_j.ns('<li');_j.s('>');
_j.ns('Currently there');
_j.ns(this._be(at_or_below));
_j.ns(this._at_or_below);
_j.ns(this._item_s(at_or_below));
_j.ns('ahead of you at this price.');
_j.ns('</li>');
}
_j.ns(this._render_proceeds_info());
_j.ns('</ul>');
return _j.v();
};
Glyde.widgets.PriceSelector.prototype._default_language=function(){
var _j=new Jaml();
_j.ns('<ul');_j.s(' class="market_price_list_text"');_j.s('>');
_j.ns(this._first_line());
_j.ns(this._render_proceeds_info());
_j.ns('</ul>');
return _j.v();
};
Glyde.widgets.PriceSelector.prototype._first_line=function(){
var _j=new Jaml();
if(this.cents==this.market_price){
_j.ns('<li');_j.s('>');
_j.ns('Your Price is at the Market Price of');
_j.ns('$'+Glyde.Money.format_cents(this.market_price));
_j.ns('</li>');
}
else{
_j.ns('<li');_j.s('>');
_j.ns('Your Price is');
_j.ns('$'+Glyde.Money.format_cents(this._current_price_difference_from_market));
_j.ns(this.set_v_market==-1?'below':'above');
_j.ns('the Market Price of');
_j.ns('$'+Glyde.Money.format_cents(this.market_price)+'.');
_j.ns('</li>');
}
return _j.v();
};
Glyde.widgets.PriceSelector.prototype._render_proceeds_info=function(){
var _j=new Jaml();
_j.ns('<li');_j.s('>');
_j.ns('<div');_j.s(' class="proceeds_info"');_j.s('>');
_j.ns('<div');_j.s(' class="proceeds_info_text"');_j.s('>');
_j.ns('Your proceeds will be');
_j.ns(this._render_proceeds());
_j.ns('</div>');
var src=Glyde.image.fully_qualified_url('images/information.png');
var title=this._proceeds_info_title();
_j.ns('<div');_j.s(' id="proceeds_info_icon"');_j.s(' title="'+(title)+'"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</li>');
return _j.v();
};
Glyde.widgets.PriceSelector.prototype._first_to_sell_text=function(){
var _j=new Jaml();
_j.ns('<li');_j.s('>Your item will be the first to sell.');
_j.ns('</li>');
return _j.v();
};
Glyde.widgets.PriceSelector.prototype._above_market_text=function(at_or_below){
var _j=new Jaml();
_j.ns('<li');_j.s('>');
_j.ns('<span');_j.s(' class="above_market_text"');_j.s('>');Jaml.x();
_j.ns('Your item may not sell. Lower Your Price to the market price of');
_j.ns('$'+Glyde.Money.format_cents(this.sp));
_j.ns('and it will be the');
_j.ns(this._ordinalize((at_or_below||0)+1));
_j.ns('to sell.');
Jaml.x();_j.ns('</span>');
_j.ns('</li>');
return _j.v();
};
Glyde.widgets.PriceSelector.prototype._at_suggested_text=function(at_or_below){
var _j=new Jaml();
_j.ns('<li');_j.s('>');
_j.ns('Your item will be the');
_j.ns(this._ordinalize(at_or_below+1));
_j.ns('to sell at the Recommended Price of');
_j.ns('$'+Glyde.Money.format_cents(this.sp)+'.&nbsp;');
if(this._mp_at_or_below>0){
_j.ns('There are already');
_j.ns(this._mp_at_or_below);
_j.ns(this._item_s(this._mp_at_or_below));
_j.ns('at the current Market Price of');
_j.ns('$'+Glyde.Money.format_cents(this.market_price)+'.');
}
_j.ns('</li>');
return _j.v();
};
var Listing=Class.create({
modified_attrs:[],
initialize:function(data){
this._short=false;
this._init(data);
this._selected=false;
this._grid_show_details=false;
var options=[{'value':'not_for_sale','display_value':'Not for sale','selected_display_value':'&nbsp;'},
{'value':'for_sale','display_value':'For sale'}];
var selected_index=(data&&data.is_for_sale?1:0);
this.sell_select=new GlydeSelect('sell_box_'+this.attrs.id,options,
selected_index,true,'sell_box_select');
this.sell_select.onchange=this._handle_sell_change.bind(this);
},
_init:function(data){
this.attrs=data;
},
select:function(){
this._ui_select(true);
this._data_select(true);
},
deselect:function(){
this._ui_select(false);
this._data_select(false);
},
is_selected:function(){
return this._selected;
},
just_set_for_sale:function(){
return this.modified_attrs.include('is_for_sale')&&this.is_for_sale();
},
just_delisted:function(){
return this.modified_attrs.include('is_for_sale')&&!this.is_for_sale();
},
_ui_select:function(select){
var row_id='listing_row_'+this.attrs.id;
var row=$(row_id);
var check_box=new Glyde.widgets.Checkbox($('select_checkbox_'+this.attrs.id));
if(!row)return;
if(select){
row.className+=' selected';
check_box.checked(true);
}else{
row.className=row.className.replace(' selected','');
check_box.checked(false);
}
},
_data_select:function(select){
this._selected=select;
this.set_re_render();
},
update_attributes:function(data){
this.modified_attrs=this.find_modified_attrs(data);
this._init(data);
this.set_re_render();
},
find_modified_attrs:function(data){
var has_changed=function(dyad){
var name=dyad[0];
if(name=='updated_at'
||name=='created_at'
||name=='bs_created_at'
||name=='floor_price'){
return false;
}
if(name=='market_price'||name=='suggested_price'){
if(!data[name])return false;
return data[name].price.cents!=dyad[1].price.cents
}
var compare_value=data[name];
return dyad[1]!=compare_value;
};
return $H(this.attrs).select(has_changed.bind(this)).map(function(dyad){return dyad[0]});
},
open_condition:function(element){
this.open_listing_details_for_condition(element);
},
close_condition:function(new_condition){
if(new_condition)this._save_condition(new_condition);
if(Collection.get_instance().update_local_model){
$('cond_'+this.attrs.id).update(this._condition_inner_html());
}
},
_save_condition:function(new_condition){
if(this.condition()==new_condition){return;}
Collection.get_instance().restart_timer();
if(Collection.get_instance().update_local_model){
this.attrs.condition_id=new_condition;
this.set_re_render();
}
this.update_remote('condition_id',new_condition);
},
update_remote:function(attr,value){
var options={
method:'put',
parameters:'listing['+attr+']='+value,
onComplete:this.on_complete_update.bind(this)
};
Loading.show();
new Ajax.Request('/listings/'+this.attrs.id+'.js',options);
},
on_complete_update:function(resp,o){
var data=resp.responseJSON;
if(data&&data.success){
var listing=data.listing;
if(listing){
this.update_attributes(listing);
Glyde.notify.publish(Listing.EVENT_UPDATED,this);
}
}else{
Glyde.notify.publish(Listing.EVENT_UPDATE_FAILED,{json:data});
}
},
delete_remote:function(){
var options={
method:'delete',
onComplete:this.on_complete_delete.bind(this),
parameters:{ids:this.attrs.id}
};
Loading.show();
new Ajax.Request('/listings/dummy.js',options);
},
on_complete_delete:function(resp,o){
Loading.hide();
var data=resp.responseJSON;
if(data&&data.success){
Glyde.notify.publish(Listing.EVENT_DELETED,this);
}
},
mark_to_market_static:function(){
this.update_remote('cents',this.attrs.market_price.price.cents);
},
update_sell:function(bool){
this.set_re_render();
if(bool){
Collection.get_instance().listing_dialog.open(this,$('sell_box_'+this.attrs.id),'sell');
}else{
this.update_remote('is_for_sale','0');
}
},
_handle_sell_change:function(new_value){
var server_val=(new_value=='not_for_sale')?false:true;
this.update_sell(server_val);
},
save_price_condition_and_sell:function(glu,cents,condition,sell,
charity_percentage,charity_id,
error_callback){
if(sell&&!Glyde.user.is_reg_complete){
var extra_params={
listing_id:this.attrs.id,
cents:cents,
condition:condition,
charity_percentage:charity_percentage,
charity_id:charity_id,
return_to:location.href
};
Glyde.page.header.sell_checkout(glu,extra_params);
return;
}
var options={
method:'put',
parameters:{'listing[condition_id]':condition,
'listing[cents]':cents,
'listing[charity_id]':charity_id,
'listing[charity_percentage]':charity_percentage},
onComplete:this.on_complete_update.bind(this),
_on_error_callback:error_callback
};
if(sell){
options.parameters['listing[is_for_sale]']=1;
ConversionTracker.get_instance().track_item_for_sale(cents);
}
new Ajax.Request('/listings/'+this.attrs.id+'.js',options);
},
to_html:function(index_class){
if(this._list_html){
this._list_html=this._list_html.replace(/row listing \w*\b/,
'row listing '+index_class);
}else{
this._list_html=this._to_html(index_class||"");
}
return this._list_html;
},
to_grid:function(extra_class){
this._grid_html=(this._grid_html||this._to_grid(extra_class||""));
return this._grid_html;
},
_truncate:function(str,length){
if(typeof(str)!='string')return str;
return str.truncate_with_delimiters(length,' ');
},
_valid_price_str:function(price){
if(!price||price==-1)return'&mdash;';
var str=''+price;
if(str.indexOf('.')==-1)str=(parseInt(str)/100).toFixed(2);
if(str.indexOf('$')==-1)str='$'+str;
return str;
},
set_re_render:function(){
this._list_html=null;
this._grid_html=null;
},
can_be_displayed_as_for_sale:function(){
return(this.is_modifiable()&&this.is_sellable());
},
is_sellable:function(){
return this.attrs.is_sellable&&!this.is_deprecated();
},
is_modifiable:function(){
return this.attrs.is_modifiable;
},
is_deletable:function(){
return this.attrs.is_deletable;
},
suggested_price:function(){
return this.is_sellable()?this.attrs.suggested_price.price.cents:0;
},
is_buydown:function(){
return this.attrs.buydown_cents!=null;
},
buydown_price:function(){
return this.attrs.buydown_cents!=null?this.attrs.buydown_cents:this.price();
},
price:function(){
return this.attrs.cents;
},
cents:function(){
return this.price();
},
price_str:function(){
return"$"+Glyde.Money.format_cents(this.cents());},
bs_date_added_str:function(){
if(this.attrs.bs_created_at){
return this.attrs.bs_created_at.strftime("%m/%d/%y");
}else{
return'';
}
},
bs_orig_price_str:function(){
if(this.attrs.bs_original_price_cents){
return"$"+Glyde.Money.format_cents(this.attrs.bs_original_price_cents);}else{
return'N/A';
}
},
subtype_str:function(){
var subtype=this.attrs.type_for_vertical;
switch(this.attrs.vertical){
case'videos':
subtype=this.attrs.type_for_vertical.toLowerCase()=='dvd'?'':this.attrs.type_for_vertical;
break;
case'music':
subtype=this.attrs.type_for_vertical.toLowerCase()=='cd'?'':this.attrs.type_for_vertical;
break;
case'book':
case'game':
subtype=this.attrs.type_for_vertical
break;
}
return subtype;
},
date:function(){
return this.attrs.created_at;
},
is_deprecated:function(){
return this.attrs.deprecated;
},
is_for_sale:function(){
return this.attrs.is_for_sale&&!this.is_deprecated();
},
condition:function(){
return parseInt(this.attrs.condition_id);
},
condition_id:function(){
return this.attrs.condition_id;
},
condition_str:function(){
return(this._conditions()[this.condition()-1].name);
},
_conditions:function(){
if(!this._local_conditions){
this._local_conditions=Glyde.Sku.conditions(this.attrs.condition_type);
}
return this._local_conditions;
},
img_path:function(max_width,max_height){
return Glyde.image.cover_path(this,max_width,max_height);
},
status_sort:function(){
return this.status();
},
status:function(){
if(!this.is_for_sale()){
return"Not for Sale";
}else{
return this.attrs.availability;
}
},
status_str:function(){
var stat=this.status();
if(!(stat&&(stat.toLowerCase()=='for sale'||stat.toLowerCase()=='not for sale'))){
return stat;
}else{
return this.is_for_sale()?'For sale':'&nbsp;';
}
},
title:function(){
return this.attrs.title;
},
fetch_extra_info:function(callback){
var options={
method:'get',
parameters:{ids:[this.attrs.id]},
onComplete:this._on_complete_fetch_extra_info.bind(this),
_callback:callback
};
return new Ajax.Request('/listings/tranny_box_info',options);
},
_on_complete_fetch_extra_info:function(res,o){
var data=res.responseJSON;
if(data.success){
var listing=data.listings[0];
this.attrs.extra_info=listing.extra_info;
this.attrs.market_price=listing.market_price;
this.attrs.collection_id=listing.collection_id;
this.attrs.sku_id=listing.sku_id;
this.attrs.condition_id=listing.condition_id;
this.attrs.collection_owner=data.collection_owner;
this.attrs.is_modifiable=listing.is_modifiable;
this.attrs.is_for_sale=listing.is_for_sale;
this.attrs.is_sellable=listing.is_sellable;
this.attrs.deprecated=listing.deprecated;
this.attrs.product_type=listing.product_type;
this.attrs.creator=listing.creator;
this.attrs.cents=listing.cents;
this.attrs.buydown_cents=listing.buydown_cents;
if(listing.is_for_sale){
this.attrs.charity_percentage=listing.charity_percentage;
this.attrs.charity_name=listing.charity_name;
this.attrs.charity_proceeds=listing.charity_proceeds;
}
res.request.options._callback();
}else{
Glyde.page.handle_server_errors(data);
}
}
});
Listing.EVENT_UPDATED="listing:updated";
Listing.EVENT_DELETED="listing:deleted";
Listing.EVENT_UPDATE_FAILED="listing:update_failed";
Listing.DEFAULT_ADD_TAG_TEXT="Enter a tag";
Listing._extra_info_fetching=false;
Listing.prototype._condition_inner_html=function(){
var s=[];
s.push('<a id="cond_a_');s.push(this.attrs.id);s.push('" class="');s.push((this.is_sellable()?'':'not_sellable'));s.push('" onclick="Collection.get_instance().listing_dialog.open(Collection.get_instance().find_listing_by_id(\'');s.push(this.attrs.id);s.push('\'), this, \'edit\');">');
s.push('<div class="up_down_arrows"></div>');
s.push('');s.push(this.condition_str());s.push('');
s.push('</a>');
return s.join('');
}
Listing.prototype._render_genre_info=function(){
var s=[];
if(this.attrs.extra_info.genre_string){
var dir_label=this.attrs.extra_info.genre_string.indexOf(', ')>=0?'Genres':'Genre'
s.push('');s.push(this._render_extra_info_text_row(dir_label,this.attrs.extra_info.genre_string.truncate_with_delimiters(70,', ')));s.push('');
}
return s.join('');
}
Listing.prototype._render_title=function(){
var s=[];
s.push('<div class="title truncate" title="');s.push(this.attrs.title);s.push('">');
s.push('');s.push(this.attrs.title.truncate_with_delimiters(50));s.push('');
if(this.attrs.orig_release_year){
s.push('&nbsp;<span class="release_year">(');s.push(this.attrs.orig_release_year);s.push(')</span>');
}
if(this.attrs.extra_info.rating){
s.push('&nbsp;<span class="product_rating">');s.push(this.attrs.extra_info.rating);s.push('</span>');
}
s.push('</div>');
return s.join('');
}
Listing.prototype._render_extra_info_cd_track_list=function(){
var s=[];
if(this.attrs.extra_info&&this.attrs.extra_info.track_list){
var disc_track_lists=Glyde.Glu.cd_tracklist_to_disc_tracklists(this.attrs.extra_info.track_list)
for(var disc_index=0;disc_index<disc_track_lists.length;++disc_index){
var tl=disc_track_lists[disc_index]
var len=tl.length
s.push('');s.push(this._render_extra_info_cd_disc_track_list(tl,disc_index));s.push('');
}
}
return s.join('');
}
Listing.prototype._render_extra_info_cd_disc_track_list=function(tl,disc_index){
var s=[];
var mid=Math.ceil(tl.length/2)
s.push('<div class="disc_track_list ');s.push((disc_index>0)?'disc_track_list_latter':'');s.push('">');
var start=0
if(tl[0].track_num==0){
s.push('<div class="disc_number">Disc ');s.push(disc_index+1);s.push(' (');s.push(tl.length-1);s.push(' tracks)</div>');
start=1
mid+=1
}
s.push('<div class="column column_right">');
s.push('');s.push(this._render_extra_info_cd_disc_track_list_block(tl,mid,tl.length));s.push('');
s.push('</div>');
s.push('<div class="column column_left">');
s.push('');s.push(this._render_extra_info_cd_disc_track_list_block(tl,start,mid));s.push('');
s.push('</div>');
s.push('</div>');
return s.join('');
}
Listing.prototype._render_extra_info_cd_disc_track_list_block=function(tl,start,end){
var s=[];
for(var i=start;i<end;++i){
s.push('<div class="track">');
s.push('<div class="track_num sfloatl">');s.push(tl[i].track_num);s.push('.</div>');
s.push('<div class="track_name" title="');s.push(tl[i].title);s.push('">');s.push(tl[i].title.truncate_with_delimiters(20));s.push('</div>');
s.push('</div>');
}
return s.join('');
}
Listing.prototype._to_grid=function(){
var _j=new Jaml();
var dims=Glyde.image.cover_dimensions_for_max_w_h(this,100,140);
background_image_url=Glyde.image.fully_qualified_cover_url_for_max_w_h(this,100,140,'d');
_j.ns('<div');_j.s(' class="img_buffer"');_j.s(' style="'+("background-image: url('"+background_image_url+"')")+'"');_j.s('>');
_j.ns('<div');_j.s(' class="item_img"');_j.s(' id="'+("item_img_"+this.attrs.id)+'"');_j.s(' onclick="'+("Glyde.notify.publish('listing_more_info:clicked', { listing_id : "+this.attrs.id+"})")+'"');_j.s(' style="'+("background-image: url('"+background_image_url+"'); width: "+dims.width+"px; height: "+dims.height+"px;")+'"');_j.s(' title="'+(this.attrs.title)+'"');_j.s('>');
_j.ns('<div');_j.s(' class="info_image_wrapper"');_j.s('>');
_j.ns('<div');_j.s(' class="info_image"');_j.s(' id="'+("info_image_"+this.attrs.id)+'"');_j.s('>info');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
Listing.prototype._to_html=function(extra_class){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="'+("row listing "+extra_class+(this.is_selected()?'selected':'')+(this.is_sellable()?'':' not_sellable')+(this.is_modifiable()?'':' not_modifiable'))+'"');_j.s(' id="'+("listing_row_"+this.attrs.id)+'"');_j.s(' onclick="'+("Collection.get_instance().select_row('"+this.attrs.id+"', $('select_checkbox_"+this.attrs.id+"'), event)")+'"');_j.s('>');
_j.ns(Glyde.page.is_user_bulk_seller()?this._to_bulk_seller_inner_html():this._to_html_inner_html());
_j.ns('</div>');
return _j.v();
};
Listing.prototype._to_html_inner_html=function(){
var _j=new Jaml();
var is_modifiable=this.is_modifiable();
var is_deletable=this.is_deletable();
var is_sellable=this.can_be_displayed_as_for_sale();
var only_sellable=!this.is_modifiable()&&this.is_sellable();
var tr_len=40;
this.sell_select.set_selected_option(this.is_for_sale()?1:0);
_j.ns('<div');_j.s(' class="select_col col"');_j.s(' onclick="'+("Collection.get_instance().toggle_row_selection('"+this.attrs.id+"', $('select_checkbox_"+this.attrs.id+"'), event);")+'"');_j.s('>');
_j.ns('<div');_j.s(' class="checkbox_button_box"');_j.s('>');
_j.ns('<a');_j.s(' class="'+("button "+(this._selected?'checked':'')+((is_modifiable||is_deletable)?'':'disabled'))+'"');_j.s(' id="'+("select_checkbox_"+this.attrs.id)+'"');_j.s(' href="'+("javascript:void(0)")+'"');_j.s('>&nbsp;');
_j.ns('</a>');
_j.ns('</div>');
_j.ns('</div>');
var supply=this.is_for_sale()?'supply_sell':'supply_neither';
_j.ns('<div');_j.s(' class="title_col col"');_j.s('>');
_j.ns('<div');_j.s(' class="'+("title_text "+supply+" truncate_text")+'"');_j.s(' id="'+("title_"+this.attrs.id)+'"');_j.s(' onclick="'+("Glyde.notify.publish('listing_more_info:clicked', {listing_id: "+this.attrs.id+", id: this.id})")+'"');_j.s(' title="'+(this.attrs.title)+'"');_j.s('>');
_j.ns(this._truncate(this.attrs.title,tr_len));
_j.ns('</div>');
_j.ns('<div');_j.s(' class="info_image"');_j.s(' id="'+("info_image_"+this.attrs.id)+'"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="creator_col col"');_j.s('>');
_j.ns('<div');_j.s(' class="truncate_text creator_text"');_j.s(' id="'+("creator_"+this.attrs.id)+'"');_j.s(' title="'+(this.attrs.creator)+'"');_j.s('>');
_j.ns(this._truncate(this.attrs.creator,20));
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="type_col col"');_j.s('>');
_j.ns('<div');_j.s(' id="'+("type_"+this.attrs.id)+'"');_j.s('>');
_j.ns(this.attrs.product_type);
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="item_type_col col"');_j.s('>');
_j.ns('<div');_j.s(' class="truncate_text"');_j.s(' id="'+("item_type_"+this.attrs.id)+'"');_j.s(' title="'+(this.attrs.type_for_vertical)+'"');_j.s('>');
_j.ns(this._truncate(this.subtype_str(),14));
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="'+("sell_col col "+(is_sellable?'actionable':''))+'"');_j.s('>');
if(!is_sellable){
_j.ns('<div');_j.s(' class="truncate_text"');_j.s(' id="'+("sell_box_"+this.attrs.id)+'"');_j.s(' title="'+(this.status_str())+'"');_j.s('>');
_j.ns(this._truncate(this.status_str(),15));
_j.ns('</div>');
}
else{
_j.ns('<div');_j.s(' class="truncate_text"');_j.s(' id="'+("sell_box_"+this.attrs.id)+'"');_j.s('>');
_j.ns(this.sell_select.render_to_string());
_j.ns('</div>');
}
_j.ns('</div>');
if(is_modifiable){
_j.ns('<div');_j.s(' class="cond_col col actionable"');_j.s(' id="'+("cond_"+this.attrs.id)+'"');_j.s('>');
_j.ns(this._condition_inner_html());
_j.ns('</div>');
}
else{
_j.ns('<div');_j.s(' class="cond_col col"');_j.s(' id="'+("cond_"+this.attrs.id)+'"');_j.s('>');
_j.ns(this.condition_str());
_j.ns('</div>');
}
_j.ns('<div');_j.s(' class="comps_col col"');_j.s(' id="'+("release_comp_"+this.attrs.id)+'"');_j.s('>');
var cents=(is_sellable||only_sellable)?this.attrs.market_price.price.cents:-1;
_j.ns(this._valid_price_str(cents));
_j.ns('</div>');
if(is_modifiable&&this.is_for_sale()){
_j.ns('<div');_j.s(' class="price_col col actionable"');_j.s(' id="'+("price_"+this.attrs.id)+'"');_j.s('>');
_j.ns(this._price_inner_html());
_j.ns('</div>');
}
else{
_j.ns('<div');_j.s(' class="price_col col"');_j.s(' id="'+("price_"+this.attrs.id)+'"');_j.s('>');
if(is_modifiable){
_j.ns(this._price_inner_html());
}
else if(this.attrs.aasm_state!='not_for_sale'&&this.attrs.aasm_state!='for_sale'){
_j.ns('<div');_j.s(' class="price_text"');_j.s('>');
_j.ns('<span');_j.s(' class="sale_pending"');_j.s('>');
_j.ns(this.price_str());
_j.ns('</span>');
_j.ns('</div>');
}
else{
_j.ns('<div');_j.s(' class="price_text"');_j.s('>&nbsp;');
_j.ns('</div>');
}
_j.ns('</div>');
}
return _j.v();
};
Listing.prototype._to_bulk_seller_inner_html=function(){
var _j=new Jaml();
var is_modifiable=this.is_modifiable();
var is_sellable=this.is_modifiable()&&this.is_sellable();
var only_sellable=!this.is_modifiable()&&this.is_sellable();
this.sell_select.set_selected_option(this.is_for_sale()?1:0);
_j.ns('<div');_j.s(' class="select_col col"');_j.s(' onclick="'+("Collection.get_instance().toggle_row_selection('"+this.attrs.id+"', $('select_checkbox_"+this.attrs.id+"'), event);")+'"');_j.s('>');
_j.ns('<div');_j.s(' class="checkbox_button_box"');_j.s('>');
_j.ns('<a');_j.s(' class="'+("button "+(this._selected?'checked':'')+(is_modifiable?'':'disabled'))+'"');_j.s(' id="'+("select_checkbox_"+this.attrs.id)+'"');_j.s(' href="'+("javascript:void(0)")+'"');_j.s('>&nbsp;');
_j.ns('</a>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="bs_external_sku_col col"');_j.s('>');
_j.ns('<div');_j.s(' class="truncate_text creator_text"');_j.s(' id="'+("external_sku_"+this.attrs.id)+'"');_j.s(' title="'+(this.attrs.bs_external_sku)+'"');_j.s('>');
_j.ns(this._truncate(this.attrs.bs_external_sku,11));
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="upc_or_isbn_col col truncate_text"');_j.s(' id="'+("upc_or_isbn_"+this.attrs.id)+'"');_j.s(' title="'+(this.attrs.bs_upc_or_isbn)+'"');_j.s('>');
_j.ns(this._truncate(this.attrs.bs_upc_or_isbn,13));
_j.ns('</div>');
var supply=this.is_for_sale()?'supply_sell':'supply_neither';
_j.ns('<div');_j.s(' class="title_col col"');_j.s('>');
_j.ns('<div');_j.s(' class="'+("title_text "+supply+" truncate_text")+'"');_j.s(' id="'+("title_"+this.attrs.id)+'"');_j.s(' onclick="'+("Glyde.notify.publish('listing_more_info:clicked', {listing_id: "+this.attrs.id+", id: this.id})")+'"');_j.s(' title="'+(this.attrs.title)+'"');_j.s('>');
_j.ns(this._truncate(this.attrs.title,12));
_j.ns('</div>');
_j.ns('<div');_j.s(' class="info_image"');_j.s(' id="'+("info_image_"+this.attrs.id)+'"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="type_col col"');_j.s('>');
_j.ns('<div');_j.s(' id="'+("type_"+this.attrs.id)+'"');_j.s('>');
_j.ns(this.attrs.product_type);
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="bs_date_added_col col"');_j.s(' id="'+("date_added_"+this.attrs.id)+'"');_j.s('>');
_j.ns(this.bs_date_added_str());
_j.ns('</div>');
_j.ns('<div');_j.s(' class="cond_col col"');_j.s(' id="'+("cond_"+this.attrs.id)+'"');_j.s('>');
_j.ns(this.condition_str());
_j.ns('</div>');
_j.ns('<div');_j.s(' class="price_col col"');_j.s(' id="'+("price_"+this.attrs.id)+'"');_j.s('>');
if(is_modifiable){
_j.ns(this._bulk_seller_price_inner_html());
}
else{
_j.ns('<div');_j.s(' class="price_text"');_j.s('>');
_j.ns('<span');_j.s(' class="sale_pending"');_j.s('>');
_j.ns(this.price_str());
_j.ns('</span>');
_j.ns('</div>');
}
_j.ns('</div>');
_j.ns('<div');_j.s(' class="bs_orig_price_col col"');_j.s(' id="'+("bs_orig_price_"+this.attrs.id)+'"');_j.s('>');
if(this.is_for_sale()){
_j.ns(this._bulk_for_sale_price_inner_html());
}
else{
_j.ns('<div');_j.s(' class="price_text"');_j.s('>');
_j.ns('<span');_j.s('>');
_j.ns(this.bs_orig_price_str());
_j.ns('</span>');
_j.ns('</div>');
}
_j.ns('</div>');
_j.ns('<div');_j.s(' class="bs_low_price_col col"');_j.s(' id="'+("release_comp_"+this.attrs.id)+'"');_j.s('>');
var cents=(is_sellable||only_sellable)?this.attrs.best_price.price.cents:-1;
_j.ns(this._valid_price_str(cents));
_j.ns('</div>');
q_id="quantity_box_"+this.attrs.id;
var onclick_str='Collection.get_instance().update_price_dialog().open(\''+q_id+'\', Collection.get_instance().find_listing_by_id('+this.attrs.id+'))';
_j.ns('<div');_j.s(' class="quantity_col col"');_j.s(' id="'+(q_id)+'"');_j.s(' onclick="'+(onclick_str)+'"');_j.s('>');
_j.ns(this.attrs.quantity);
_j.ns('</div>');
return _j.v();
};
Listing.prototype._bulk_for_sale_price_inner_html=function(){
var _j=new Jaml();
var anchor_id='bs_orig_price_a_'+this.attrs.id;
var onclick_str='Collection.get_instance().update_price_dialog().open(\''+anchor_id+'\', Collection.get_instance().find_listing_by_id('+this.attrs.id+'))';
_j.ns('<a');_j.s(' id="'+(anchor_id)+'"');_j.s(' onclick="'+(onclick_str)+'"');_j.s(' href="'+('javascript:void(0)')+'"');_j.s('>');
_j.ns('<div');_j.s(' class="up_down_arrows"');_j.s('>');
_j.ns('</div>');
_j.ns(this.bs_orig_price_str());
_j.ns('</a>');
return _j.v();
};
Listing.prototype._bulk_seller_price_inner_html=function(){
var _j=new Jaml();
if(this.is_for_sale()){
var charity_info=this.attrs.charity_percentage?this.attrs.charity_percentage+'% of your proceeds ($'+Glyde.Money.format_cents(this.attrs.charity_proceeds.cents)+') will be donated to '+this.attrs.charity_name:'';
var cl=(this.price()<=this.attrs.market_price.price.cents?'under_or_equal_to_market':'over_market');
_j.ns('<div');_j.s(' class="'+("sblock actionable "+cl)+'"');_j.s(' id="'+("price_a_"+this.attrs.id)+'"');_j.s(' title="'+(charity_info)+'"');_j.s('>');
if(this.attrs.charity_percentage){
_j.ns('<div');_j.s(' class="info_image"');_j.s('>');
_j.ns('</div>');
}
_j.ns('<div');_j.s(' class="price_text"');_j.s('>');
_j.ns(this.price_str());
_j.ns('</div>');
_j.ns('</div>');
}
return _j.v();
};
Listing.prototype._price_inner_html=function(){
var _j=new Jaml();
if(this.is_for_sale()){
var charity_info=this.attrs.charity_percentage?this.attrs.charity_percentage+'% of your proceeds ($'+Glyde.Money.format_cents(this.attrs.charity_proceeds.cents)+') will be donated to '+this.attrs.charity_name:'';
var cl=(this.price()<=this.attrs.market_price.price.cents?'under_or_equal_to_market':'over_market');
_j.ns('<a');_j.s(' class="'+("sblock sfloatl actionable "+cl)+'"');_j.s(' id="'+("price_a_"+this.attrs.id)+'"');_j.s(' onclick="'+("Collection.get_instance().listing_dialog.open(Collection.get_instance().find_listing_by_id('"+this.attrs.id+"'), this, 'edit')")+'"');_j.s(' title="'+(charity_info)+'"');_j.s('>');
_j.ns('<div');_j.s(' class="up_down_arrows"');_j.s('>');
_j.ns('</div>');
if(this.attrs.charity_percentage){
_j.ns('<div');_j.s(' class="info_image"');_j.s('>');
_j.ns('</div>');
}
_j.ns('<div');_j.s(' class="price_text"');_j.s('>');
_j.ns(this.price_str());
_j.ns('</div>');
_j.ns('</a>');
}
return _j.v();
};
Listing.prototype.render_owner_info=function(){
var _j=new Jaml();
_j.ns(this._render_extra_info_text_row('Condition',this.condition_str()));
var is_sellable=this.can_be_displayed_as_for_sale();
var only_sellable=!this.is_modifiable()&&this.is_sellable();
var cents=(is_sellable||only_sellable)?this.attrs.market_price.price.cents:-1;
if(this.is_for_sale()){
_j.ns(this._render_extra_info_text_row('Your Price',this.price_str()+' (market price is '+this._valid_price_str(cents)+')'));
}
else{
_j.ns(this._render_extra_info_text_row('Market Price',this._valid_price_str(cents)));
}
if(this.attrs.charity_percentage){
_j.ns(this._render_extra_info_text_row('Donation',this.attrs.charity_percentage+'% of your proceeds ('+this._valid_price_str(this.attrs.charity_proceeds.cents)+') will be donated to '+this.attrs.charity_name));
}
return _j.v();
};
Listing.prototype.render_non_owner_info=function(suppress_price){
var _j=new Jaml();
var legit_skus=this.attrs.extra_info.legit_skus;
if(legit_skus.length>0){
var lowest_price=null;
for(var c=0;c<legit_skus.length;c++){
if(legit_skus[c].best_price.cents<lowest_price||lowest_price==null){
lowest_price=legit_skus[c].best_price.cents;
}
}
if(!suppress_price){
_j.ns(this._render_extra_info_text_row('Price','starting at '+this._valid_price_str(lowest_price)));
}
}
return _j.v();
};
Listing.prototype.render_vertical_info=function(){
var _j=new Jaml();
_j.ns(this['_render_extra_info_'+this.attrs.vertical]());
return _j.v();
};
Listing.prototype._render_extra_info_videos=function(){
var _j=new Jaml();
_j.ns(this._render_genre_info());
if(this.attrs.extra_info.stars.length>0){
_j.ns(this._render_extra_info_text_row('Starring',this.attrs.extra_info.stars.join(', ').truncate_with_delimiters(70,',')));
}
if(this.attrs.extra_info.directors.length>0){
var dir_label=this.attrs.extra_info.directors.length>1?'Directors':'Director';
_j.ns(this._render_extra_info_text_row(dir_label,this.attrs.extra_info.director));
}
if(!Glyde.is.empty_string(this.attrs.extra_info.details)){
_j.ns(this._render_extra_info_text_row('Details',this.attrs.extra_info.num_discs+' '+(this.attrs.extra_info.num_discs==1?'Disc':'Discs')+', '+this.attrs.extra_info.details));
}
if(this.attrs.extra_info.description){
_j.ns(this._render_extra_info_text_row('Synopsis',this.attrs.extra_info.description));
}
return _j.v();
};
Listing.prototype._render_extra_info_games=function(){
var _j=new Jaml();
if(this.attrs.extra_info.platform){
_j.ns(this._render_extra_info_text_row('Platform',this.attrs.extra_info.platform));
}
if(this.attrs.extra_info.publisher){
_j.ns(this._render_extra_info_text_row('Publisher',this.attrs.extra_info.publisher));
}
if(this.attrs.extra_info.num_players){
_j.ns(this._render_extra_info_text_row('Players',this.attrs.extra_info.num_players));
}
if(this.attrs.extra_info.description){
_j.ns(this._render_extra_info_text_row('Description',this.attrs.extra_info.description));
}
return _j.v();
};
Listing.prototype._render_extra_info_books=function(){
var _j=new Jaml();
if(this.attrs.extra_info.authors.length>0){
var auth_label=this.attrs.extra_info.authors.length>1?'Authors':'Author';
_j.ns(this._render_extra_info_text_row(auth_label,this.attrs.extra_info.authors.join(', ')));
}
if(this.attrs.extra_info.format){
_j.ns(this._render_extra_info_text_row('Binding',this.attrs.extra_info.format));
}
_j.ns(this._render_genre_info());
if(!Glyde.is.empty_string(this.attrs.extra_info.details)){
_j.ns(this._render_extra_info_text_row('Details',this.attrs.extra_info.details));
}
if(this.attrs.extra_info.description){
_j.ns(this._render_extra_info_text_row('Synopsis',this.attrs.extra_info.description));
}
return _j.v();
};
Listing.prototype._render_extra_info_music=function(){
var _j=new Jaml();
if(this.attrs.extra_info.artist){
_j.ns(this._render_extra_info_text_row('Artist',this.attrs.extra_info.artist));
}
_j.ns(this._render_genre_info());
if(!Glyde.is.empty_string(this.attrs.extra_info.details)){
_j.ns(this._render_extra_info_text_row('Release',this.attrs.extra_info.details));
}
if(this.attrs.extra_info.num_discs){
_j.ns(this._render_extra_info_text_row('Discs',this.attrs.extra_info.num_discs));
}
var nt=this.attrs.extra_info.valid_track_list_length;
if(nt>0){
_j.ns(this._render_extra_info_text_row('Track List',nt+(nt==1?' track':' tracks')));
_j.ns('<div');_j.s(' class="track_list"');_j.s('>'+(this._render_extra_info_cd_track_list()));
_j.ns('</div>');
}
return _j.v();
};
Listing.prototype._render_extra_info_text_row=function(label,value){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="extra_info_row"');_j.s('>');
_j.ns('<span');_j.s(' class="label"');_j.s('>'+(label+':'));
_j.ns('</span>');
_j.ns('<span');_j.s(' class="value"');_j.s('>'+(value));
_j.ns('</span>');
_j.ns('</div>');
return _j.v();
};
LineupDialog=Class.create(Glyde.Dialog,{
LINEUP_CONTENT_ID:'lineup_box',
LINEUP_HOME_ID:'lineup_box_home',
DEFAULT_LINEUP_SIZE:4,
initialize:function(target_id,on_submit,options,should_position,sell_page_lineup){
Glyde.Dialog.prototype.initialize.call(this,options);
this._should_center=false;
this._target_id=target_id;
this._on_submit=on_submit||Glyde.empty_function;
this._selection_clicked=false;
this._options=options;
this._should_position=!(typeof(should_position)=='undefined')?should_position:true;
this._sell_page_lineup=sell_page_lineup;
if(!this._should_position){
this._is_modal=false;
}
},
_create_container_if_necessary:function(instance_num){
var div=$(this._dialog_container_id);
if(!div){
div=document.createElement('div');
div.id=this._dialog_container_id;
div.className='modal_dialog_container dialog_container';
document.body.appendChild(div);
}
return div;
},
_set_container_ids:function(instance_num){
this._dialog_container_id='lineup_dialog_container';
},
_compose_content:function(container,html){
$(this._dialog_container_id).innerHTML=html;
},
open:function(){
Glyde.Dialog.prototype.open.call(this,$(this._target_id),this._to_html(this._sell_page_lineup));
var opts=this._options;
this.lineup=new Glyde.widgets.LineupScroll($('lineup_scroll'),opts.lineup_size||this.DEFAULT_LINEUP_SIZE,
opts.vertical,opts.search_key,
this._proxy_submit.bind(this));
this._selection_clicked=false;
},
close:function(no_on_close){
this.lineup.cancel();
Glyde.Dialog.prototype.close.call(this,no_on_close);
},
_proxy_submit:function(glu_id,glu){
if(this._selection_clicked){return;}
this._selection_clicked=true;
this.close(true);
this._on_submit(glu_id,glu);
},
_handle_window_resize:function(){
if(this._should_position){
Glyde.Dialog.prototype._handle_window_resize.call(this);
}
},
_watch_window_resize:function(){
if(this._should_position){
Glyde.Dialog.prototype._watch_window_resize.call(this);
}
},
_stop_watching_window_resize:function(){
if(this._should_position){
Glyde.Dialog.prototype._stop_watching_window_resize.call(this);
}
},
_set_dialog_and_arrow_position:function(){
if(this._should_position){
Glyde.Dialog.prototype._set_dialog_and_arrow_position.call(this);
}
}
});
LineupDialog.prototype._to_html=function(sell_page_lineup){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="dialog_close_box"');_j.s('>');
var href="javascript:void(0)";
var click="Glyde.Dialog.close()";
_j.ns('<a');_j.s(' class="dialog_close_button close_button a_button"');_j.s(' id="dialog_close_button_lineup_dialog"');_j.s(' href="'+(href)+'"');_j.s(' onclick="'+(click)+'"');_j.s('>');
_j.ns('</a>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="lineup_title"');_j.s('>');Jaml.x();
_j.ns('<span');_j.s(' class="primary_text"');_j.s('>'+(sell_page_lineup?(Glyde.page.is_facebook()?'Donate':'Sell'):'Add'));
_j.ns('</span>');
_j.ns('&mdash; choose your version');
Jaml.x();_j.ns('</div>');
_j.ns('<div');_j.s(' id="lineup_scroll"');_j.s('>');
_j.ns('</div>');
return _j.v();
};
ListingDialog=Class.create(Glyde.Dialog,{
EVENT_OPEN:'listing_dialog:open',
EVENT_CLOSE:'listing_dialog:close',
initialize:function($super,card_issuers,options){
this._card_issuers=card_issuers;
var opts={
is_light:true,
should_center:false,
use_arrow:true,
use_small_close:true,
on_enter_key:Glyde.Dialog.close
};
Object.extend(opts,options);
$super(opts);
Glyde.notify.subscribe(Glyde.BuyReceiptWidget.prototype.MESSAGE_PURCHASE_CANCELLED,this._handle_purchase_cancelled.bind(this));
},
open:function($super,listing,target_element,initial_state){
$super(target_element,'');
this._listing=listing;
this._initial_state=initial_state;
this._listing_is_for_sale=this._listing.attrs.is_for_sale;
this._loading_timeout=setTimeout(function(){$(this._container_id).update(this._render_loading_title());}.bind(this),250);
this._loading_request=listing.fetch_extra_info(function(){
clearTimeout(this._loading_timeout);
switch(initial_state){
case'sell':this._sell_request();break;
case'edit':
if(this._listing.is_for_sale()){
this._price_condition_request();
}else{
this._condition_request();
}
break;
case'buy_now':
this._create_buttons();
this._buy_request();
break;
default:
$(this._container_id).update(this._render_info());
this._create_buttons();
var cover=$(this._container_id).select('.image_box .cover')[0];
cover.fade_appear_image();
break;
}
this._loading_request=null;
}.bind(this));
Glyde.notify.publish(this.EVENT_OPEN,{'item_id':listing.attrs.id,'attrs':listing.attrs});
},
close:function($super){
if(this._refetch_buy_timer){clearTimeout(this._refetch_buy_timer);}
if(this._loading_request){this._loading_request.abort();}
this._destroy_shipping_select();
$super();
Glyde.notify.publish(this.EVENT_CLOSE,{'listing_id':this._listing.attrs.id,'listing_is_for_sale':this._listing_is_for_sale});
},
_destroy_shipping_select:function(){
if(this._shipping_address_select){
this._shipping_address_select.destroy();
this._shipping_address_select=null;
}
},
_create_buttons:function(){
var buttons_info=[
{id:'sell',text:'Sell This Item'},
{id:'condition',text:'Change Condition'},
{id:'delete',text:'Delete Item'},
{id:'delist',text:'Delist from Sale'},
{id:'price_condition',text:'Change Price or Condition'},
{id:'cancel',text:'Cancel'},
{id:'buy',text:'Buy',blue:true},
{id:'buy_now',text:'Buy Now',blue:true},
{id:'list',text:'List for Sale',blue:true},
{id:'update',text:'Update',blue:true}
];
buttons_info.each(function(info){
var element_id='listing_'+info.id+'_button';
var button_element=$(element_id);
if(button_element){
var options={};
if(info.blue){options.color='blue';}
var handler_name='_'+info.id+'_request';
var button=new Glyde.ButtonWidget(element_id,info.text,options);
button.observe('widget:activate',this[handler_name].bind(this));
this['_'+info.id+'_button']=button;
}
}.bind(this));
},
_delete_request:function(){
var confirm_msg="Are you sure you want to delete this copy of \""+this._listing.attrs.title+"\" from your collection?";
if(confirm(confirm_msg)){
this.close();
this._listing.delete_remote();
}
},
_buy_request:function(){
$(this._container_id).update(this._render_title_only());
this._loading_timeout=setTimeout(function(){
$(this._container_id).update(this._render_loading());
}.bind(this),250);
if(Glyde.user&&Glyde.user.is_reg_complete){
this._fetch_user_info(function(){clearTimeout(this._loading_timeout);this._buy_load();}.bind(this));
}else{
clearTimeout(this._loading_timeout);
this._buy_load();
}
},
_cancel_request:function(){
if(this._initial_state){
this.close();
}else{
this._destroy_shipping_select();
$(this._container_id).update(this._render_info());
this._create_buttons();
}
},
_sell_request:function(){
$(this._container_id).update(this._render_title_only());
this._loading_timeout=setTimeout(function(){$(this._container_id).update(this._render_loading());}.bind(this),250);
this._edit_mode=1;
this._fetch_edit_info(function(){clearTimeout(this._loading_timeout);this._edit_load();}.bind(this));
},
_setup_update_handlers:function(setting_for_sale){
this.__update_error_callback=function(msg_name,info){
var json=info.json;
if(json&&!json.success){
this._listing_is_for_sale=false;
if(json.exception){
if(json.exception.message&&
json.exception.message.match(/exceeds the limit/)){
this._listing_details_widget.price_selector._adjuster._open_max_alert();
}
}
}
Glyde.notify.unsubscribe(Listing.EVENT_UPDATED,this.__update_success_callback);
Glyde.notify.unsubscribe(Listing.EVENT_UPDATE_FAILED,this.__update_error_callback);
}.bind(this);
Glyde.notify.subscribe(Listing.EVENT_UPDATE_FAILED,this.__update_error_callback);
this.__update_success_callback=function(msg_name,listing){
var listing_original_market_price=this._listing_details_widget.market_price_cents();
var was_above_market=this._start_price>listing_original_market_price;
var is_above_market=listing.attrs.cents>listing_original_market_price;
if(Glyde.user.stats){
var original_num_listings_above_market_price=Glyde.user.stats.num_listings_above_market_price();
if(!was_above_market&&is_above_market){
Glyde.user.stats.increment_num_listings_above_market_price();
}else if(was_above_market&&!is_above_market){
Glyde.user.stats.decrement_num_listings_above_market_price();
}
}
if(setting_for_sale){
this._listing_is_for_sale=false;
}
Glyde.notify.unsubscribe(Listing.EVENT_UPDATED,this.__update_success_callback);
Glyde.notify.unsubscribe(Listing.EVENT_UPDATE_FAILED,this.__update_error_callback);
this.close();
}.bind(this);
Glyde.notify.subscribe(Listing.EVENT_UPDATED,this.__update_success_callback);
},
_list_request:function(){
if(!this._validate_donation_selector()){return;}
var ldw=this._listing_details_widget;
this._setup_update_handlers(true);
this._listing.save_price_condition_and_sell(ldw.glu(),ldw.cents(),
ldw.condition_id(),true,
ldw.charity_percentage(),
ldw.charity_id()
);
},
_condition_request:function(){
$(this._container_id).update(this._render_title_only());
this._loading_timeout=setTimeout(function(){$(this._container_id).update(this._render_loading());}.bind(this),250);
this._edit_mode=2;
this._fetch_edit_info(function(){clearTimeout(this._loading_timeout);this._edit_load();}.bind(this));
},
_update_request:function(){
if(!this._validate_donation_selector()){return;}
var set_sell=this._edit_mode==1;
this._setup_update_handlers(set_sell);
var ldw=this._listing_details_widget;
this._listing.save_price_condition_and_sell(ldw.glu(),ldw.cents(),
ldw.condition_id(),set_sell,
ldw.charity_percentage(),
ldw.charity_id());
},
_validate_donation_selector:function(){
var ldw=this._listing_details_widget;
var donation_selector=ldw.donation_selector();
if(donation_selector&&donation_selector.is_enabled()&&!donation_selector.is_charity_selected()){
donation_selector.show_no_charity_error();
return false;
}
return true;
},
_delist_request:function(){
var listing_update_handler=function(event_name,info){
Glyde.notify.unsubscribe(Listing.EVENT_UPDATED,listing_update_handler);
Glyde.notify.unsubscribe(Listing.EVENT_UPDATE_FAILED,listing_update_handler);
if(Glyde.user.stats){
if(this._listing.price()>this._listing.attrs.market_price.price.cents){
Glyde.user.stats.decrement_num_listings_above_market_price();
}
}
this.close();
}.bind(this);
Glyde.notify.subscribe(Listing.EVENT_UPDATED,listing_update_handler);
Glyde.notify.subscribe(Listing.EVENT_UPDATE_FAILED,listing_update_handler);
this._listing.update_remote('is_for_sale','0');
},
_price_condition_request:function(){
$(this._container_id).update(this._render_title_only());
this._loading_timeout=setTimeout(function(){$(this._container_id).update(this._render_loading());}.bind(this),250);
this._edit_mode=1;
this._fetch_edit_info(function(){clearTimeout(this._loading_timeout);this._edit_load();}.bind(this));
},
_buy_load:function(){
$(this._container_id).update(this._render_buy());
this._create_buttons();
var cheapest_item=null;
this._items.each(function(item,index){
if(cheapest_item==null||item.price_cents<this._items[cheapest_item].price_cents){
cheapest_item=index;
}
}.bind(this));
this._buy_select_item(cheapest_item);
if(this._shipping_addresses){
this._shipping_address_select=
new ShippingAddressSelect('shipping_address_select',
this._shipping_addresses,20000,10);
}
},
_buy_select_item:function(item_index){
this._item_selected=item_index;
$(this._container_id).select('.item.selected').each(function(e){
e.removeClassName('selected');
});
$(this._container_id).select('.item_'+item_index)[0].addClassName('selected');
if(Glyde.user){$(this._container_id).select('#payment_value')[0].update(this._render_payment());}
},
_buy_now_request:function(){
if(Glyde.user){
if(Glyde.user.is_reg_complete){
this._buy_now_button.disable();
var credit_card_charge_required=this._items[this._item_selected].total_cents>this._account.cents;
if(this._shipping_address_select.selected_address().cvv2_required&&credit_card_charge_required){
this._show_cvv2_dialog();
}else{
this._on_buy();
}
}else{
this._send_user_to_signup();
}
}else{
this._send_user_to_signup();
}
},
_show_cvv2_dialog:function(){
this._cvv2_dialog=new TransactionCvvDialog(this._on_cvv2_dialog_close.bind(this),
this._on_cvv2_dialog_purchase.bind(this),
this._card_issuers[this._credit_card.issuer]);
this._cvv2_dialog.open('listing_buy_now_button');
},
_on_cvv2_dialog_close:function(){
this._buy_now_button.enable();
},
_on_cvv2_dialog_purchase:function(cvv2){
this._on_buy(cvv2);
},
_on_buy:function(cvv2){
$(this._container_id).update(this._render_title_only());
var render_verify=function(){
$(this._container_id).update(this._render_verifying());
}.bind(this);
this._loading_timeout=setTimeout(render_verify,250);
var func=function(data){
clearTimeout(this._loading_timeout);
if(data.success){
this._buy_now_load(data);
}else{
this._buy_now_failed(data);
}
}.bind(this);
this._buy_item(func,cvv2,this._shipping_address_select.selected_address().address_id);
},
_send_user_to_signup:function(){
var context=$H({a:window.location.pathname+'#buy_now',i:this._listing.attrs.id}).toQueryString();
var hash={
return_to:location.toString(),
ctx:context,
collection_id:this._listing.attrs.collection_id
};
var sku_id=this._listing.attrs.sku_id;
if(this._items[this._item_selected].listing_id){
hash.listing_id=this._items[this._item_selected].listing_id;
}else{
sku_id=this._items[this._item_selected].sku_id;
}
Glyde.page.header.checkout(sku_id,this._listing.attrs.title,hash);
},
_buy_now_load:function(data){
$(this._container_id).update(this._render_purchased());
this._receipt=new Glyde.BuyReceiptWidget($(this._container_id).select('.receipt_container')[0],data,this._listing.attrs);
},
_handle_purchase_cancelled:function(msg_name,info){
this._refetch_buy_timer=setTimeout(this._buy_request.bind(this),10000);
},
_buy_now_failed:function(data){
if(data.html){
$(this._container_id).update(data.html);
}else{
$(this._container_id).update("Sorry, an error occurred while trying to process your buy request.");
}
},
_buy_item:function(callback,cvv2,address_id){
function on_complete(res,o){
var data=res.responseJSON;
if(data.success){
(callback||Glyde.empty_function)(data);
}else{
(callback||Glyde.page.handle_server_errors)(data);
}
}
var parameters={};
if(this._items[this._item_selected].sku_id){
parameters['sku[type]']='Sku';
parameters['sku[id]']=this._items[this._item_selected].sku_id;
parameters['price[cents]']=this._items[this._item_selected].price_cents;
}else if(this._items[this._item_selected].listing_id){
parameters['listing_id']=this._items[this._item_selected].listing_id;
}
if(cvv2){parameters.cvv2=cvv2;}
if(address_id){parameters.shipping_address_id=address_id;}
var options={
method:'post',
parameters:parameters,
onComplete:on_complete.bind(this)
};
ConversionTracker.get_instance().track_purchase(this._items[this._item_selected].price_cents);
new Ajax.Request('/purchase_orders',options);
},
_fetch_user_info:function(callback){
function on_complete(res,o){
var data=res.responseJSON;
if(data.success){
this._credit_card=data.credit_card;
this._account=data.account;
this._shipping_addresses=data.shipping_addresses;
(callback||Glyde.empty_function)();
}else{
Glyde.page.handle_server_errors(data);
}
}
var options={
method:'get',
parameters:{},
onComplete:on_complete.bind(this)
};
new Ajax.Request('/users/'+Glyde.user.id+'/user_info',options);
},
_fetch_edit_info:function(callback){
function on_complete(res,o){
var data=res.responseJSON;
if(data.success){
this._edit_data=data;
(callback||Glyde.empty_function)();
}else{
Glyde.page.handle_server_errors(data);
}
}
var options={
method:'get',
parameters:{show:this._edit_mode},
onComplete:on_complete.bind(this)
};
new Ajax.Request('/listings/'+this._listing.attrs.id+'/edit',options);
},
_edit_load:function(){
$(this._container_id).update(this._render_edit());
this._create_buttons();
this._start_price=this._listing.price();
var elem=$(this._container_id).select('.listing_details_widget')[0];
this._listing_details_widget=new Glyde.widgets.ListingDetailsWidget(
elem,
this._edit_data.glu,
this._listing,
this._start_price,
this._listing.condition_id(),
this._edit_mode,
this._edit_data.charity_percentage,
this._edit_data.charity_id,
this._edit_data.charity_name,
this._edit_data.charity_enabled,
null,
11000
);
},
_payment_str:function(){
var str='';
if(this._account.cents>0){
str+='Glyde Credit';
if(this._account.cents<this._items[this._item_selected].total_cents){
str+=' ('+this._listing._valid_price_str(this._account.cents)+')';
}
}
if(this._items[this._item_selected].total_cents>this._account.cents){
if(str!=''){
str+=', ';
}
str+=this._credit_card.short_issuer+' x'+this._credit_card.last4;
if(this._account.cents>0){
str+=' ('+this._listing._valid_price_str(this._items[this._item_selected].total_cents-this._account.cents)+')';
}
}
return str;
},
_set_container_ids:function(instance_num){
this._dialog_container_id='listing_dialog_container';
this._container_id='listing_dialog_content';
this._arrow_id='listing_dialog_arrow';
this._close_button_id='listing_dialog_close_button';
},
_get_condition_name_from_sku:function(sku){
var map={
'VidCondition':global_var.conditions.videos,
'BkCondition':global_var.conditions.books,
'MusCondition':global_var.conditions.music,
'GameCartridgeCondition':global_var.conditions.games_cartridge,
'GameDiscCondition':global_var.conditions.games_disc
};
function find_entry(condition_array,condition_id){
for(var c=0;c<condition_array.length;c++){
if(condition_array[c].id==condition_id){
return condition_array[c].name;
}
}
return null;
}
return find_entry(map[sku.condition_type],sku.condition_id);
},
_get_condition_desc_from_sku:function(sku){
var map={
'VidCondition':global_var.conditions.videos,
'BkCondition':global_var.conditions.books,
'MusCondition':global_var.conditions.music,
'GameCartridgeCondition':global_var.conditions.games_cartridge,
'GameDiscCondition':global_var.conditions.games_disc
};
function find_entry(condition_array,condition_id){
for(var c=0;c<condition_array.length;c++){
if(condition_array[c].id==condition_id){
return condition_array[c].transaction_box_desc;
}
}
return null;
}
return find_entry(map[sku.condition_type],sku.condition_id);
},
_is_owner:function(){
if(Glyde.user){
return this._listing.attrs.collection_owner.id==Glyde.user.id;
}else{
return false;
}
},
_close_on_mouseup:function(event){
return(!this._mouse_down_within_dialog&&!event.element().id.match(/charity/));
},
_click_is_within_dialog:function(element){
element=$(element);
var matches_array=$$('.shipping_address_menu');
var shipping_address_menu=(matches_array&&matches_array.length)?matches_array[0]:null;
var email_dialog_node=this._receipt?this._receipt.share_buttons_widget().email_dialog_node():null;
var search_flyout,percent_select_menu;
if(this._listing_details_widget){
search_flyout=$('suggest_list'+this._listing_details_widget.charity_search_input_id());
percent_select_menu=$(this._listing_details_widget.charity_percent_select_menu_id());
}
return element.descendantOf(this._dialog_container_id)||
(shipping_address_menu&&element.descendantOf(shipping_address_menu)||
(search_flyout&&element.descendantOf(search_flyout))||
(email_dialog_node&&element.descendantOf(email_dialog_node))||
(percent_select_menu&&element.descendantOf(percent_select_menu)));
}
});
ListingDialog.prototype._render_loading_title=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="loading"');_j.s('>');
_j.ns('<img');_j.s(' class="loading_throbber"');_j.s(' src="'+('images/wait.gif')+'"');_j.s(' />');
_j.ns('<span');_j.s(' class="loading_message"');_j.s('>Loading...');
_j.ns('</span>');
_j.ns('</div>');
return _j.v();
};
ListingDialog.prototype._render_loading=function(){
var _j=new Jaml();
_j.ns(this._listing._render_title());
_j.ns('<div');_j.s(' class="listing_details"');_j.s('>');
_j.ns('<div');_j.s(' class="loading"');_j.s('>');
_j.ns('<img');_j.s(' class="loading_throbber"');_j.s(' src="'+('images/wait.gif')+'"');_j.s(' />');
_j.ns('<span');_j.s(' class="loading_message"');_j.s('>Loading...');
_j.ns('</span>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
ListingDialog.prototype._render_verifying=function(){
var _j=new Jaml();
_j.ns(this._listing._render_title());
_j.ns('<div');_j.s(' class="listing_details"');_j.s('>');
_j.ns('<div');_j.s(' class="loading"');_j.s('>');
_j.ns('<img');_j.s(' class="loading_throbber"');_j.s(' src="'+('images/wait.gif')+'"');_j.s(' />');
_j.ns('<span');_j.s(' class="loading_message"');_j.s('>Verifying...');
_j.ns('</span>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
ListingDialog.prototype._render_title_only=function(){
var _j=new Jaml();
_j.ns(this._listing._render_title());
return _j.v();
};
ListingDialog.prototype._render_info=function(){
var _j=new Jaml();
_j.ns(this._listing._render_title());
_j.ns('<div');_j.s(' class="listing_details"');_j.s('>');
_j.ns('<div');_j.s(' class="'+('image_box'+(this._listing.attrs.vertical=="music"?" image_box_cd":""))+'"');_j.s('>');
_j.ns('<img');_j.s(' class="cover"');_j.s(' src="'+(Glyde.image.cover_path_for_max_w_h(this._listing,100,140).replace('.jpg','h.jpg'))+'"');_j.s(' title="'+(this._listing.attrs.title)+'"');_j.s(' />');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="text_box"');_j.s('>');
if(this._is_owner()){
_j.ns(this._listing.render_owner_info());
}
else{
_j.ns(this._listing.render_non_owner_info());
}
_j.ns(this._listing.render_vertical_info());
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="actions"');_j.s('>');
_j.ns('<div');_j.s(' class="left"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="right"');_j.s('>');
if(!Glyde.page.is_user_bulk_seller()){
if(this._is_owner()){
if(this._listing.is_deletable()){
_j.ns('<div');_j.s(' id="listing_delete_button"');_j.s('>');
_j.ns('</div>');
}
if(this._listing.is_modifiable()){
if(this._listing.is_for_sale()){
_j.ns('<div');_j.s(' id="listing_delist_button"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' id="listing_price_condition_button"');_j.s('>');
_j.ns('</div>');
}
else{
if(this._listing.is_sellable()){
_j.ns('<div');_j.s(' id="listing_sell_button"');_j.s('>');
_j.ns('</div>');
}
_j.ns('<div');_j.s(' id="listing_condition_button"');_j.s('>');
_j.ns('</div>');
}
}
}
else{
if((this._listing.attrs.extra_info.legit_skus.length>0)&&(g_collection.vacation_return_at==null)){
_j.ns('<div');_j.s(' id="listing_buy_button"');_j.s('>');
_j.ns('</div>');
}
}
}
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
ListingDialog.prototype._render_buy=function(){
var _j=new Jaml();
_j.ns(this._listing._render_title());
var legit_skus=this._listing.attrs.extra_info.legit_skus;
_j.ns('<div');_j.s(' class="skus"');_j.s(' style="'+('width: '+legit_skus.length*202+'px')+'"');_j.s('>');
this._items=[];
for(var c=legit_skus.length-1;c>=0;c--){
_j.ns('<div');_j.s(' class="sku"');_j.s('>');
var onclick='Collection.get_instance().listing_dialog._buy_select_item('+this._items.length+')';
_j.ns('<div');_j.s(' class="'+('item item_'+this._items.length)+'"');_j.s(' onclick="'+(onclick)+'"');_j.s('>');
_j.ns('<div');_j.s(' class="condition"');_j.s(' title="'+(this._get_condition_desc_from_sku(legit_skus[c]).replace(/\n/g,' '))+'"');_j.s('>');
_j.ns('<div');_j.s(' class="name"');_j.s('>');Jaml.x();_j.s(this._get_condition_name_from_sku(legit_skus[c]));Jaml.x();
Jaml.x();_j.ns('</div>');
_j.ns('<div');_j.s(' class="icon"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="price"');_j.s('>');
_j.ns('<div');_j.s(' class="label"');_j.s('>Price');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="value"');_j.s('>'+(this._listing._valid_price_str(legit_skus[c].lowest_price.cents)));
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="shipping"');_j.s('>');
_j.ns('<div');_j.s(' class="label"');_j.s('>Shipping');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="value"');_j.s('>'+(this._listing._valid_price_str(legit_skus[c].shipping.cents)));
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="total"');_j.s('>');
_j.ns('<div');_j.s(' class="label"');_j.s('>Total');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="value"');_j.s('>'+(this._listing._valid_price_str(legit_skus[c].total.cents)));
_j.ns('</div>');
_j.ns('</div>');
if(this._listing.is_for_sale()&&this._listing.attrs.condition_id==legit_skus[c].condition_id&&this._listing.attrs.buydown_cents==legit_skus[c].lowest_price.cents){
_j.ns('<div');_j.s(' class="owner"');_j.s(' title="'+(this._listing.attrs.collection_owner.username+"'s "+Glyde.Glu.friendly_vertical_name(this._listing.attrs.vertical))+'"');_j.s('>'+(this._listing.attrs.collection_owner.username+'\'s '+Glyde.Glu.friendly_vertical_name(this._listing.attrs.vertical)));
_j.ns('</div>');
this._items.push({sku_id:null,listing_id:this._listing.attrs.id,total_cents:legit_skus[c].total.cents,price_cents:this._listing.attrs.buydown_cents});
}
else{
this._items.push({sku_id:legit_skus[c].market_price.sku_id,listing_id:null,total_cents:legit_skus[c].total.cents,price_cents:legit_skus[c].lowest_price.cents});
}
_j.ns('</div>');
if(this._listing.is_for_sale()&&this._listing.attrs.condition_id==legit_skus[c].condition_id&&this._listing.attrs.buydown_cents>legit_skus[c].lowest_price.cents){
onclick='Collection.get_instance().listing_dialog._buy_select_item('+this._items.length+')';
_j.ns('<div');_j.s(' class="'+('item item_'+this._items.length)+'"');_j.s(' onclick="'+(onclick)+'"');_j.s('>');
_j.ns('<div');_j.s(' class="price"');_j.s('>');
_j.ns('<div');_j.s(' class="label"');_j.s('>'+(this._listing.attrs.collection_owner.username+'\'s '+Glyde.Glu.friendly_vertical_name(this._listing.attrs.vertical)));
_j.ns('</div>');
_j.ns('<div');_j.s(' class="value"');_j.s('>'+(this._listing._valid_price_str(this._listing.attrs.buydown_cents+legit_skus[c].shipping.cents)));
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
this._items.push({sku_id:null,listing_id:this._listing.attrs.id,total_cents:this._listing.attrs.buydown_cents+legit_skus[c].shipping.cents,price_cents:this._listing.attrs.buydown_cents});
}
_j.ns('</div>');
}
_j.ns('</div>');
_j.ns('<div');_j.s(' class="user_info"');_j.s('>');
if(Glyde.user){
_j.ns('<div');_j.s(' class="shipping_info"');_j.s('>');
_j.ns('<div');_j.s(' class="label"');_j.s('>');
_j.ns('Shipping:');
_j.ns('</div>');
_j.ns('<div');_j.s(' id="shipping_address_select"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="payment_info"');_j.s('>');
_j.ns('<div');_j.s(' class="label"');_j.s('>');
_j.ns('Payment:  ');
_j.ns('</div>');
_j.ns('<div');_j.s(' id="payment_value"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
}
_j.ns('</div>');
_j.ns('<div');_j.s(' class="actions"');_j.s('>');
_j.ns('<div');_j.s(' class="left"');_j.s('>');
_j.ns('<div');_j.s(' id="listing_cancel_button"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="right"');_j.s('>');
_j.ns('<div');_j.s(' id="listing_buy_now_button"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
ListingDialog.prototype._render_edit=function(){
var _j=new Jaml();
_j.ns(this._listing._render_title());
_j.ns('<div');_j.s(' class="edit_container"');_j.s('>');
_j.ns('<div');_j.s(' class="listing_details_widget"');_j.s(' id="listing_details_widget"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="actions"');_j.s('>');
_j.ns('<div');_j.s(' class="left"');_j.s('>');
_j.ns('<div');_j.s(' id="listing_cancel_button"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="right"');_j.s('>');
if(this._edit_mode==1&&!this._listing.is_for_sale()){
_j.ns('<div');_j.s(' id="listing_list_button"');_j.s('>');
_j.ns('</div>');
}
else{
_j.ns('<div');_j.s(' id="listing_update_button"');_j.s('>');
_j.ns('</div>');
}
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
ListingDialog.prototype._render_purchased=function(){
var _j=new Jaml();
_j.ns(this._listing._render_title());
_j.ns('<div');_j.s(' class="purchase_details"');_j.s('>');
_j.ns('<div');_j.s(' class="'+('image_box'+(this._listing.attrs.vertical=="music"?" image_box_cd":""))+'"');_j.s('>');
_j.ns('<img');_j.s(' class="cover"');_j.s(' src="'+(Glyde.image.cover_path_for_max_w_h(this._listing,100,140).replace('.jpg','h.jpg'))+'"');_j.s(' title="'+(this._listing.attrs.title)+'"');_j.s(' />');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="receipt_container"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
ListingDialog.prototype._render_payment=function(){
var _j=new Jaml();
_j.ns(this._payment_str());
return _j.v();
};
ShareDialog=Class.create(Glyde.Dialog,{
EVENT_OPEN:'share_dialog:open',
EVENT_CLOSE:'share_dialog:close',
EMBED_HELP_WINDOWS:'<p>Use this badge on any webpage to show your collection.</p><p>Press Ctrl+C to copy the code, then Ctrl+V to paste</p>',
EMBED_HELP_OSX:'<p>Use this badge on any webpage to show your collection.</p><p>Press &#8984;C to copy the badge code, then &#8984;V to paste</p>',
EMBED_HELP_IE:'Use this badge on any webpage to show your collection. Copy the code, then paste with Ctrl+V',
COPY_LINK_HELP_WINDOWS:'<p>Press Ctrl+C to copy the link above, then paste it into an email or instant message using Ctrl+V</p>',
COPY_LINK_HELP_OSX:'<p>Press &#8984;C to copy the link above, then paste it into an email or instant message using &#8984;V</p>',
COPY_LINK_HELP_IE:'<p>Click the button to copy the link to the clipboard, then paste it into an email or instant message using Ctrl+V</p>',
MAX_EMAIL_RECIPIENTS:10,
SEND_EMAIL_ERRORS:'<p>The email could not be sent.</p>',
SEND_EMAIL_SUCCESS:'<p>Your email was successfully sent</p>',
SEND_EMAIL_FAILED:'<p>You email could not be sent at this time</p><p>Please try again later</p>',
EMAIL_SAMPLE_ADDRESS_TEXT:'name@gmail.com,name@msn.com',
EMAIL_SAMPLE_MESSAGE_TEXT:'Add your note...',
initialize:function(){
var dialog_options={
is_light:true,
should_center:false,
use_arrow:true,
disable_escape:false,
use_small_close:true
};
Glyde.Dialog.prototype.initialize.call(this,dialog_options);
},
open_share_collection:function(source_element_id,owner,is_owner,is_store,collection){
this._helper=new ShareCollectionHelper(owner,is_owner,is_store,this,collection);
this._open(source_element_id);
this._helper.pregenerate_images();
},
open_share_collection_item:function(source_element_id,listing,owner,is_owner,is_store,position_above,dialog_opener,collection){
this._listing=listing;
this._helper=new ShareCollectionItemHelper(listing,owner,is_owner,is_store,this,collection);
this._open(source_element_id,position_above,dialog_opener);
},
open_share_buy_item:function(source_element_id,glu){
this._helper=new ShareBuyItemHelper(glu);
this._open(source_element_id);
},
open_email_buy_item_share:function(source_element_id,glu,percent_off_msrp,position_above){
this._helper=new ShareEmailBuyHelper(glu,percent_off_msrp);
this._open(source_element_id,position_above,null,'email_panel');
},
open_email_list_item_share:function(source_element_id,glu,url,position_above){
this._helper=new ShareEmailListHelper(glu,url);
this._open(source_element_id,position_above,null,'email_panel');
},
open_email_site_share:function(source_element_id,position_above,referral_code){
this._helper=new ShareEmailSiteHelper(referral_code);
this._open(source_element_id,position_above,null,'email_panel');
},
_open:function(source_element_id,position_above,dialog_opener,panel_name){
this._position_preference=(position_above)?this.POSITION_ABOVE:this.POSITION_BELOW;
var dialog_title=this._helper.dialog_title();
var copy_link_panel_title=this._helper.copy_link_panel_title();
var email_panel_title=this._helper.email_panel_title();
Glyde.Dialog.prototype.open.call(this,$(source_element_id),this._to_html(dialog_title,copy_link_panel_title,email_panel_title),dialog_opener);
this._show_panel(panel_name?panel_name:'main_panel');
Glyde.notify.publish(this.EVENT_OPEN);
},
close:function(){
InputErrorNotice.clear_all();
Glyde.Dialog.prototype.close.call(this);
Glyde.notify.publish(this.EVENT_CLOSE);
},
collection_base_url:function(is_store){
var url=Glyde.urls.collections_url+'/';
var collections_regexp=/\/collections\//;
if(is_store&&collections_regexp.test(url)){
url=url.replace(collections_regexp,'/stores/');
}
return url;
},
front_page_url:function(){
var host_url='http://'+location.host;
return host_url;
},
_show_panel:function(id){
['main_panel','email_panel','badge_panel','copy_link_panel'].each(function(panel_id){
$(panel_id).style.display=(id==panel_id?'block':'none');
});
var on_open_function="_on_open_"+id;
if(this[on_open_function]){this[on_open_function]();}
var on_enter_key_function="_on_enter_key_"+id;
this._on_enter_key=this[on_enter_key_function];
},
_on_open_main_panel:function(){
this._create_main_buttons();
if(this._helper.hide_badge_button()){this._main_buttons['badge_button'].hide();}
},
_create_main_buttons:function(){
this._main_buttons={};
var buttons_info=[
{id:'send_email_button',text:'Send Email',panel:'email_panel'},
{id:'facebook_button',text:'Share on Facebook'},
{id:'myspace_button',text:'Share on MySpace'},
{id:'badge_button',text:'Add Badge'},
{id:'copy_link_button',text:'Copy Link'}
];
buttons_info.each(function(info){
var button=new Glyde.ButtonWidget(info.id,info.text);
this._main_buttons[info.id]=button;
}.bind(this));
with(this._main_buttons){
send_email_button.observe('widget:activate',this._on_activate_email_button.bind(this));
facebook_button.observe('widget:activate',this._on_activate_facebook_button.bind(this));
myspace_button.observe('widget:activate',this._on_activate_myspace_button.bind(this));
badge_button.observe('widget:activate',function(){this._show_panel('badge_panel');}.bind(this));
copy_link_button.observe('widget:activate',function(){this._show_panel('copy_link_panel');}.bind(this));
}
},
_on_activate_email_button:function(){
if(Glyde.user){
this._show_panel('email_panel');
return;
}else{
var context=$H({a:window.location.pathname+'#share_email'}).toQueryString();
Glyde.page.header.login({on_success:this._on_activate_email_button.bind(this)},context,{return_to:window.location,ctx:context});
}
},
_on_open_email_panel:function(){
this._send_email_button=new Glyde.ButtonWidget('send_email_send_button','Send Email',{color:'blue'});
this._send_email_button.observe('widget:activate',this._on_activate_send_email_button.bind(this));
this._setup_sample_text('email_addresses_input',this.EMAIL_SAMPLE_ADDRESS_TEXT,'keydown');
this._setup_sample_text('email_addresses_input',this.EMAIL_SAMPLE_ADDRESS_TEXT,'click');
this._setup_sample_text('email_message_input',this.EMAIL_SAMPLE_MESSAGE_TEXT,'focus');
var preview_container=$('email_message_preview_container');
preview_container.update(this._strip_newlines(this._helper.email_salutation()));
preview_container.select('a').each(function(link){link.href="javascript:void (0)";});
with($('email_addresses_input')){
focus();
select();
}
},
_on_activate_send_email_button:function(){
InputErrorNotice.clear_all();
var emails=$('email_addresses_input').value;
var error_str=this._validate_email_addresses(emails);
if(error_str){
this._display_error(this._create_error('email_addresses_input',error_str));
}else{
this._send_share_email_request(this._split_email_string(emails));
}
},
_send_share_email_request:function(recipients){
var request_params={
recipients:recipients.slice(0,this.MAX_EMAIL_RECIPIENTS).join(' '),
salutation:this._helper.email_salutation(),
user_text:this._email_message_input_value()
};
Object.extend(request_params,this._helper.email_parameters());
var options={
method:'post',
parameters:request_params,
onSuccess:function(t,o){
this._on_end_share_email_request();
$('send_email_form').enable();
var json=t.responseJSON;
if(json.success){
this._on_share_email_success();
}else{
this._on_share_email_errors(json.errors);
}
}.bind(this),
onFailure:function(t,o){
this._on_end_share_email_request();
this._on_share_email_failure();
}.bind(this)
};
this._on_start_share_email_request();
new Ajax.Request(this._helper.email_creation_url(),options);
},
_on_share_email_success:function(){
$('email_server_status').update(this.SEND_EMAIL_SUCCESS);
$('email_addresses_input').value='';
$('email_message_input').value='';
this._pause_and_fade_server_status(function(){
this._send_email_button.enable();
}.bind(this));
},
_on_share_email_errors:function(errors){
if(errors&&errors.length){
this._display_error(this._create_error('email_addresses_input',errors[0]));
$('email_server_status').hide();
this._send_email_button.enable();
}else{
$('email_server_status').update(this.SEND_EMAIL_ERRORS);
this._pause_and_fade_server_status(function(){
this._send_email_button.enable();
}.bind(this));
}
},
_on_share_email_failure:function(){
$('email_server_status').update(this.SEND_EMAIL_FAILED);
},
_pause_and_fade_server_status:function(callback){
var email_server_status=$('email_server_status');
var options={
duration:750,
onComplete:function(){
with(email_server_status){
hide();
vshow();
}
if(callback){callback();}
}
};
setTimeout(function(){
var fade_effect=new fx.Opacity(email_server_status,options);
fade_effect.toggle();
},2500);
},
_email_message_input_value:function(){
var value=$('email_message_input').value;
return(value==this.EMAIL_SAMPLE_MESSAGE_TEXT)?'':value;
},
_on_start_share_email_request:function(){
with($('email_server_status')){
setOpacity(1);
style.display='block';
}
$('send_email_form').disable();
this._send_email_button.disable();
Loading.show();
},
_on_end_share_email_request:function(){
Loading.hide();
},
_validate_email_addresses:function(email_str){
var generic_error='Enter one or more email addresses separated by commas or spaces';
if(email_str.length==0||email_str==this.EMAIL_SAMPLE_ADDRESS_TEXT){return generic_error;}
var emails=this._split_email_string(email_str);
if(emails.length==0){return generic_error;}
var num_valid_addresses=0;
var error_str=null;
for(var i=0;i<emails.length;i++){
var address=emails[i];
if(address.length==0){continue;}
if(Glyde.is_valid.email_address(address)){
num_valid_addresses++;
}else{
error_str='"'+address+'" does not appear to be a valid email address';
return error_str;
}
}
if(num_valid_addresses>this.MAX_RECIPIENTS){
error_str='Please provide a maximum of '+this.MAX_RECIPIENTS+' email addresses';
}else if(num_valid_addresses==0){
error_str=generic_error;
}
return error_str;
},
_split_email_string:function(emails_str){
var split_regexp=emails_str.indexOf(",")>-1?/,\s*/:/\s+/;
return emails_str.split(split_regexp);
},
_setup_sample_text:function(input_element_id,sample_text,event_name){
event_name=event_name||'keydown';
var on_event=function(){
with($(input_element_id)){
value='';
removeClassName('sample_text');
stopObserving(event_name,on_event);
}
}.bindAsEventListener(this);
with($(input_element_id)){
value=sample_text;
observe(event_name,on_event);
}
},
_create_error:function(id,value){
return{id:id,value:value};
},
_display_error:function(error){
InputErrorNotice.create_all_no_load([error]);
InputErrorNotice.focusFirstError();
},
_on_open_badge_panel:function(){
var badge_html=this._to_badge_html().replace(/^\s+/,'');
$('badge_container').innerHTML=badge_html;
with($('badge_embed_code')){
value=badge_html;
observe('click',function(){$('badge_embed_code').select();});
}
$('badge_embed_help').innerHTML=
(Glyde.Browser.IE)?this.EMBED_HELP_IE:
(Glyde.Browser.MAC)?this.EMBED_HELP_OSX:
this.EMBED_HELP_WINDOWS;
var button_options={color:'blue',tooltip_text:'copy the code to the clipboard'};
var badge_embed_copy_button=new Glyde.ButtonWidget('badge_embed_copy_button','Copy Code',button_options);
badge_embed_copy_button.observe('widget:activate',function(){
Glyde.dom.copy_to_clipboard_ie(badge_html);
}.bind(this));
if(!Glyde.Browser.IE){badge_embed_copy_button.hide();}
with($('badge_embed_code')){
focus();
select();
}
},
_on_open_copy_link_panel:function(){
var link_url=this._helper.share_url();
with($('copy_link_code')){
value=link_url;
observe('click',function(){$('copy_link_code').select();});
}
$('copy_link_help').innerHTML=
(Glyde.Browser.IE)?this.COPY_LINK_HELP_IE:
(Glyde.Browser.MAC)?this.COPY_LINK_HELP_OSX:
this.COPY_LINK_HELP_WINDOWS;
var button_options={color:'blue',tooltip_text:'copy the code to the clipboard'};
var copy_link_button=new Glyde.ButtonWidget('copy_link_copy_button','Copy Code',button_options);
copy_link_button.observe('widget:activate',function(){
Glyde.dom.copy_to_clipboard_ie(link_url);
}.bind(this));
if(!Glyde.Browser.IE){copy_link_button.hide();}
with($('copy_link_code')){
focus();
select();
}
},
_on_activate_facebook_button:function(){
Glyde.share.open_facebook_window(this._helper.share_url());
},
_on_activate_myspace_button:function(event){
var share_params=$H({
fuseaction:'postto',
t:this._helper.myspace_title(),
c:this._helper.myspace_content(),
l:this._helper.myspace_location(),
u:this._helper.share_url()
});
var myspace_share_url='http://www.myspace.com/index.cfm?'+share_params.toQueryString();
window.open(myspace_share_url);
},
_strip_newlines:function(str){
return str.replace(/\n/g,'');
},
_set_container_ids:function(instance_num){
this._dialog_container_id='share_dialog_container';
this._container_id='share_dialog_content';
this._arrow_id='share_dialog_arrow';
this._close_button_id='share_dialog_close_button';
}
});
ShareDialogHelper=Class.create({
intialize:function(referral_code){
this._referral_code=referral_code;
},
dialog_title:function(){},
copy_link_panel_title:function(){},
email_panel_title:function(){return'Tell Your Friends';},
share_url:function(){},
hide_badge_button:function(){
return true;
},
email_subject:function(){},
email_salutation:function(){},
email_view_link:function(){},
email_farewell:function(){},
email_composite_image_url:function(){},
email_parameters:function(){return{};},
email_creation_url:function(){}
});
ShareEmailBuyHelper=Class.create(ShareDialogHelper,{
initialize:function($super,glu,percent_off_msrp,referral_code){
$super(referral_code);
this._glu=glu;
this._percent_off_msrp=percent_off_msrp;
this._vertical_name=Glyde.Glu.friendly_vertical_name(glu.vertical,false,false,true);
},
email_salutation:function(){
return this._email_salutation(this._percent_off_msrp);
},
email_parameters:function(){
return{
glu_id:this._glu.id
};
},
email_creation_url:function(){
return'/share_emails/create_buy';
}
});
ShareEmailListHelper=Class.create(ShareDialogHelper,{
initialize:function($super,glu,listing_id){
$super();
this._glu=glu;
this._listing_id=listing_id;
this._vertical_name=Glyde.Glu.friendly_vertical_name(glu.vertical,false,false,true);
},
email_salutation:function(){
return this._email_salutation();
},
email_parameters:function(){
return{
listing_id:this._listing_id
};
},
email_creation_url:function(){
return'/share_emails/create_listing';
}
});
ShareEmailSiteHelper=Class.create(ShareDialogHelper,{
email_salutation:function(){
return this._email_salutation();
},
email_creation_url:function(){
return'/share_emails/create_site';
}
});
SharePanelDialogHelper=Class.create(ShareDialogHelper,{
email_panel_title:function(){
return'Send Email';
},
myspace_title:function(){},
myspace_content:function(){},
myspace_location:function(){}
});
ShareCollectionHelper=Class.create(SharePanelDialogHelper,{
initialize:function(owner,is_owner,is_store,share_dialog,collection){
this._owner=owner;
this._collection=collection||{};
this._is_owner=is_owner;
this._is_store=is_store;
this._collection_type_label=(is_store)?'store':'media collection';
this._store_name=is_store?collection.store_name:owner.username;
this._collection_url=share_dialog.collection_base_url(is_store)+this._store_name;
this._front_page_url=share_dialog.front_page_url();
this._email_composite_image_url=this._composite_image_url(3,3,53,73,this._store_name);
this._facebook_composite_image_url=this._composite_image_url(3,3,42,58,this._store_name);
},
dialog_title:function(){
var owner_name=this._store_name;
var owner_label=(this._is_store)?'':(this._is_owner)?'your':owner_name+'\'s';
return'Share '+owner_label+' '+this._collection_type_label;
},
hide_badge_button:function(){
return!this._is_owner||this._is_store;
},
copy_link_panel_title:function(){
return'Copy '+this._collection_type_label+' link';
},
share_url:function(){
return this._collection_url;
},
email_subject:function(){
return this._email_subject_text();
},
email_salutation:function(){
return(this._is_owner)?this._email_collection_owner_salutation():
this._email_collection_non_owner_salutation();
},
email_view_link:function(){
return this._email_view_link();
},
email_farewell:function(){
return this._email_farewell(this._is_owner&&!this._is_store);
},
email_composite_image_url:function(){
return this._email_composite_image_url;
},
email_parameters:function(){
return{
subject_text:this.email_subject().replace(/\n/g,''),
farewell:this.email_farewell(),
view_link:this.email_view_link(),
composite_image_url:this.email_composite_image_url()
};
},
email_creation_url:function(){
return'/share_emails/create_collection';
},
myspace_title:function(){
return this._myspace_title();
},
myspace_content:function(){
return this._myspace_content();
},
myspace_location:function(){
return(this._is_owner)?3:2;
},
collection_url:function(){
return this._collection_url;
},
pregenerate_images:function(){
this._pregenerate_composite_image(this._email_composite_image_url);
this._pregenerate_composite_image(this._facebook_composite_image_url);
},
_pregenerate_composite_image:function(image_url){
var pregen_url='http://'+location.host+'/palettes/pregen_image';
var options={
method:'get',
parameters:{composite_image_url:image_url}
};
new Ajax.Request(pregen_url,options);
},
_composite_image_url:function(rows,columns,width,height,identifier){
var dims=rows+'/'+columns+'/'+width+'x'+height;
return'http://'+location.host+'/palettes/'+dims+'/'+identifier+'.jpg';
}
});
ShareCollectionItemHelper=Class.create(SharePanelDialogHelper,{
initialize:function(item,owner,is_owner,is_store,share_dialog,collection){
this._is_store=is_store;
if(this._is_store){
this._listing=item.listing;
var item_id=item.id;
}else{
this._listing=item;
var item_id=this._listing.attrs.id;
}
this._owner=owner;
this._is_owner=is_owner;
this._store_name=(collection&&is_store)?collection.store_name:owner.username;
this._listing_url=share_dialog.collection_base_url(is_store)+owner.username+'?open=true&item='+item_id;
this._front_page_url=share_dialog.front_page_url();
this._cover_url='http://'+location.host+'/'+this._listing.img_path(130,180);
},
dialog_title:function(){
var owner_label=(this._is_store)?'':(this._is_owner)?'your ':this._owner.username+'\'s ';
return'Share '+owner_label+'item';
},
hide_badge_button:function(){
return true;
},
copy_link_panel_title:function(){
return'Copy item link';
},
share_url:function(){
return this._listing_url;
},
email_subject:function(){
return this._email_item_subject_text(this._listing);
},
email_salutation:function(){
return this._email_item_salutation(this._listing);
},
email_view_link:function(){
return this._email_view_item_link();
},
email_farewell:function(){
return this._email_farewell();
},
myspace_title:function(){
return this._myspace_title();
},
myspace_content:function(){
return this._myspace_content();
},
myspace_location:function(){
return 2;
},
_midsentence_product_type:function(listing){
var type=listing.attrs.product_type;
return(type=='Book'||type=='Game')?type.toLowerCase():type;
}
});
ShareBuyItemHelper=Class.create(SharePanelDialogHelper,{
initialize:function(glu){
this._glu=glu;
this._vertical_name=this._midsentence_vertical_name(glu);
glu.glu_id=glu.id;
this._cover_url=Glyde.image.fully_qualified_cover_url_for_max_w_h(glu,130,180);
this._glu_url=Glyde.Glu.product_page_url(glu);
},
dialog_title:function(){
return'Share "'+this._glu.title.truncate_with_delimiters(25)+'"';
},
hide_badge_button:function(){
return true;
},
copy_link_panel_title:function(){
return"Copy item link";
},
share_url:function(){
return this._glu_url;
},
email_subject:function(){
return this._email_glu_subject_text(this._glu,this._vertical_name);
},
email_salutation:function(){
return this._email_glu_salutation(this._glu,this._vertical_name);
},
email_view_link:function(){
return this._email_view_link(this._glu);
},
email_farewell:function(){
var lowest_price=-1;
if(this._glu.lowest_price_cents!=null){
lowest_price=this._glu.lowest_price_cents;
}else{
this._glu.skus.each(function(sku){
if(sku.best_price.quantity>0){
if(lowest_price==-1||sku.best_price.cents<lowest_price){
lowest_price=sku.best_price.cents;
}
}
});
}
var price_str=(lowest_price==-1)?null:'$'+Glyde.Money.format_cents(lowest_price);
return this._email_glu_farewell(this._glu,price_str);
},
myspace_title:function(){
return this._myspace_title(this._glu);
},
myspace_content:function(){
return this._myspace_content(this._glu);
},
myspace_location:function(){
return 2;
},
_midsentence_vertical_name:function(glu){
var lookup={music:'CD',videos:'DVD',games:'game',books:'book'};
return lookup[glu.vertical];
}
});
ShareDialog.prototype._to_html=function(dialog_title,copy_link_panel_title,email_panel_title){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="common_dialog"');_j.s(' id="share_dialog"');_j.s('>');
_j.ns('<div');_j.s(' class="share_dialog_panel"');_j.s(' id="main_panel"');_j.s('>');
_j.ns('<div');_j.s(' class="title"');_j.s('>'+(dialog_title));
_j.ns('</div>');
_j.ns('<div');_j.s(' id="main_buttons_container"');_j.s('>');
_j.ns('<div');_j.s(' id="send_email_button"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' id="facebook_button"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' id="myspace_button"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' id="badge_button"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' id="copy_link_button"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="share_dialog_panel"');_j.s(' id="email_panel"');_j.s('>');
_j.ns('<div');_j.s(' class="title"');_j.s('>');
_j.ns(email_panel_title);
_j.ns('</div>');
_j.ns('<form');_j.s(' id="send_email_form"');_j.s(' onsubmit="'+('return false;')+'"');_j.s('>');
_j.ns('<div');_j.s(' class="field"');_j.s('>');
_j.ns('<label');_j.s(' for="'+('email_addresses_input')+'"');_j.s('>To');
_j.ns('</label>');
_j.ns('<input');_j.s(' class="sample_text"');_j.s(' id="email_addresses_input"');_j.s(' type="'+('text')+'"');_j.s('>');
_j.ns('</input>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="field"');_j.s('>');
_j.ns('<label');_j.s(' for="'+('email_message_input')+'"');_j.s('>Message');
_j.ns('</label>');
_j.ns('<div');_j.s(' id="email_server_status"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' id="email_message_preview_container"');_j.s('>');
_j.ns('</div>');
_j.ns('<textarea');_j.s(' class="sample_text"');_j.s(' id="email_message_input"');_j.s('>');
_j.ns('</textarea>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="widget_button_row"');_j.s('>');
_j.ns('<div');_j.s(' id="send_email_send_button"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</form>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="share_dialog_panel"');_j.s(' id="badge_panel"');_j.s('>');
_j.ns('<div');_j.s(' class="title"');_j.s('>');
_j.ns('Add Badge');
_j.ns('</div>');
_j.ns('<div');_j.s(' id="badge_container"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="field"');_j.s('>');
_j.ns('<textarea');_j.s(' class="code_box"');_j.s(' id="badge_embed_code"');_j.s(' readonly="'+('true')+'"');_j.s('>');
_j.ns('</textarea>');
_j.ns('</div>');
_j.ns('<div');_j.s(' id="badge_embed_help"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="widget_button_row"');_j.s('>');
_j.ns('<div');_j.s(' id="badge_embed_copy_button"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="share_dialog_panel"');_j.s(' id="copy_link_panel"');_j.s('>');
_j.ns('<div');_j.s(' class="title"');_j.s('>'+(copy_link_panel_title));
_j.ns('</div>');
_j.ns('<div');_j.s(' class="field"');_j.s('>');
_j.ns('<textarea');_j.s(' class="code_box"');_j.s(' id="copy_link_code"');_j.s(' readonly="'+('true')+'"');_j.s('>');
_j.ns('</textarea>');
_j.ns('</div>');
_j.ns('<div');_j.s(' id="copy_link_help"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="widget_button_row"');_j.s('>');
_j.ns('<div');_j.s(' id="copy_link_copy_button"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
ShareDialog.prototype._to_badge_html=function(){
var _j=new Jaml();
if(Glyde.user){
var logo_url="http://"+location.host+"/images/badges/button-100x24.png";
_j.ns('<a');_j.s(' href="'+(this._helper.share_url())+'"');_j.s(' title="'+('check out my collection at glyde.com')+'"');_j.s('>');
_j.ns('<img');_j.s(' src="'+(logo_url)+'"');_j.s(' width="'+('100')+'"');_j.s(' height="'+('24')+'"');_j.s(' border="'+('0')+'"');_j.s(' alt="'+('see my collection')+'"');_j.s(' />');
_j.ns('</a>');
}
return _j.v();
};
ShareCollectionHelper.prototype._email_subject_text=function(){
var _j=new Jaml();
if(this._is_owner){
_j.ns('Check out '+this._owner.name.capitalize_each_word()+'\'s '+this._collection_type_label);
}
else{
_j.ns(Glyde.user.name.capitalize_each_word()+' has shared a '+this._collection_type_label+' with you');
}
return _j.v();
};
ShareCollectionHelper.prototype._email_collection_owner_salutation=function(){
var _j=new Jaml();
var collection_label=(this._is_store)?' has a store':' has created a media collection';
_j.ns('<p');_j.s('>'+(this._owner.name.capitalize_each_word()+collection_label+' on Glyde and would like to share it with you.'));
_j.ns('</p>');
return _j.v();
};
ShareCollectionHelper.prototype._email_collection_non_owner_salutation=function(){
var _j=new Jaml();
_j.ns('<p');_j.s('>'+(Glyde.user.name.capitalize_each_word()+' thinks you will be interested in a '+this._collection_type_label+' on Glyde.'));
_j.ns('</p>');
return _j.v();
};
ShareCollectionHelper.prototype._email_collection_owner_farewell=function(){
var _j=new Jaml();
_j.ns('<p');_j.s('>'+('Have fun checking out '+Glyde.user.first_name.capitalize()+'\'s collection.'));
_j.ns('</p>');
return _j.v();
};
ShareCollectionHelper.prototype._email_view_link=function(){
var _j=new Jaml();
var collection_url=this._collection_url;
_j.ns('<p');_j.s('>');
_j.ns('<a');_j.s(' href="'+(collection_url)+'"');_j.s('>');
_j.ns('<img');_j.s(' src="'+(this._email_composite_image_url)+'"');_j.s(' style="'+('border: 1px solid black;')+'"');_j.s(' />');
_j.ns('</a>');
_j.ns('</p>');
_j.ns('<a');_j.s(' href="'+(collection_url)+'"');_j.s(' title="'+(collection_url)+'"');_j.s('>');
_j.ns('View it here');
_j.ns('</a>');
return _j.v();
};
ShareCollectionHelper.prototype._email_farewell=function(include_collection_owner_message){
var _j=new Jaml();
_j.ns('<p');_j.s('>'+('Want to organize and share your own collection? Sign up at <a href="'+this._front_page_url+'">glyde.com</a>.'));
_j.ns('</p>');
_j.ns('<p');_j.s('>'+('Glyde is the easiest and cheapest way to buy, sell, and organize your DVDs, CDs, games, and books.'));
_j.ns('</p>');
if(include_collection_owner_message){
_j.ns('<p');_j.s('>'+('Have fun checking out '+Glyde.user.first_name.capitalize()+'\'s collection.'));
_j.ns('</p>');
}
return _j.v();
};
ShareCollectionHelper.prototype._myspace_title=function(){
var _j=new Jaml();
var owner_label=(this._is_owner)?'My ':(this._owner.username+'\'s ');
_j.ns('Glyde: '+owner_label+this._collection_type_label+' of DVDs, CDs, games, and books');
return _j.v();
};
ShareCollectionHelper.prototype._myspace_content=function(){
var _j=new Jaml();
var collection_label=(this._is_store)?'store':'media collection';
if(this._is_owner){
_j.ns('<p');_j.s('>'+('Check out my '+this._collection_type_label+' of DVDs, CDs, video games, and books.'));
_j.ns('</p>');
}
else{
if(this._is_store){
_j.ns('<p');_j.s('>'+('Buy used and new DVD movies, music CDs, video games, and books at great prices.'));
_j.ns('</p>');
}
else{
_j.ns('<p');_j.s('>'+('View '+this._owner.username+'\'s collection on glyde.com, the cheapest and easiest way to buy, sell, and organize DVD movies, music CDs, video games, and books.'));
_j.ns('</p>');
}
}
_j.ns('<a');_j.s(' href="'+(this._collection_url)+'"');_j.s('>');
_j.ns('<img');_j.s(' src="'+(this._facebook_composite_image_url)+'"');_j.s(' style="'+('border: 1px solid black;')+'"');_j.s(' />');
_j.ns('</a>');
return _j.v();
};
ShareCollectionItemHelper.prototype._email_item_subject_text=function(listing){
var _j=new Jaml();
var name_label=(this._is_owner&&this._is_store)?this._owner.name:Glyde.user.name.capitalize_each_word();
_j.ns(name_label+' has shared the '+this._midsentence_product_type(listing)+' "'+listing.attrs.title+'" with you');
return _j.v();
};
ShareCollectionItemHelper.prototype._email_item_salutation=function(listing){
var _j=new Jaml();
var name_label=Glyde.page.is_user_bulk_seller()?Glyde.user.name.capitalize_each_word():(this._is_owner&&this._is_store)?this._owner.name:Glyde.user.first_name.capitalize();
_j.ns('<p');_j.s('>'+(name_label+' thinks you will be interested in the '+this._midsentence_product_type(listing)+' "'+listing.attrs.title+'".'));
_j.ns('</p>');
return _j.v();
};
ShareCollectionItemHelper.prototype._email_view_item_link=function(){
var _j=new Jaml();
if(this._listing.attrs.has_image){
_j.ns('<p');_j.s('>');
_j.ns('<a');_j.s(' href="'+(this._listing_url)+'"');_j.s('>');
_j.ns('<img');_j.s(' src="'+(this._cover_url)+'"');_j.s(' />');
_j.ns('</a>');
_j.ns('</p>');
}
_j.ns('<p');_j.s('>');
_j.ns('<a');_j.s(' href="'+(this._listing_url)+'"');_j.s('>'+('View it here'));
_j.ns('</a>');
_j.ns('</p>');
return _j.v();
};
ShareCollectionItemHelper.prototype._email_farewell=function(){
var _j=new Jaml();
_j.ns('<p');_j.s('>'+('Want to organize and share your own collection? Sign up at <a href="'+this._front_page_url+'">glyde.com</a>.'));
_j.ns('</p>');
_j.ns('<p');_j.s('>'+('Glyde is the easiest and cheapest way to buy, sell, and organize your DVDs, CDs, games, and books.'));
_j.ns('</p>');
return _j.v();
};
ShareCollectionItemHelper.prototype._myspace_title=function(){
var _j=new Jaml();
var collection_type_label=(this._is_store)?'store':'collection';
var product_type=this._midsentence_product_type(this._listing);
_j.ns('Glyde: "'+this._listing.attrs.title+'", a '+product_type+' in '+this._owner.username+'\'s '+collection_type_label+'.');
return _j.v();
};
ShareCollectionItemHelper.prototype._myspace_content=function(){
var _j=new Jaml();
var collection_type_label=(this._is_store)?'store':'collection';
var product_type=this._midsentence_product_type(this._listing);
if(this._is_owner&&!this._is_store){
_j.ns('<p');_j.s('>'+('Check out the '+product_type+' "'+this._listing.attrs.title+'" in my collection.'));
_j.ns('</p>');
}
else{
_j.ns('<p');_j.s('>'+('"'+this._listing.attrs.title+'", a '+product_type+' in '+this._owner.username+'\'s '+collection_type_label+'.'));
_j.ns('</p>');
}
if(this._listing.attrs.has_image){
_j.ns('<p');_j.s('>');
_j.ns('<a');_j.s(' href="'+(this._listing_url)+'"');_j.s('>');
_j.ns('<img');_j.s(' src="'+(this._cover_url)+'"');_j.s(' />');
_j.ns('</a>');
_j.ns('</p>');
}
else{
_j.ns('<p');_j.s('>');
_j.ns('<a');_j.s(' href="'+(this._listing_url)+'"');_j.s('>'+('View it here'));
_j.ns('</a>');
_j.ns('</p>');
}
return _j.v();
};
ShareBuyItemHelper.prototype._email_glu_subject_text=function(glu,vertical){
var _j=new Jaml();
_j.ns(Glyde.user.name.capitalize_each_word()+' has shared the '+vertical+' "'+glu.title+'" with you');
return _j.v();
};
ShareBuyItemHelper.prototype._email_glu_salutation=function(glu,vertical){
var _j=new Jaml();
_j.ns('<p');_j.s('>'+(Glyde.user.first_name.capitalize()+' thinks you will be interested in the '+vertical+' "'+glu.title+'".'));
_j.ns('</p>');
return _j.v();
};
ShareBuyItemHelper.prototype._email_view_link=function(glu){
var _j=new Jaml();
if(glu.has_image){
_j.ns('<p');_j.s('>');
_j.ns('<a');_j.s(' href="'+(this._glu_url)+'"');_j.s('>');
_j.ns('<img');_j.s(' src="'+(this._cover_url)+'"');_j.s(' />');
_j.ns('</a>');
_j.ns('</p>');
}
_j.ns('<p');_j.s('>');
_j.ns('<a');_j.s(' href="'+(this._glu_url)+'"');_j.s('>'+('View it here'));
_j.ns('</a>');
_j.ns('</p>');
return _j.v();
};
ShareBuyItemHelper.prototype._email_glu_farewell=function(glu,price){
var _j=new Jaml();
_j.ns('<p');_j.s('>');
if(price!=null){
_j.ns('"'+glu.title+'" is available for sale on <a href="'+this._glu_url+'">glyde.com</a> for as low as '+price+'. ');
}
_j.ns('Glyde is the easiest and cheapest way to buy and sell your DVDs, CDs, games, and books.');
_j.ns('</p>');
return _j.v();
};
ShareBuyItemHelper.prototype._myspace_title=function(glu){
var _j=new Jaml();
var creator=glu.creator?' - '+glu.creator:'';
_j.ns('Glyde: "'+glu.title+'"'+creator+' - '+this._vertical_name);
return _j.v();
};
ShareBuyItemHelper.prototype._myspace_content=function(glu){
var _j=new Jaml();
_j.ns('<p');_j.s('>'+('Buy or sell "'+glu.title+'" on glyde.com, the cheapest and easiest way to buy, sell, and organize DVD movies, music CDs, video games, and books.'));
_j.ns('</p>');
if(glu.has_image){
_j.ns('<p');_j.s('>');
_j.ns('<a');_j.s(' href="'+(this._glu_url)+'"');_j.s('>');
_j.ns('<img');_j.s(' src="'+(this._cover_url)+'"');_j.s(' />');
_j.ns('</a>');
_j.ns('</p>');
}
else{
_j.ns('<p');_j.s('>');
_j.ns('<a');_j.s(' href="'+(this._glu_url)+'"');_j.s('>'+('View it here'));
_j.ns('</a>');
_j.ns('</p>');
}
return _j.v();
};
ShareEmailBuyHelper.prototype._email_salutation=function(percent_off_msrp){
var _j=new Jaml();
var save_text=(percent_off_msrp>10)?' and saved '+percent_off_msrp+'%':'';
_j.ns('<p');_j.s('>'+(Glyde.user.first_name.capitalize()+' bought the '+this._vertical_name+' "'+this._glu.title+'" on glyde.com'+save_text+'.'));
_j.ns('</p>');
return _j.v();
};
ShareEmailListHelper.prototype._email_salutation=function(){
var _j=new Jaml();
_j.ns('<p');_j.s('>'+(Glyde.user.first_name.capitalize()+' thinks you might be interested in buying the '+this._vertical_name+' "'+this._glu.title+'" on glyde.com.'));
_j.ns('</p>');
return _j.v();
};
ShareEmailSiteHelper.prototype._email_salutation=function(){
var _j=new Jaml();
_j.ns('<p');_j.s('>'+(Glyde.user.first_name.capitalize()+' thinks you will be interested in '+'glyde.com'+' to simply buy and sell your video games, DVDs, CDs, and books.'));
_j.ns('</p>');
return _j.v();
};
ShareDialogHelper.prototype._email_farewell=function(){
var _j=new Jaml();
_j.ns('<p');_j.s(' style="'+('font-size:smaller;')+'"');_j.s('>');
_j.ns('Follow Glyde on <a href=\'http://twitter.com/glyde\'>Twitter</a> or <a href=\'http://www.facebook.com/glyde\'>Facebook</a>');
_j.ns('</p>');
_j.ns('<div');_j.s('>');
_j.ns('</div>');
return _j.v();
};
Glyde.widgets.LineupScroll=Class.create(Glyde.widgets.ScrollWidget,{
DOM_CLASS:'lineup_scroll_widget',
MEDIUM_NAME_CHAR_LIMIT:40,
PAGE_SIZE:1,
initialize:function($super,element,item_size,vertical,search_key,on_glu_selected_func){
this._item_size=item_size;
this._vertical=vertical;
this._search_key=search_key;
this._on_glu_selected_callback=on_glu_selected_func||Prototype.emptyFunction;
$super(element,this.PAGE_SIZE);
this._element.observe('click',this.handle_click.bindAsEventListener(this));
},
handle_click:function(e){
var target=Event.element(Event.get(e));
if(target&&target.id.indexOf('image_')!=-1){
var glu_id=target.id.split('image_')[1];
var glu=this._glus_map[glu_id];
this.submit_glu('lineup:submit',glu);
}
},
_render_pages:function(page_range,callback){
var item_start=page_range[0]*this._page_size;
var item_end=(page_range[1]+1)*this._page_size;
var render_func=function(json){
var total_items=Math.ceil(json.total/this._item_size);
var pages=[];
for(var c=page_range[0];c<=page_range[1];c++){
var start=(c-page_range[0])*this._page_size*this._item_size;
var stop=start+(this._page_size*this._item_size);
var glus=json.glus.slice(start,stop);
pages.push({page_index:c,
items:[this._render_lineup_cells(glus,json.total)]
});
}
(callback||this._on_pages_ready.bind(this))(pages,total_items);
this._add_to_glus_map(json.glus);
}.bind(this);
this._fetch_lineup_pages(page_range,render_func);
},
_fetch_lineup_pages:function(page_range,callback){
Loading.show();
new Ajax.Request('/glus/listing',{
evalScripts:true,
method:'get',
parameters:{res_id:this._search_key,
vertical:this._vertical,
include_glus_p:true,
offset:page_range[0]*this._page_size*this._item_size,
limit:(page_range[1]-page_range[0]+1)*this._page_size*this._item_size
},
onComplete:function(resp,o){
Loading.hide();
var json=resp.responseJSON;
if(json.success){
callback(json);
}else{
Glyde.page.handle_server_errors(json);
}
}.bind(this)
});
},
_add_to_glus_map:function(glus){
if(!this._glus_map){
this._glus_map={};
}
var i,res,len=glus.length;
for(i=0;i<len;++i){
res=glus[i];
this._glus_map[res.id]=res;
}
},
find_glu:function(id){
return this._glus_map[id];
},
cancel:function(){
this._glus_map={};
},
submit_glu:function(event_name,glu){
this._on_glu_selected_callback(glu.id,glu);
}
});
Glyde.widgets.LineupScroll.prototype._render_lineup_cells=function(items,total_items){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="scroll_item"');_j.s('>');
for(var c=0;c<items.length;c++){
_j.ns(this._render_lineup_cell(items[c],total_items));
}
_j.ns('</div>');
return _j.v();
};
Glyde.widgets.LineupScroll.prototype._render_lineup_cell=function(glu,total_items){
var _j=new Jaml();
var type_class=glu.type;
var s_dims=Glyde.image.dimensions_from_cover_url(Glyde.image.fully_qualified_cover_url_for_max_w_h(glu,140,190));
var l_dims=Glyde.image.dimensions_from_cover_url(Glyde.image.fully_qualified_cover_url_for_max_w_h(glu,155,210));
var med_name=((glu.show_year&&glu.orig_release_year)?('('+glu.orig_release_year+') '):'')+((glu.medium_name&&!glu.medium_name.match(/descriptor/))?glu.medium_name:'');
var cell_class=(total_items<this._item_size)?('lineup_cell fake_lineup_cell_'+total_items):'lineup_cell';
_j.ns('<div');_j.s(' class="'+('actionable sfloatl '+cell_class+' '+type_class)+'"');_j.s(' id="'+('lineup_cell_'+glu.id)+'"');_j.s('>');
var background_image_url=Glyde.image.fully_qualified_cover_url_for_max_w_h(glu,140,190,'d');
_j.ns('<div');_j.s(' class="item_info"');_j.s(' id="'+('item_info_'+glu.id)+'"');_j.s(' style="'+('background-image:url('+background_image_url+');')+'"');_j.s('>');
_j.ns('<a');_j.s(' class="image"');_j.s(' id="'+('image_'+glu.id)+'"');_j.s(' style="'+('background-image:none; background-repeat: no-repeat; height:'+s_dims.height+'px; width:'+(s_dims.width-1)+'px')+'"');_j.s('>');
_j.ns('</a>');
_j.ns('<div');_j.s(' class="extra_info"');_j.s(' id="'+('extra_info_'+glu.id)+'"');_j.s(' title="'+(glu.medium_name)+'"');_j.s('>');
_j.ns(med_name.truncate_with_delimiters(this.MEDIUM_NAME_CHAR_LIMIT,' - ')||'&nbsp;');
_j.ns('</div>');
_j.ns(glu.product_codes_html);
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
Glyde.widgets.ListingDetailsWidget=Class.create(Glyde.widgets.Widget,{
DOM_CLASS:'listing_details_widget',
SHOW_BOTH:1,
SHOW_CONDITION:2,
SHOW_PRICE:3,
GOOD_CONDITION_ID:3,
LISTABLE_ELEMENTS:['add_to_catalog_button'],
SELLABLE_ELEMENTS:['list_for_sale_button'],
initialize:function($super,element,glu,listing,start_cents,
start_condition_id,show_mode,charity_percentage,charity_id,charity_name,
is_charity_enabled,is_charity_immutable,select_z_index,disable_charity)
{
$super(element);
this._element.update(this._render());
this.show_mode=(show_mode||this.SHOW_BOTH);
this.condition_selector=new Glyde.widgets.ConditionSelectorWidget(this.$$('.condition_control_box')[0],this.on_condition_change.bind(this),(glu?glu.condition_type:null));
this.price_selector=this._price_selector(element,glu,start_cents,start_condition_id);
if(!disable_charity){
this._donation_selector=new Glyde.widgets.DonationSelectorWidget(this.$$first('.donation_selector'),is_charity_immutable,select_z_index);
}
this.reset(glu,listing,start_cents,start_condition_id,charity_percentage,charity_id,charity_name,is_charity_enabled);
},
_price_selector:function(element,glu,start_cents,start_condition_id){
return new Glyde.widgets.PriceSelector(element,glu,start_cents,start_condition_id);
},
on_condition_change:function(){
if(this._glu==null){return;}
this.condition_selector.select(this.condition_selector.selected_id(),this._glu.condition_type);
this.price_selector.on_condition_change(this.condition_selector.selected_id());
},
reset:function(glu,listing,cents,condition_id,charity_percentage,charity_id,charity_name,is_charity_enabled){
this._element.removeClassName('sellable');
this._element.removeClassName('not_sellable');
this._element.removeClassName('condition_only');
this._listing=(listing||null);
this._glu=(glu||null);
if(this._glu){
var cond_id=condition_id||this.GOOD_CONDITION_ID;
this.condition_selector.select(cond_id,this._glu.condition_type);
this.price_selector.reset(glu,cents,cond_id,(listing?listing.is_for_sale():false));
this.price_selector.on_condition_change(cond_id);
this._toggle_price_box(this._glu.is_sellable);
}
if(this._donation_selector){
this._donation_selector.reset(charity_percentage,charity_id,charity_name,is_charity_enabled);
}
},
glu:function(){
return this._glu;
},
cents:function(){
return this.price_selector.cents;
},
condition_id:function(){
return this.condition_selector.selected_value();
},
donation_selector:function(){
return this._donation_selector;
},
charity_search_input_id:function(){
return this._donation_selector.charity_search_input_id();
},
charity_percent_select_menu_id:function(){
return this._donation_selector.select_menu_id();
},
charity_id:function(){
return this._donation_selector.charity_id();
},
charity_name:function(){
return this._donation_selector.charity_name();
},
charity_percentage:function(){
return this._donation_selector.charity_percentage();
},
market_price_cents:function(){
return this.price_selector.market_price_cents();
},
serialize:function(){
var hash={
'listing[price]':this.price_selector.cents/100,'sku[condition_id]':this.condition_selector.selected_value(),
'sku[glu_id]':this._glu.id
};
if(this._donation_selector){
Object.extend(hash,{
'listing[charity_id]':this.charity_id(),
'listing[charity_name]':this.charity_name(),
'listing[charity_percentage]':this.charity_percentage()
});
}
return hash;
},
_toggle_price_box:function(is_sellable){
if(this.show_mode==this.SHOW_CONDITION){
this._element.addClassName('condition_only');
return;
}
if(is_sellable){
this._element.addClassName('sellable');
}else{
this._element.addClassName('not_sellable');
}
this.LISTABLE_ELEMENTS.each(function(element_id){
if($(element_id)){
$(element_id).style.display=(is_sellable?'none':'block');
}
});
this.SELLABLE_ELEMENTS.each(function(element_id){
if($(element_id)){
$(element_id).style.display=(is_sellable?'block':'none');
}
});
if(Glyde.Browser.IE){
function toggle_visibility_for_elements(elements){
$A(elements).each(function(id){
var elem=$(id);
if(elem){elem.style.visibility=(is_sellable?'visible':'hidden');}
});
}
toggle_visibility_for_elements(['donation_checkbox','listing_price_text','proceeds_info_icon']);
var price_buttons=this.$$('.price_button');
toggle_visibility_for_elements(price_buttons);
}
}
});
Glyde.widgets.ListingDetailsWidget.prototype._render=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="condition_control_box"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="price_control_box"');_j.s('>');
_j.ns('<div');_j.s(' class="header"');_j.s('>Price');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="contents"');_j.s('>');
_j.ns('<div');_j.s(' class="custom_price"');_j.s('>');
_j.ns('<div');_j.s(' class="listing_price"');_j.s('>');
_j.ns('<div');_j.s(' id="listing_price_text_box"');_j.s('>');
_j.ns('<div');_j.s(' class="sfloatl"');_j.s('>$');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="listing_price_text sfloatl"');_j.s('>&nbsp;');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="sfloatl"');_j.s('>');
_j.ns('<div');_j.s(' class="price_buttons_div"');_j.s(' id="price_buttons"');_j.s('>');
_j.ns('<a');_j.s(' class="price_up a_button price_button"');_j.s(' href="'+('javascript:void(0)')+'"');_j.s('>');
_j.ns('</a>');
_j.ns('<a');_j.s(' class="price_down a_button price_button"');_j.s(' href="'+('javascript:void(0)')+'"');_j.s('>');
_j.ns('</a>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="best_price_container"');_j.s('>');
_j.ns('<div');_j.s(' class="best_price"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="donation_selector"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="not_sellable_price_box"');_j.s('>');
_j.ns('<div');_j.s(' class="header"');_j.s('>Notice');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="contents"');_j.s('>');
_j.ns('<div');_j.s(' class="can_not_sell_text"');_j.s('>');
_j.ns('This item is one of very few that cannot currently be sold on Glyde.');
_j.ns('<br');_j.s(' />');
_j.ns('<br');_j.s(' />');
_j.ns('Add this item to your collection now and it will be possible to sell in the future.');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
var CollectionScrollWidget=Class.create(Glyde.widgets.ScrollWidget,{
DOM_CLASS:'collection_scroll_widget',
PAGE_SIZE:7,
PAGE_SIZE_FB:5,
initialize:function($super,element){
$super(element,Glyde.page.is_facebook()?this.PAGE_SIZE_FB:this.PAGE_SIZE);
this.$$('.scroll_control')[0].insert('Your Items For Sale <span class="scroll_total"></span>');
this._listing_dialog=new ListingDialog();
this._listings_cache={};
Glyde.notify.subscribe(Listing.EVENT_UPDATED,
this.handle_listing_object_update.bind(this));
Glyde.notify.subscribe(Listing.EVENT_DELETED,
this.handle_listing_object_update.bind(this));
},
click_handler:function($super,e){
$super(e);
var target=e.element();
if(target.className=='cover'){
var listing_id=target.id.split('_')[1];
var json=this._listings_cache[listing_id];
var listing=new Listing(json);
this._listing_dialog.open(listing,target);
}
},
handle_listing_object_update:function(event_name,listing){
Loading.hide();
if(event_name==Listing.EVENT_DELETED){
Glyde.page.flash_notice('"'+listing.attrs.title+'"'+' has been deleted.');
this.refresh(this.current_page);
}
else if(listing.just_delisted()){
Glyde.page.flash_notice('"'+listing.attrs.title+'"'+' has been delisted.');
this.refresh(this.current_page);
}else{
Glyde.page.flash_notice('"'+listing.attrs.title+'"'+' has been updated.');
}
listing.modified_attrs=[];
},
_on_initial_load_complete:function($super){
$super();
this._update_item_count();
},
add_new_item:function(item){
this.refresh();
},
_update_item_count:function(){
this.$$('.scroll_total')[0].innerHTML='('+this.num_items()+')';
},
_render_pages:function(page_range,callback){
var item_start=page_range[0]*this._page_size;
var item_end=(page_range[1]+1)*this._page_size;
var options={
parameters:{
for_sale:true,
offset:item_start,
limit:item_end-item_start
},
method:'get',
onComplete:function(resp,o){
var data=resp.responseJSON;
if(data.success){
var total_items=data.total;
var pages=[];
for(var c=page_range[0];c<=page_range[1];c++){
var start=(c-page_range[0])*this._page_size;
var stop=start+this._page_size;
this._add_to_listings_cache(data.listings);
pages.push({page_index:c,items:data.listings.slice(start,stop).map(this._item_html.bind(this))});
}
(callback||this._on_pages_ready.bind(this))(pages,total_items);
}else{
Glyde.page.handle_server_errors(data);
}
}.bind(this)
};
new Ajax.Request('/listings/image_index.js',options);
},
_add_to_listings_cache:function(listings_json){
var i,listing;
for(i=0;i<listings_json.length;++i){
this._listings_cache[listings_json[i].id]=listings_json[i];
}
}
});
CollectionScrollWidget.prototype._item_html=function(item){
var _j=new Jaml();
var background_image_url=Glyde.image.fully_qualified_cover_url_for_max_w_h(item,84,117,Glyde.page.is_facebook()?'h':'b');
var dims=Glyde.image.dimensions_from_cover_url(background_image_url);
var style="background-image: url('"+background_image_url+"')";
_j.ns('<div');_j.s(' class="scroll_item '+(item._new?'new':'')+'"');_j.s(' style="'+(style)+'"');_j.s('>');
_j.ns('<a');_j.s(' class="cover"');_j.s(' id="'+('cover_'+item.id)+'"');_j.s(' style="'+("width: "+dims.width+"px; height: "+dims.height+"px;")+'"');_j.s('>');
_j.ns('</a>');
_j.ns('<div');_j.s(' class="scroll_item_info"');_j.s('>'+(item.created_at.strftime("%m/%d/%y")));
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
Glyde.widgets.Checkbox=Class.create(Glyde.widgets.Widget,{
DOM_CLASS:'checkbox_widget',
initialize:function($super,el,toggle){
$super(el);
if(!this._element)return;
if(this.is_disabled()){
this._remove_onclick();
}
if(toggle){
this.toggle();
}
},
is_checked:function(){
return(this._element.className.indexOf('checked')!=-1);
},
is_disabled:function(){
return(this._element.className.indexOf('disabled')!=-1);
},
checked:function(bool){
if(bool){
if(!this.is_checked()){
this._element.className+=' checked';
}
}else{
this._element.className=this._element.className.replace(' checked','');
}
},
toggle:function(){
if(!this.is_disabled()){
this.checked(!this.is_checked());
}
},
dom_element:function(){
return this._element;
},
id:function(){
return this._element.id;
},
_restore_onclick:function(){
if(this._element._onclick){
this._element.onclick=this._element._onclick;
this._element._onclick=null;
}
},
_remove_onclick:function(){
if(!this._element._onclick){
this._element._onclick=this._element.onclick;
this._element.onclick=Glyde.empty_function;
}
}
});
var HowToDialog=Class.create(Glyde.Dialog,{
initialize:function($super,html_url){
$super();
this._html_url=html_url;
this._fetch_html();
},
open:function($super){
ConversionTracker.get_instance().track('/how_to_dialog/open'+this._html_url);
if(this._content_html){
$super(null,this._content_html);
}else{
this._fetch_html(function(resp,o){
var data=resp.responseJSON;
if(data&&data.success){
$super(null,data.html);
}
}.bind(this));
}
$(this._container_id).addClassName('how_to_widget');
},
_fetch_html:function(callback){
var options={
method:'get',
onComplete:callback||this._on_after_html_load.bind(this),
trackRequest:false
};
new Ajax.Request(this._html_url,options);
},
_on_after_html_load:function(resp,o){
var data=resp.responseJSON;
if(data&&data.success){
this._content_html=data.html;
}
},
_set_container_ids:function(instance_num){
this._dialog_container_id='how_to_dialog_container';
this._container_id='how_to_dialog';
this._arrow_id='how_to_dialog_arrow';
this._close_button_id='how_to_dialog_close_button';
}
});
var CharitySearchWidget=Class.create(Glyde.widgets.Widget,{
DOM_CLASS:'charity_search_widget',
DEFAULT_INITIAL_TEXT:'find a charity...',
EVENT_CHARITY_SELECTED:'charity_search:charity_selected',
EVENT_SEARCH_INPUT_FOCUSED:'charity_search:search_input_focussed',
STATES:{
NEW:'new',
ACTIVE:'active',
SELECTED:'selected'
},
initialize:function($super,element,width,max_selected_title_length,initial_text,in_stock_only){
$super(element);
this._search_input_id='charity_search_input_'+CharitySearchWidget.instance_id++;
this._element.update(this._search_box_html(width,this._search_input_id));
this._max_selected_title_length=max_selected_title_length;
this._set_state(this.STATES.NEW);
var search_input=this._search_input();
search_input.value=initial_text||this.DEFAULT_INITIAL_TEXT;
search_input.observe('keydown',this._on_key_down.bindAsEventListener(this));
this._suggest_input=new CharityLiveSearchInput(search_input,Glyde.urls.title_suggestions_url,
this._on_select.bind(this),['charities'],in_stock_only,in_stock_only,this);
},
search_input_id:function(){
return this._search_input_id;
},
is_selected:function(){
return this._state==this.STATES.SELECTED;
},
selected_id:function(){
return(this.is_selected())?this._selected_charity_id:null;
},
selected_name:function(){
return(this.is_selected())?this._selected_charity_name:null;
},
select_charity:function(charity_id,charity_name){
this._select(charity_id,charity_name);
},
_on_select:function(result){
this._select(result.charity_id,result.title);
},
_select:function(charity_id,charity_name){
this._set_state(this.STATES.SELECTED);
var search_input=this._search_input();
var selected_title=charity_name;
if(selected_title.length>this._max_selected_title_length){
selected_title=this._truncate_title(charity_name);
search_input.title=charity_name;
}
search_input.value=selected_title;
this._selected_charity_id=charity_id;
this._selected_charity_name=charity_name;
search_input.blur();
Glyde.notify.publish(this.EVENT_CHARITY_SELECTED,{charity_id:charity_id,name:charity_name});
},
on_search_box_focus:function(event){
this._reset_state_if_necessary();
Glyde.notify.publish(this.EVENT_SEARCH_INPUT_FOCUSED,{id:this._search_input_id});
},
_on_key_down:function(event){
this._reset_state_if_necessary();
},
_reset_state_if_necessary:function(){
if(this._state==this.STATES.NEW||this._state==this.STATES.SELECTED){
this._search_input().value='';
this._set_state(this.STATES.ACTIVE);
}
},
_set_state:function(new_state){
if(this._state){this._element.removeClassName(this._state+'_'+this.DOM_CLASS);}
this._state=new_state;
this._element.addClassName(this._state+'_'+this.DOM_CLASS);
this._search_input().title='';
},
_truncate_title:function(title_text){
if(title_text.length<=this._max_selected_title_length){
return title_text;
}
var index=title_text.lastIndexOf(' ',this._max_selected_title_length);
return title_text.substring(0,(index==-1?len:index))+'...';
},
_search_input:function(){
return this.$$first('.charity_search_box');
}
});
CharitySearchWidget.instance_id=0;
var CharityLiveSearchInput=Class.create(LiveSearchInput,{
initialize:function($super,
input_element,
list_update_path,
on_complete,
selected_domains,
is_buy_side,
hide_out_of_stock,
charity_search_widget)
{
this._charity_search_widget=charity_search_widget;
$super(input_element,list_update_path,on_complete,selected_domains,is_buy_side,hide_out_of_stock);
},
_on_focus:function($super,event){
this._charity_search_widget.on_search_box_focus();
$super(event);
}
});
CharitySearchWidget.prototype._search_box_html=function(box_width,search_input_id){
var _j=new Jaml();
var left_end_cap_width=18;
var right_end_cap_width=8;
var end_caps_width=left_end_cap_width+right_end_cap_width;
var middle_width=box_width-end_caps_width;
var input_width=middle_width;
_j.ns('<div');_j.s(' class="left_cap"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="middle"');_j.s(' style="'+('width: '+middle_width+'px')+'"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="right_cap"');_j.s('>');
_j.ns('</div>');
_j.s('<!-- ');_j.s('/ put \'find a charity store...\' as default value?');
_j.s('-->');
_j.ns('<input');_j.s(' class="charity_search_box"');_j.s(' id="'+(search_input_id)+'"');_j.s(' type="'+('text')+'"');_j.s(' autocomplete="'+('off')+'"');_j.s(' style="'+('width: '+input_width+'px')+'"');_j.s('>');
_j.ns('</input>');
return _j.v();
};
Glyde.widgets.DonationSelectorWidget=Class.create(Glyde.widgets.Widget,{
DOM_CLASS:'donation_selector_widget',
PERCENTAGE_OPTIONS:[
{text:'25%',value:{key:25,selected_text:'25%'}},
{text:'50%',value:{key:50,selected_text:'50%'}},
{text:'75%',value:{key:75,selected_text:'75%'}},
{text:'100%',value:{key:100,selected_text:'100%'}}
],
initialize:function($super,element,immutable,select_z_index){
$super(element);
this._instance_id=Glyde.widgets.DonationSelectorWidget.instance_id++;
this._element.update(this._html(this._instance_id,immutable));
var select_node=this.$$first('.donation_percent_select');
this._percent_select=new SelectWidget(select_node,{items:this.PERCENTAGE_OPTIONS,titles:null},null,{z_index:select_z_index});
this._charity_search=new CharitySearchWidget(this.$$first('.charity_search'),281,38);
Glyde.notify.subscribe(this._charity_search.EVENT_CHARITY_SELECTED,this._on_charity_selected.bind(this));
if(immutable){
this._immutable=true;
this._element.addClassName('donation_selector_widget_immutable');
}else{
this.$$first('.main_container').observe('click',this._on_container_click.bindAsEventListener(this));
var checkbox_node=this.$$first('.donation_checkbox');
this._checkbox=new Glyde.widgets.Checkbox(checkbox_node);
this.$$first('.checkbox_container').observe('click',this._on_checkbox_click.bindAsEventListener(this));
if(Glyde.Browser.FF){Glyde.notify.subscribe(this._charity_search.EVENT_SEARCH_INPUT_FOCUSED,this._on_charity_search_focus.bind(this));}
}
},
show_no_charity_error:function(){
this._set_charity_search_error();
},
charity_search_input_id:function(){
return this._charity_search.search_input_id();
},
select_menu_id:function(){
return this._percent_select.menu_id();
},
charity_id:function(){
return(this._immutable||this._enabled)?this._charity_search.selected_id():null;
},
charity_name:function(){
return(this._immutable||this._enabled)?this._charity_search.selected_name():null;
},
charity_percentage:function(){
return(this._immutable||this._enabled)?this._percent_select.selected_item().value.key:null;
},
reset:function(percentage,charity_id,charity_name,is_enabled){
if(percentage){this._percent_select.select(percentage);}
if(charity_id){this._charity_search.select_charity(charity_id,charity_name);}
if(!this._immutable){
if(is_enabled){
this.enable();
}else{
this.disable();
}
}
},
is_enabled:function(){
return this._enabled;
},
is_charity_selected:function(){
return this._immutable||this._charity_search.is_selected();
},
enable:function(){
this._update_enabled(true);
},
disable:function(){
this._update_enabled(false);
},
_charity_search_container:function(){
return this.$$first('.charity_search_container');
},
_on_charity_search_focus:function(event_name,event_info){
if(event_info.id==this._charity_search.search_input_id()){this.enable();}
},
_on_checkbox_click:function(event){
if(this._enabled){this._clear_charity_search_error();}
this._update_enabled(!this._enabled);
},
_on_container_click:function(event){
if(!this._enabled){this._update_enabled(true);}
},
_set_charity_search_error:function(){
if(!this._missing_charity_error){
this._charity_search_container().addClassName('charity_search_container_error');
this._missing_charity_error=true;
}
},
_clear_charity_search_error:function(){
if(this._missing_charity_error){
this._charity_search_container().removeClassName('charity_search_container_error');
this._missing_charity_error=false;
}
},
_on_charity_selected:function(){
this._clear_charity_search_error();
},
_update_enabled:function(enabled){
if(enabled==this._enabled){return;}
this._enabled=enabled;
this._checkbox.checked(enabled);
var enabled_class=this.DOM_CLASS+'_enabled';
var disabled_class=this.DOM_CLASS+'_disabled';
this._element.addClassName(enabled?enabled_class:disabled_class);
this._element.removeClassName(enabled?disabled_class:enabled_class);
}
});
Glyde.widgets.DonationSelectorWidget.instance_id=0;
Glyde.widgets.DonationSelectorWidget.prototype._html=function(instance_id,immutable){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="checkbox_container"');_j.s('>');
_j.ns('<a');_j.s(' class="donation_checkbox button"');_j.s(' href="'+('javascript:void(0)')+'"');_j.s('>');
_j.ns('</a>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="main_container"');_j.s('>');
_j.ns('<div');_j.s(' class="donation_percent_line"');_j.s('>');
_j.ns('<div');_j.s(' class="donate_percent_prefix_text"');_j.s('>');
_j.ns('Donate');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="donation_percent_select"');_j.s(' id="'+('donation_percent_select_'+instance_id)+'"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="donate_percent_postfix_text"');_j.s('>');
_j.ns('of the proceeds'+(immutable?'.':' to:'));
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="charity_search_container"');_j.s(' id="'+('charity_search_container_'+instance_id)+'"');_j.s('>');
_j.ns('<div');_j.s(' class="charity_search"');_j.s(' id="'+('charity_search_'+instance_id)+'"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
Glyde.widgets.AbstractShareButtonsWidget=Class.create(Glyde.widgets.Widget,{
DOM_CLASS:'share_buttons_widget',
SHARE_TYPE:null,initialize:function($super,element,opts){
$super(element);
this._options={
small:false,
referral_code:Glyde.user.referral_code
};
Object.extend(this._options,opts||{});
if(this._options.small)this._element.addClassName('small_share_buttons');
this._element.update(this._render());
this._element.disable_drag_selection();
['email','facebook','twitter'].each(function(button_name){
this.$$first('.'+button_name+'_share_button').observe('click',function(event){
this._show_click_response(event.target);
this['_'+button_name+'_click_handler'](event);
if(typeof ConversionTracker!='undefined'){
ConversionTracker.get_instance().doGAFunction('_trackEvent','Share-'+this.SHARE_TYPE,button_name,[this._shared_item(),'open'].join('-'));
}
}.bindAsEventListener(this));
}.bind(this));
},
email_dialog_node:function(){
return this._share_dialog?$(this._share_dialog._dialog_container_id):null;
},
_email_click_handler:function(event){
if(this._share_dialog==null){this._share_dialog=new ShareDialog();}
},
_facebook_click_handler:function(event){
},
_facebook_publish:function(url,publish_data){
var self=this;
function onResponse(resp){
if(resp&&resp.post_id){
ConversionTracker.get_instance().doGAFunction('_trackEvent','Share-'+self.SHARE_TYPE,'facebook',[self._shared_item(),'published'].join('-'));
}else{
ConversionTracker.get_instance().doGAFunction('_trackEvent','Share-'+self.SHARE_TYPE,'facebook',[self._shared_item(),'canceled'].join('-'));
}
}
Glyde.share.open_facebook_window(url,publish_data,this.SHARE_TYPE,this._options.referral_code,onResponse);
},
_twitter_click_handler:function(event){
},
_show_click_response:function(target){
var clicked_class='share_button_clicked';
target.addClassName(clicked_class);
Element.removeClassName.delay(0.3,target,clicked_class);
},
is_referral:function(){
return this._options.referral_code!=null;
},
_shared_item:function(){
}
});
Glyde.widgets.AbstractShareButtonsWidget.prototype._render=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="share_buttons_container"');_j.s('>');
_j.ns('<a');_j.s(' class="'+('facebook_share_button')+'"');_j.s(' href="'+('javascript: void(0)')+'"');_j.s(' title="'+('Share on Facebook')+'"');_j.s('>');
_j.ns('</a>');
_j.ns('<a');_j.s(' class="'+('twitter_share_button')+'"');_j.s(' href="'+('javascript: void(0)')+'"');_j.s(' title="'+('Share on Twitter')+'"');_j.s('>');
_j.ns('</a>');
_j.ns('<a');_j.s(' class="'+('email_share_button')+'"');_j.s(' href="'+('javascript: void(0)')+'"');_j.s(' title="'+('Send an email')+'"');_j.s('>');
_j.ns('</a>');
_j.ns('</div>');
return _j.v();
};
Glyde.widgets.ShareButtonsSiteWidget=Class.create(Glyde.widgets.AbstractShareButtonsWidget,{
SHARE_TYPE:'site',
initialize:function($super,element,opts){
$super(element,opts);
},
_email_click_handler:function($super,event){
$super(event);
this._share_dialog.open_email_site_share(event.target,true,this._options.referral_code);
},
_facebook_click_handler:function($super,event){
$super(event);
var publish_data={
message:this._facebook_message(),
title:Glyde.tagline,
image:Glyde.image.fully_qualified_url('images/logo-email.png'),
prompt:'Tell your friends about Glyde'
};
this._facebook_publish('http://'+Glyde.config.server_name,publish_data);
},
_twitter_click_handler:function($super,event){
$super(event);
Glyde.share.open_twitter_window(this._tweet());
},
_facebook_message:function(){
return'Check out glyde.com - get great deals and easily make money selling your stuff';
},
_tweet:function(){
return['Try glyde.com to simply buy and sell your video games, DVDs, CDs, and books. Great deals. Selling made simple.',Glyde.TinyUrl.home_page(this._options.referral_code)].join(' ');
},
_shared_item:function(){
return'homepage';
}
});
Glyde.widgets.AbstractNotificationWidget=Class.create(Glyde.widgets.Widget,{
DOM_CLASS:'notification_widget',
initialize:function($super,element){
$super(element);
this._notifications=this._notifications_by_priority();
this.refresh(true);
if(!Glyde.user){Glyde.notify.subscribe('login:succeeded',this._on_login.bind(this));}
Glyde.notify.subscribe(Glyde.AbstractNotification.UPDATED_EVENT,this._on_notification_updated.bind(this));
},
refresh:function(first_time){
var active_notification;
var active_notifications=[];
active_notifications=this._notifications.select(function(notification,index){
return notification.is_active(first_time);
});
active_notification=active_notifications.pop();
active_notifications.each(function(notification,index){
var rand=Math.random();
if(rand>0.5){
active_notification=notification;
throw $break;
}
});
if(active_notification){
this._element.show();
this._show_notification(active_notification);
}else{
this._element.hide();
}
},
_show_notification:function(notification){
this._element.update(notification.render());
notification.on_render_complete(this._element);
},
_on_login:function(){
this._notifications.each(function(notification){
if(notification.on_login){notification.on_login();}
});
},
_on_notification_updated:function(event_name,info){
this.refresh();
},
_notifications_by_priority:function(){
}
});
Glyde.widgets.BuyNotificationWidget=Class.create(Glyde.widgets.AbstractNotificationWidget,{
_notifications_by_priority:function(){
return[
new Glyde.AccountCreditNotification(),
new Glyde.ReferFriendNotification(),
new Glyde.MarketPriceNotification(),
new Glyde.DefaultBuyNotification()
];
}
});
Glyde.widgets.SellNotificationWidget=Class.create(Glyde.widgets.AbstractNotificationWidget,{
_notifications_by_priority:function(){
return[
new Glyde.MarketPriceNotification(),
new Glyde.ReferFriendNotification(),
new Glyde.DefaultSellNotification()
];
}
});
Glyde.widgets.DonateNotificationWidget=Class.create(Glyde.widgets.AbstractNotificationWidget,{
_notifications_by_priority:function(){
return[
new Glyde.MarketPriceNotification(),
new Glyde.DefaultDonateNotification()
];
}
});
Glyde.AbstractNotification=Class.create({
is_active:function(first_time){},
render:function(){},
on_render_complete:function(notification_node){},
on_login:null
});
Glyde.AbstractNotification.UPDATED_EVENT='notification:updated';
Glyde.MarketPriceNotification=Class.create(Glyde.AbstractNotification,{
REPRICE_MESSAGE:'market_price_notification:reprice',
initialize:function(){
if(Glyde.user){
Glyde.notify.subscribe(Glyde.user.stats.CHANGE_EVENT,this.on_user_stat_change.bind(this));
}
},
is_active:function(){
return Glyde.user&&Glyde.user.stats.num_listings_above_market_price();
},
on_render_complete:function(notification_node){
notification_node.select('.market_reprice_link')[0].observe('click',function(event){
Glyde.notify.publish(this.REPRICE_MESSAGE);
}.bindAsEventListener(this));
},
on_login:function(){
Glyde.notify.subscribe(Glyde.user.stats.CHANGE_EVENT,this.on_user_stat_change.bind(this));
if(Glyde.user.stats.num_listings_above_market_price()){
Glyde.notify.publish(Glyde.AbstractNotification.UPDATED_EVENT,{notification:this});
}
},
on_user_stat_change:function(event_name,event_data){
if(event_data.property_name=='num_listings_above_market_price'){
Glyde.notify.publish(Glyde.AbstractNotification.UPDATED_EVENT,{notification:this});
}
}
});
Glyde.AccountCreditNotification=Class.create(Glyde.AbstractNotification,{
MIN_CREDIT_CENTS:500,initialize:function(){
Glyde.notify.subscribe('buy_box:stored_credit_amount_changed',this._on_stored_credit_amount_changed.bind(this));
},
is_active:function(){
return Glyde.user&&Glyde.user.available_account_cents>=this.MIN_CREDIT_CENTS;
},
render:function(){
var formatted_balance=Glyde.Money.format_cents(Glyde.user.available_account_cents);
return['You have $',formatted_balance,' credit in your Glyde account. Why not buy something?'].join('');
},
on_login:function(){
if(Glyde.user.available_account_cents>=this.MIN_CREDIT_CENTS){
Glyde.notify.publish(Glyde.AbstractNotification.UPDATED_EVENT,{notification:this});
}
},
_on_stored_credit_amount_changed:function(){
Glyde.notify.publish(Glyde.AbstractNotification.UPDATED_EVENT,{notification:this});
}
});
Glyde.DefaultBuyNotification=Class.create(Glyde.AbstractNotification,{
MAX_NOVICE_USER_PURCHASE_ORDERS:2,
MAX_NOVICE_USER_LISTINGS:2,
initialize:function(){
Glyde.notify.subscribe('buy_box:num_purchase_orders_changed',this._on_num_purchase_orders_changed.bind(this));
},
is_active:function(first_time){
return(first_time)?!this._is_experienced_user():true;
},
on_render_complete:function(notification_node){
this._create_how_to_buy_handlers(notification_node);
this._create_how_to_sell_handlers(notification_node);
},
_is_experienced_user:function(){
return Glyde.user&&(Glyde.user.stats.num_purchase_orders()>this.MAX_NOVICE_USER_PURCHASE_ORDERS||
Glyde.user.stats.num_listings()>this.MAX_NOVICE_USER_LISTINGS);
},
_on_num_purchase_orders_changed:function(){
Glyde.notify.publish(Glyde.AbstractNotification.UPDATED_EVENT,{notification:this});
},
_create_how_to_buy_handlers:function(notification_node){
if(this._how_to_buy==null){this._how_to_buy=new HowToDialog('/how_to_buy_widget');}
notification_node.select('.buy_learn_more')[0].observe('click',function(event){
this._how_to_buy.open();
event.stop();
}.bindAsEventListener(this));
},
_create_how_to_sell_handlers:function(notification_node){
if(this._how_to_sell==null){this._how_to_sell=new HowToDialog('/how_to_sell_widget');}
notification_node.select('.sell_learn_more')[0].observe('click',function(event){
this._how_to_sell.open();
event.stop();
}.bindAsEventListener(this));
},
_how_to_buy_url:function(){
return this._how_to_url('buy');
},
_how_to_sell_url:function(){
return this._how_to_url('sell');
},
_how_to_url:function(action){
return['http://',window.location.host,'/how-to-',action].join('');
}
});
Glyde.DefaultSellNotification=Class.create(Glyde.DefaultBuyNotification,{
on_render_complete:function(notification_node){
this._create_how_to_sell_handlers(notification_node);
},
_is_experienced_user:function(){
return Glyde.user&&Glyde.user.stats.num_listings()>this.MAX_NOVICE_USER_LISTINGS;
}
});
Glyde.DefaultDonateNotification=Class.create(Glyde.DefaultSellNotification,{
on_render_complete:function(notification_node){
},
_is_experienced_user:function(){
return Glyde.user&&Glyde.user.stats.num_listings()>this.MAX_NOVICE_USER_LISTINGS;
},
_how_to_sell_url:function(){
return this._how_to_url('donate')+window.location.search;
}
});
Glyde.ReferFriendNotification=Class.create(Glyde.AbstractNotification,{
is_active:function(){
return Glyde.user&&Glyde.user.referral_code;
},
on_render_complete:function(notification_node){
var share_container=notification_node.select('.share_container')[0];
this._share_widget=new Glyde.widgets.ShareButtonsSiteWidget(share_container,{small:true});
},
on_login:function(){
if(this.is_active()){
Glyde.notify.publish(Glyde.AbstractNotification.UPDATED_EVENT,{notification:this});
}
}
});
Glyde.DefaultBuyNotification.prototype.render=function(){
var _j=new Jaml();
_j.ns('<a');_j.s(' class="buy_learn_more"');_j.s(' href="'+(this._how_to_buy_url())+'"');_j.s('>');Jaml.x();
_j.ns('Buyers save up to 90%');
Jaml.x();_j.ns('</a>');
_j.ns('<span');_j.s(' class="text_bullet"');_j.s('>');Jaml.x();
_j.ns('&bull;');
Jaml.x();_j.ns('</span>');
_j.ns('<a');_j.s(' class="sell_learn_more"');_j.s(' href="'+(this._how_to_sell_url())+'"');_j.s('>');Jaml.x();
_j.ns('Sellers receive pre-stamped packaging');
Jaml.x();_j.ns('</a>');
return _j.v();
};
Glyde.DefaultSellNotification.prototype.render=function(){
var _j=new Jaml();
_j.ns('10 second listing');
_j.ns('<span');_j.s(' class="text_bullet"');_j.s('>');
_j.ns('&bull;');
_j.ns('</span>');
_j.ns('Glyde sends you pre-stamped mailers');
_j.ns('<span');_j.s(' class="text_bullet"');_j.s('>');
_j.ns('&bull;');
_j.ns('</span>');
_j.ns('<a');_j.s(' class="sell_learn_more"');_j.s(' href="'+(this._how_to_sell_url())+'"');_j.s('>');Jaml.x();
_j.ns('Learn more  ');
Jaml.x();_j.ns('</a>');
return _j.v();
};
Glyde.MarketPriceNotification.prototype.render=function(){
var _j=new Jaml();
var num_listings=Glyde.user.stats.num_listings_above_market_price();
var plural=num_listings>1;
var item_text='item'+(plural?'s':'');
var is_text=plural?'are':'is';
_j.ns([num_listings,' of your listings ',is_text,' above market price and may not sell.'].join(''));
_j.ns('<a');_j.s(' class="market_reprice_link"');_j.s(' href="'+('javascript: void(0)')+'"');_j.s(' title="'+('Click to reprice your listings')+'"');_j.s('>');Jaml.x();
_j.ns('Reprice your '+item_text);
Jaml.x();_j.ns('</a>');
return _j.v();
};
Glyde.ReferFriendNotification.prototype.render=function(){
var _j=new Jaml();
var has_referrals=Glyde.user.stats.num_referrals_completed()>0;
_j.ns('<div');_j.s(' class="'+('refer_container'+(has_referrals?' has_referrals':''))+'"');_j.s('>');
_j.ns('<div');_j.s(' class="refer_text"');_j.s('>');
if(has_referrals){
_j.ns('Refer more friends and get $'+Glyde.user.stats.per_user_referral_amount_cents()/100+' per. You are only '+Glyde.user.stats.num_referrals_until_bonus()+" away from a  $"+Glyde.user.stats.bonus_referral_amount_cents()/100+' bonus!');
}
else{
_j.ns('Refer 5 friends to Glyde and make $20. ');
_j.ns('<a');_j.s(' href="'+(Glyde.urls.how_to_refer_url)+'"');_j.s('>Learn more');
_j.ns('</a>');
}
_j.ns('</div>');
_j.ns('<div');_j.s(' class="share_container"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
Glyde.widgets.UpdatePricesWidget=Class.create(Glyde.widgets.Widget,{
DOM_CLASS:'update_prices_widget',
initialize:function($super,element){
$super(element);
element.update(this._render());
this._listings=[];
this._load_listings();
},
listings_count:function(){
return this._listings.length;
},
on_set_to_market:function(event){
var listing_id=this._get_listing_id_from_element(event.element().up('.listing'));
event.memo.widget.disable();
this.set_to_market(listing_id,function(success){if(this.listings_count()==0){this.$$first('.widget_body').addClassName('no_listings');}this.fire('widget:set_to_market',{listing_id:listing_id});}.bind(this));
},
set_to_market:function(listing_id,callback){
var market_price,listing;
if((listing=this._get_listing(listing_id))){
market_price=listing.market_price.price.cents;
}else{
callback(false);
return;
}
new Ajax.Request('/listings/'+listing_id+'.js',{
method:'put',
parameters:{'listing[cents]':market_price},
onComplete:function(resp,o){
var json=resp.responseJSON,element;
if(json.success){
element=this.$$first('.listings .listing_'+listing_id+' .above_market');
element.removeClassName('above_market');
element.update('$'+Glyde.Money.format_cents(market_price));
this._remove_listing(listing_id,callback);
}else{
callback(false);
}
}.bind(this)
});
},
set_all_to_market:function(callback,set_flash){
var params={},listing,seconds;
if(this.listings_count()==0){
callback();
return;
}
if(this.listings_count()>=30){
seconds=Math.ceil(Math.floor(this.listings_count()/10)/10)*10;
this.$$first('.sub_message_wrapper .sub_message .message').update('This may take up to '+seconds+' seconds.');
}
this.$$first('.widget_body').addClassName('setting_all_to_market');
for(var c=0;c<this._listings.length;c++){
listing=this._listings[c];
params['listings['+listing.id+'][cents]']=listing.market_price.price.cents;
}
if(set_flash){
params['set_flash']=true;
}
new Ajax.Request('/listings/update_multiple.js',{
method:'put',
parameters:params,
onComplete:function(resp,o){
var updated_count=this._listings.length;
this._listings=[];
this.$$first('.listings').update(this._render_listings());
this.$$first('.widget_body').removeClassName('setting_all_to_market');
callback(updated_count);
}.bind(this)
});
},
_load_listings:function(){
this.$$first('.widget_body').addClassName('loading');
new Ajax.Request('/listings/paging.js',{
method:'get',
parameters:{view:'collection',context:'update_prices',offset:0,limit:100000},
onComplete:function(resp,o){
var json=resp.responseJSON;
this._listings=json.listings;
this._on_loaded();
}.bind(this)
});
},
_on_loaded:function(){
this.$$first('.widget_body').removeClassName('loading');
if(this.listings_count()==0){
this.$$first('.widget_body').addClassName('no_listings');
}else{
this.$$first('.listings').update(this._render_listings());
var buttons=this.$$('.listings .listing .update_price_button');
for(var c=0;c<buttons.length;c++){
(new DialogButtonWidget(buttons[c],'Reprice to $'+Glyde.Money.format_cents(this._listings[c].market_price.price.cents),{color:'blue'})).observe('widget:activate',this.on_set_to_market.bindAsEventListener(this));
}
}
this.fire('widget:loaded');
},
_get_listing_index:function(listing_id){
for(var c=0;c<this._listings.length;c++){
if(this._listings[c].id==listing_id){
return c;
}
}
return null;
},
_get_listing:function(listing_id){
var listing_index;
if((listing_index=this._get_listing_index(listing_id))!=null){
return this._listings[listing_index];
}else{
return null;
}
},
_get_listing_id_from_element:function(element){
return element.className.split('_')[1];
},
_remove_listing:function(listing_id,callback){
var listing_index;
if((listing_index=this._get_listing_index(listing_id))!=null){
delete this._listings[listing_index];
this._listings=this._listings.compact();
}else{
callback(false);
return;
}
var element=this.$$first('.listings .listing_'+listing_id);
new Effect.Parallel([
new Effect.Fade(element,{sync:true}),
new Effect.SlideUp(element,{sync:true})
],{
duration:0.5,
delay:0.5,
afterFinish:function(){callback(true);}
});
}
});
Glyde.widgets.UpdatePricesWidget.prototype._render=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="widget_body"');_j.s('>');
_j.ns('<div');_j.s(' class="loading_wrapper"');_j.s('>');
_j.ns('<div');_j.s(' class="loading"');_j.s('>');
_j.ns('<div');_j.s(' class="throbber"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="message"');_j.s('>Loading...');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="setting_all_to_market_wrapper"');_j.s('>');
_j.ns('<div');_j.s(' class="setting_all_to_market"');_j.s('>');
_j.ns('<div');_j.s(' class="throbber"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="message"');_j.s('>Setting all to market...');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="no_listings_wrapper"');_j.s('>');
_j.ns('<div');_j.s(' class="no_listings"');_j.s('>');
_j.ns('<div');_j.s(' class="message"');_j.s('>You have no listings above market price.');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="sub_message_wrapper"');_j.s('>');
_j.ns('<div');_j.s(' class="sub_message"');_j.s('>');
_j.ns('<div');_j.s(' class="message"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="listings"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
Glyde.widgets.UpdatePricesWidget.prototype._render_listings=function(){
var _j=new Jaml();
var content=[];
for(var c=0;c<this._listings.length;c++){
content.push(this._render_listing(this._listings[c]));
}
_j.ns(content.join(''));
return _j.v();
};
Glyde.widgets.UpdatePricesWidget.prototype._render_listing=function(listing){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="listing '+('listing_'+listing.id)+'"');_j.s('>');
_j.ns('<div');_j.s(' class="image"');_j.s('>');
_j.ns('<img');_j.s(' src="'+('/images/'+listing.img_path_xs)+'"');_j.s(' />');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="description"');_j.s('>');
_j.ns('<div');_j.s(' class="title"');_j.s('>'+(listing.title.truncate_with_tooltip(30)));
_j.ns('</div>');
_j.ns('<div');_j.s(' class="creator"');_j.s('>'+(listing.creator.truncate_with_tooltip(30)));
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="pricing"');_j.s('>');
_j.ns('<div');_j.s(' class="market_price"');_j.s('>'+('Market Price: $'+Glyde.Money.format_cents(listing.market_price.price.cents)));
_j.ns('</div>');
_j.ns('<div');_j.s(' class="your_price"');_j.s('>');
_j.ns('Your Price:');
_j.ns('<span');_j.s(' class="above_market"');_j.s('>'+('$'+Glyde.Money.format_cents(listing.cents)));
_j.ns('</span>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="update_price_button"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
Glyde.SellCouponManager=Class.create({
initialize:function(on_new_message,new_coupon_id){
this._existing_coupons=[];
this._message=null;
this._coupon_id=null;
this._on_new_message=on_new_message;
this.create_or_fetch_offers(new_coupon_id);
Glyde.notify.subscribe(Glyde.Page.prototype.MESSAGE_NOTICE_AREA_EMPTY,
this._handle_notice_area_empty.bind(this));
},
create_or_fetch_offers:function(new_coupon_id){
if(new_coupon_id){
this.create_offer(new_coupon_id);
}else{
this._fetch_existing_offers();
}
Glyde.notify.subscribe(Glyde.Page.prototype.MESSAGE_NOTICE_AREA_EMPTY,
this._handle_notice_area_empty.bind(this));
},
create_offer:function(new_coupon_id){
this._coupon_id=new_coupon_id;
this._create_on_server(new_coupon_id);
},
coupon_id:function(){
return this._coupon_id;
},
message:function(){
return this._message;
},
_handle_notice_area_empty:function(msg_name,info){
var current_message=this.message();
if(!Glyde.is.empty_string(current_message)){
this._set_message(current_message,true);
}
},
_fetch_existing_offers:function(){
var options={
method:'get',
onComplete:function(resp,o){
var json=resp.responseJSON;
if(json&&json.success){
this._set_message_from_data(json.existing_sell_coupon_offers);
}
}.bind(this)
};
new Ajax.Request('/sell_coupon_offers',options);
},
_create_on_server:function(coupon_code){
if(Glyde.user&&Glyde.user.is_reg_complete){
var options={
method:'post',
parameters:{
code:coupon_code,
add_existing:true
},
onComplete:function(resp,o){
var json=resp.responseJSON;
if(json&&json.success){
this._set_message_from_data(json.existing_sell_coupon_offers,
json.sell_coupon_offer,json.existing);
}else{
}
}.bind(this)
};
new Ajax.Request('/sell_coupon_offers',options);
}else{
var options={
method:'get',
onComplete:function(resp,o){
var json=resp.responseJSON;
if(json&&json.success){
this._set_message(this._message_for_one_coupon(json.sell_coupon));
}else{
}
}.bind(this)
};
new Ajax.Request('/sell_coupons/'+coupon_code,options);
}
},
_set_message_from_data:function(sell_coupon_offers,new_sell_coupon_offer,
existing){
var message='';
var no_new_offer=!new_sell_coupon_offer;
var new_offer=(new_sell_coupon_offer&&!existing);
var existing_new_offer=(new_sell_coupon_offer&&existing);
var has_existing_offers=(sell_coupon_offers!=null&&
sell_coupon_offers.length>0);
var has_one_existing_offer=(has_existing_offers&&
sell_coupon_offers.length==1);
var has_multiple_existing_offers=(has_existing_offers&&
sell_coupon_offers.length>1);
if(new_offer){
message=this._message_for_one_coupon(new_sell_coupon_offer.sell_coupon,
has_multiple_existing_offers);
}else if((existing_new_offer&&has_one_existing_offer)||
no_new_offer&&has_one_existing_offer){
message=this._message_for_one_coupon(sell_coupon_offers[0].sell_coupon,
has_multiple_existing_offers);
}
if(has_multiple_existing_offers){
message=message+"You have multiple active offers. The best will be applied when an item sells.";
}
this._set_message(message);
},
_message_for_one_coupon:function(sell_coupon,has_multiple_existing_offers){
var message=null;
if(!has_multiple_existing_offers){
message=['Upon sale, the offer ','"',sell_coupon.description,
'"',' will apply.'].join('');
}else{
message=['The offer ','"',sell_coupon.description,
'"',' will be applied to your account. '].join('');
}
return message;
},
_set_message:function(message,force_notice){
if(force_notice||(message!=this._message)){
this._message=message;
this._on_new_message(this._message);
}
}
});
ConfirmPrimaryAddressDialog=Class.create(Glyde.Dialog,{
initialize:function($super,address){
$super();
this.on_open=this._create_buttons.bind(this);
this._states=["AK","AL","AR","AZ","CA","CO","CT","DC","DE","FL","GA","HI","IA","ID","IL","IN","KS","KY","LA","MA","MD","ME","MI","MN","MO","MS","MT","NC","ND","NE","NH","NJ","NM","NV","NY","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VA","VT","WA","WI","WV","WY","AA","AE","AP","AS","FM","GU","MH","MP","PR","PW","VI"];
this._address=address;
},
open:function($super){
$super(null,this._render_confirm());
},
close:function($super,confirmed){
if(confirmed){
Glyde.notify.publish('confirm_primary_address_dialog:address_confirmed');
}
InputErrorNotice.clear_all();
$super();
},
_create_buttons:function(){
var container=$(this._container_id);
new Glyde.ButtonWidget(container.select('.change_button')[0],'No, I need to change this address').observe('widget:activate',function(e){this._show_change_address_card();}.bindAsEventListener(this));
new Glyde.ButtonWidget(container.select('.continue_button')[0],'Yes, send mailers to this address',{color:'blue'}).observe('widget:activate',function(e){this.close(true);}.bindAsEventListener(this));
},
_populate_state_select:function(select_node_name){
var select_node=$(this._container_id).select('#locale_state')[0];
select_node.options[0]=new Option('--','');
this._states.each(function(state_name,index){
select_node.options[index+1]=new Option(state_name,state_name);
});
},
_on_submit:function(){
var options={
method:'post',
parameters:this._add_extra_params(Form.serialize($(this._container_id).select('#address_form')[0],true)),
onComplete:function(resp,o){
var json=resp.responseJSON;
if(json.success){
var address=json.address;
this.close(true);
}else{
this._show_errors(json.errors);
}
}.bind(this)
};
new Ajax.Request('/shipping_addresses',options);
},
_add_extra_params:function(parm_obj){
parm_obj['address[is_default]']='1';
parm_obj['user[is_admin]']=false;
parm_obj['user[is_glyde]']=true;
parm_obj['user[is_suspended]']=true;
return parm_obj;
},
_show_confirmation_card:function(){
var container=$(this._container_id);
this._compose_content(container,this._render_confirm());
this._create_buttons();
},
_show_change_address_card:function(){
var container=$(this._container_id);
this._compose_content(container,this._render_address());
this._populate_state_select();
container.select('#address_name')[0].focus();
new Glyde.ButtonWidget(container.select('.back_button')[0],'Back').observe('widget:activate',function(e){this._show_confirmation_card();}.bindAsEventListener(this));
new Glyde.ButtonWidget(container.select('.submit_button')[0],'Change my primary address',{color:'blue'}).observe('widget:activate',function(e){this._on_submit();}.bindAsEventListener(this));
},
_show_errors:function(errors){
InputErrorNotice.create_all_no_load(errors);
InputErrorNotice.focusFirstError();
}
});
Glyde.notify.subscribe('sell_box:confirm_primary_address',function(name,info){(new ConfirmPrimaryAddressDialog(info.address)).open();}.bind(this));
ConfirmPrimaryAddressDialog.prototype._render_confirm=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="confirm_primary_address_dialog_content"');_j.s('>');
_j.ns('<div');_j.s(' class="confirmation_card"');_j.s('>');
_j.ns('<h2');_j.s('>Confirm your primary selling address');
_j.ns('</h2>');
_j.ns('<div');_j.s(' class="description"');_j.s('>When this item sells, Glyde will send a pre-stamped mailer to:');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="address"');_j.s('>');
_j.ns('<div');_j.s(' class="name"');_j.s('>'+(this._address.name));
_j.ns('</div>');
_j.ns('<div');_j.s(' class="street_1"');_j.s('>'+(this._address.street_1));
_j.ns('</div>');
_j.ns('<div');_j.s(' class="street_2"');_j.s('>'+(this._address.street_2));
_j.ns('</div>');
_j.ns('<div');_j.s(' class="city_state_zip"');_j.s('>'+(this._address.city+', '+this._address.state+' '+this._address.zip));
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="description"');_j.s('>This address will be your primary selling (and buying) address - typically your home address. We will send mailers for all sold items to this address.');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="buttons"');_j.s('>');
_j.ns('<div');_j.s(' class="change_button"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="continue_button"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
ConfirmPrimaryAddressDialog.prototype._render_address=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="confirm_primary_address_dialog_content"');_j.s('>');
_j.ns('<div');_j.s(' class="address_change_card"');_j.s('>');
_j.ns('<h2');_j.s('>Primary selling address');
_j.ns('</h2>');
_j.ns('<form');_j.s(' id="address_form"');_j.s(' onsubmit="'+('return false;')+'"');_j.s('>');
_j.ns('<div');_j.s(' class="input_row"');_j.s('>');
_j.ns('<label');_j.s(' for="'+('address_name')+'"');_j.s('>');
_j.ns('Name');
_j.ns('</label>');
_j.ns('<input');_j.s(' id="address_name"');_j.s(' type="'+('text')+'"');_j.s(' name="'+('address[name]')+'"');_j.s('>');
_j.ns('</input>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="input_row"');_j.s('>');
_j.ns('<div');_j.s(' class="address_street_1 half_input_row"');_j.s('>');
_j.ns('<label');_j.s(' for="'+('address_street_1')+'"');_j.s('>');
_j.ns('Shipping Address, Line 1');
_j.ns('</label>');
_j.ns('<input');_j.s(' id="address_street_1"');_j.s(' type="'+('text')+'"');_j.s(' name="'+('address[street_1]')+'"');_j.s('>');
_j.ns('</input>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="address_street_2 half_input_row"');_j.s('>');
_j.ns('<label');_j.s(' for="'+('address_street_2')+'"');_j.s('>');
_j.ns('Shipping Address, Line 2');
_j.ns('</label>');
_j.ns('<input');_j.s(' id="address_street_2"');_j.s(' type="'+('text')+'"');_j.s(' name="'+('address[street_2]')+'"');_j.s('>');
_j.ns('</input>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="input_row"');_j.s('>');
_j.ns('<div');_j.s(' class="city_input half_input_row"');_j.s('>');
_j.ns('<label');_j.s(' for="'+('locale_city')+'"');_j.s('>');
_j.ns('City');
_j.ns('</label>');
_j.ns('<input');_j.s(' id="locale_city"');_j.s(' type="'+('text')+'"');_j.s(' name="'+('locale[city]')+'"');_j.s('>');
_j.ns('</input>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="state_selector"');_j.s('>');
_j.ns('<label');_j.s(' for="'+('locale_state')+'"');_j.s('>');
_j.ns('State');
_j.ns('</label>');
_j.ns('<select');_j.s(' id="locale_state"');_j.s(' name="'+('locale[state]')+'"');_j.s('>');
_j.ns('</select>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="zip_input"');_j.s('>');
_j.ns('<label');_j.s(' for="'+('locale_zip')+'"');_j.s('>');
_j.ns('Zip');
_j.ns('</label>');
_j.ns('<input');_j.s(' id="locale_zip"');_j.s(' type="'+('text')+'"');_j.s(' size="'+('5')+'"');_j.s(' maxlength="'+('5')+'"');_j.s(' name="'+('locale[zip]')+'"');_j.s('>');
_j.ns('</input>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</form>');
_j.ns('<div');_j.s(' class="buttons"');_j.s('>');
_j.ns('<div');_j.s(' class="back_button"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="submit_button"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
UpdatePricesDialog=Class.create(Glyde.Dialog,{
initialize:function($super){
$super();
this.on_open=this._on_open.bind(this);
},
open:function($super){
$super(null,this._render());
},
_on_open:function(){
var container=$(this._container_id);
this._update_prices_widget=new Glyde.widgets.UpdatePricesWidget(container.select('.listings_to_update')[0]);
this._continue_button=new Glyde.widgets.BigButtonWidget(container.select('.continue_button')[0],'Close');
this._all_button=new Glyde.widgets.BigButtonWidget(container.select('.all_button')[0],'Reprice All',{color:'blue'});
this._all_button.disable();
this._update_prices_widget.observe('widget:loaded',this.on_update_prices_widget_loaded.bindAsEventListener(this));
this._update_prices_widget.observe('widget:set_to_market',this.on_set_to_market.bindAsEventListener(this));
this._continue_button.observe('widget:activate',this.on_continue.bindAsEventListener(this));
this._all_button.observe('widget:activate',this.on_all.bindAsEventListener(this));
},
on_update_prices_widget_loaded:function(event){
if(this._update_prices_widget.listings_count()>0){
this._all_button.enable();
}
},
on_set_to_market:function(event){
if(this._update_prices_widget.listings_count()==0){
this._all_button.disable();
}
Glyde.user.stats.decrement_num_listings_above_market_price();
},
on_continue:function(event){
this.close();
},
on_all:function(event){
var container=$(this._container_id);
var num_listings=this._update_prices_widget.listings_count();
this._all_button.disable();
if(num_listings>3){
this._confirm_dialog=new GlydeConfirm('Are you sure you want to reprice '+num_listings+' items?',container.select('.all_button')[0],this._confirm_callback.bind(this),'Yes','No');
}else{
this._confirm_callback(true);
}
},
on_all_complete:function(updated_count){
Glyde.user.stats.set_num_listings_above_market_price(Glyde.user.stats.num_listings_above_market_price()-updated_count);
Glyde.page.flash_notice(updated_count+' '+(updated_count>1?'listings':'listing')+' repriced to market price.');
this.close();
},
_confirm_callback:function(response){
if(response){
this._update_prices_widget.set_all_to_market(this.on_all_complete.bind(this));
}else{
this._all_button.enable();
}
}
});
Glyde.notify.subscribe('market_price_notification:reprice',function(){(new UpdatePricesDialog()).open();}.bind(this));
UpdatePricesDialog.prototype._render=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="update_prices_dialog_content"');_j.s('>');
_j.ns('<div');_j.s(' class="heading"');_j.s('>Reprice your items');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="message"');_j.s('>Lowering your prices to match market price will help you sell.');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="listings_to_update"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="buttons"');_j.s('>');
_j.ns('<div');_j.s(' class="continue_button"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="all_button"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
var NewListingPage=Class.create({
NEW_LISTING_COOKIE_NAME:'glyde_new_listing_attrs',
PRODUCT_VERTICALS:['books','games','music','videos'],
initialize:function(){
this.elem_id='new_listing_form';
this.live_step=null;
this.options={
product_id:null,
vertical:null,
container_id:'view_header'
};
this.product_id=this.options.product_id;
this.vertical=this.options.vertical;
document.observe('list_box:clicked_closed',function(e){this.listing_box_closed();}.bind(this));
if(!Glyde.user){
Glyde.notify.subscribe('login:succeeded',this._on_login.bind(this));
}
},
onload:function(params,is_back){
this._search_widget=new Glyde.widgets.Search($('search'),{selected_domains:this.PRODUCT_VERTICALS,is_buy_side:false});
this._search_widget.observe('widget:select',this.on_search_select.bindAsEventListener(this));
this._search_widget.set_focus();
this._create_collection_scroll();
var on_new_message=function(message){
Glyde.page.set_notice(message);
};
this._sell_coupon_manager=new Glyde.SellCouponManager(on_new_message,
params.sc_id);
if(params.charity_id){
this._charity_override_id=params.charity_id;
this._charity_override_name=g_charity_name;
this.listing_details=new Glyde.widgets.ListingDetailsWidget($('listing_details_widget'),null,null,null,null,null,null,null,null,null,true);
}else{
this.listing_details=new Glyde.widgets.ListingDetailsWidget($('listing_details_widget'));
}
if(is_back){this.restore_from_state(params);}
this._set_search_box_position();
if(params.charity_id){
this._notification_widget=new Glyde.widgets.DonateNotificationWidget('notification_widget');
}else{
this._notification_widget=new Glyde.widgets.SellNotificationWidget('notification_widget');
}
},
_handle_scan_success:function(name,message){
console.log('scanner: '+message.ean);
new Ajax.Request('/glus',{
method:'get',
parameters:{ean:message.ean},
onSuccess:function(response){
var glus=response.responseJSON.glus;
if(glus.length==1){
console.log('scanner: glu found: '+glus[0].title);
this.on_submit_glu(glus[0].id);
}else if(glus.length==0){
console.log('scanner: no glus found');
}else if(glus.length>1){
console.log('scanner: '+glus.length+' glus found');
}
}.bind(this)
});
},
_set_search_box_position:function(){
if(Glyde.page.is_facebook()){
$('search_content').style.top='0';
}else if(document.viewport.getHeight()<690){
$('search_content').style.top='10px';
}
},
current_state:function(params){
if(this._current_req){
params.call=this._current_req.options._call;
params.p=encodeURIComponent(Hash.toQueryString(this._current_req.options._params));
return[params.call,params.p].compact().join('/');
}else{
return['reset'].compact().join('/');
}
return params;
},
parse_history_params:function(state_str){
var params={};
var arr=state_str.split('/');
if(arr.length>1){
params.call=arr[0];
params.p=arr[1];
}
return params;
},
on_in_page_back:function(params){
this.restore_from_state(params);
},
restore_from_state:function(params){
var p=decodeURIComponent(params.p).toQueryParams();
switch(params.call){
case'submit_glu':
this.on_submit_glu(p.glu_id,null,true);
break;
case'new_title':
this._search_widget.deactivate();
this._on_new_title(p.vertical,null,p.search_key,true);
break;
default:
if(this.lineup){this.lineup.hide();}
this.cancel_search();
this._search_widget.activate();
this._search_widget.set_focus();
}
},
on_submit_glu:function(glu_id,glu,from_back){
if(this._current_lineup_submit_key==('glu_'+glu_id)){
return;
}
var on_complete=function(resp,o){
Loading.hide();
if(this.lineup_dialog)this.lineup_dialog.close(true);
this._current_lineup_submit_key=null;
var json=resp.responseJSON;
if(!json.success&&json.redirect_to){
Glyde.page.handle_server_errors(json);
}else{
this._show_sell_or_lineup(json);
if(!from_back){
Glyde.page.end_backable_action();
}
}
}.bind(this);
var options={
_call:'submit_glu',
_params:{glu_id:glu_id},
method:'get',
evalScripts:true,
parameters:{include_glus_p:true},
onComplete:on_complete
};
Loading.show();
this._current_lineup_submit_key='glu_'+glu_id;
this._current_req=new Ajax.Request('/glus/'+glu_id,options);
if(!from_back){
Glyde.page.start_backable_action();
}
},
is_for_sale:function(){
var e=$('listing_is_for_sale');
return e?e.checked:false;
},
cancel_search:function(){
var action=function(){
this.reset_glu();
this.hide_glu();
this.hide_lineup();
if(this.lineup_dialog){
this.lineup_dialog.close();
}
this._current_req=null;
};
Glyde.page.run_client_backable_action(action.bind(this));
},
display_lineup:function(json,vertical,search_key){
this._search_widget.remove_focus();
var opts={
on_close:function(){
this.cancel_search();
this._search_widget.reset();
}.bind(this),
search_key:search_key,
vertical:vertical
};
if(Glyde.page.is_facebook()){
opts.lineup_size=3;
}
this.lineup_dialog=new LineupDialog('page_content',
this.on_submit_glu.bind(this),
opts,false,true);
if(this.product_id){
$('glu').style.height='5px';
}
this.hide_glu();
$('page_content').addClassName('lineup_mode');
this.lineup_dialog.open();
},
glu_selected:function(){
this._search_widget.enable();
},
reset_glu:function(){
$('selected_glu').update('&nbsp;').show();
this.listing_details.reset();
this._enable_list_for_sale_button();
},
listing_box_closed:function(){
this.cancel_search();
this.reset_suggestions();
},
hide_glu:function(){
$('page_content').removeClassName('list_product_mode');
},
hide_lineup:function(){
$('page_content').removeClassName('lineup_mode');
},
on_glu_selected:function(glu,year,default_charity_percentage,default_charity_id,default_charity_name){
this.reset_glu();
if(this.lineup){this.lineup.hide();}
this.display_selected(this._render_glu(glu));
var cookie_data=this._new_listing_data_from_cookie();
var enable,cents,condition_id=null;
var charity_percentage=default_charity_percentage;
var charity_id=default_charity_id;
var charity_name=default_charity_name;
if(cookie_data){
if(parseInt(cookie_data.glu_id)==glu.id){
cents=cookie_data.price*100;
condition_id=cookie_data.condition_id;
charity_percentage=cookie_data.charity_percentage;
charity_id=cookie_data.charity_id;
charity_name=cookie_data.charity_name;
enable=true;
}
}
if(this._charity_override_id){
charity_percentage=100;
enable=true;
charity_id=this._charity_override_id;
charity_name=this._charity_override_name;
}
this.listing_details.reset(glu,null,cents,condition_id,
charity_percentage,charity_id,charity_name,enable);
$('page_content').addClassName('list_product_mode');
if(Glyde.Browser.IE){this._search_widget.remove_focus();}
return this;
},
_save_new_listing_data_to_cookie:function(){
var obj=this.listing_details.serialize();
var cook_hash={
'charity_id':obj['listing[charity_id]'],
'charity_name':obj['listing[charity_name]'],
'charity_percentage':obj['listing[charity_percentage]'],
'price':obj['listing[price]'],
'condition_id':obj['sku[condition_id]'],
'glu_id':obj['sku[glu_id]']
};
var cook_val=encodeURIComponent($H(cook_hash).toQueryString());
Glyde.cookie.set(this.NEW_LISTING_COOKIE_NAME,cook_val);
},
_new_listing_data_from_cookie:function(){
var cook_str=Glyde.cookie.get(this.NEW_LISTING_COOKIE_NAME);
var cook=null;
if(cook_str){
cook={};
cook=decodeURIComponent(cook_str).parseQuery();
cook.charity_id=isNaN(parseInt(cook.charity_id))?null:parseInt(cook.charity_id);
cook.charity_name=cook.charity_name;
cook.charity_percentage=isNaN(parseInt(cook.charity_percentage))?null:parseInt(cook.charity_percentage);
cook.price=parseFloat(cook.price);
cook.condition_id=parseInt(cook.condition_id);
Glyde.cookie.remove(this.NEW_LISTING_COOKIE_NAME);
}
return cook;
},
display_selected:function(html){
if(this.product_id){
$('cancel_selected').hide();
}
$('glu').style.height='';
$('selected_glu').update(html).show();
return this;
},
reset:function(response_text){
this._display_status(response_text);this.hide_glu();
this.hide_lineup();
this.reset_glu();
this._search_widget.reset();
},
reset_suggestions:function(){
this._search_widget.reset();
},
_enable_list_for_sale_button:function(){
var list_for_sale_button=$('list_for_sale_button');
if(list_for_sale_button){Glyde.dom.enable_link(list_for_sale_button,'list_for_sale_button_disabled');}
var add_to_catalog_button=$('add_to_catalog_button');
if(add_to_catalog_button){Glyde.dom.enable_link(add_to_catalog_button,'add_to_catalog_button_disabled');}
},
_disable_list_for_sale_button:function(is_for_sale){
var node_name=(is_for_sale)?'list_for_sale_button':'add_to_catalog_button';
var target_node=$(node_name);
Glyde.dom.disable_link(target_node,node_name+'_disabled');
},
_on_login:function(msg_name,info){
var params=window.location.search.parseQuery();
this._sell_coupon_manager.create_or_fetch_offers(params.sc_id);
this._create_collection_scroll();
},
_create_collection_scroll:function(){
if(Glyde.user&&!this.collection_scroll){
this.collection_scroll=new CollectionScrollWidget($('collection_scroll'));
}
},
_redirect_to_sell_checkout:function(){
var ld=this.listing_details;
var return_to=Glyde.page.is_facebook()?Glyde.page.query_str_params().checkout_next:'/sell';
var extra_params={
listing_id:null,
cents:ld.cents(),
condition:ld.condition_id(),
charity_percentage:ld.charity_percentage(),
charity_id:ld.charity_id(),
sc_id:this._sell_coupon_manager.coupon_id(),
return_to:return_to
};
Glyde.page.header.sell_checkout(ld.glu(),extra_params);
},
create:function(is_for_sale){
if(Glyde.user==null||!Glyde.user.is_reg_complete){
this._redirect_to_sell_checkout();
return;
}
if(is_for_sale&&g_check_primary){
Glyde.notify.subscribe('confirm_primary_address_dialog:address_confirmed',function(){g_check_primary=false;this.create(is_for_sale);}.bind(this));
Glyde.notify.publish('sell_box:confirm_primary_address',{address:g_primary_address});
return;
}
var donation_selector=this.listing_details.donation_selector();
if(donation_selector&&donation_selector.is_enabled()&&!donation_selector.is_charity_selected()){
donation_selector.show_no_charity_error();
return;
}
this._disable_list_for_sale_button(is_for_sale);
var options={
_method:'post',
onComplete:this._on_create_complete.bind(this)
};
options.parameters=Form.serialize($('new_listing_form'),true);
$H(options.parameters).keys().each(function(key){
if(/^sku\[condition_id\]_\d$/.test(key)){delete options.parameters[key];}
});
options.parameters['listing[is_for_sale]']=(is_for_sale?1:0);
Object.extend(options.parameters,this.listing_details.serialize());
Glyde.page.start_backable_action();
this._current_req=null;
ConversionTracker.get_instance().track_item_for_sale(this.listing_details.cents());
new Ajax.Request('/listings',options);
},
_on_create_complete:function(request){
var json=Ajax.evalJSON(request.responseText);
if(json.success){
Glyde.page.end_backable_action();
this._on_create_success(json,request.request.options.parameters['listing[is_for_sale]']);
}else{
Glyde.page.handle_server_errors(json);
}
},
_on_create_success:function(json,is_sellable){
if(is_sellable){
var func=function(){
this.collection_scroll.add_new_item(json.listing);
this.reset(json.status);
};
this._animate_listing_to_collection_scroll(json.listing,func.bind(this));
if(this.listing_details.cents()>this.listing_details.market_price_cents()){
Glyde.user.stats.increment_num_listings_above_market_price();
}
}else{
this.reset(json.status);
}
},
_animate_listing_to_collection_scroll:function(listing,on_done){
new NewListingInternalMove(listing,this.collection_scroll,on_done);
},
_on_new_title:function(vertical,title,search_key,from_back){
var elem=$('status_text');
if(elem){elem.hide();}
var options={
_call:'new_title',
_params:{'vertical':vertical,
search_key:search_key},
evalScripts:true,
method:'get',
parameters:'res_id='+search_key+'&vertical='+vertical+'&include_glus_p=false',
onComplete:function(transport){
Loading.hide();
var json=Ajax.evalJSON(transport.responseText);
if(json.success){
this._show_sell_or_lineup(json,vertical,search_key);
}else{
Glyde.page.handle_server_errors(json);
}
if(!from_back){
Glyde.page.end_backable_action();
}
}.bind(this)
};
Glyde.page.start_backable_action();
Loading.show();
this._current_req=new Ajax.Request('/glus/listing',options);
},
on_search_select:function(event){
this._on_new_title(event.memo.domain,event.memo.title,event.memo.res_id);
},
_show_sell_or_lineup:function(json,vertical,search_key){
if(json.success){
this._cached_html=json.html;if(json.total==1){this.on_glu_selected(json.glus[0],json.year,json.default_charity_percentage,json.default_charity_id,json.default_charity_name);
}else{
this.display_lineup(json,vertical,search_key);
}
}else{
this._display_status('No matching product.');
}
},
_display_status:function(status_text){
if(status_text){
Glyde.page.flash_notice(status_text,10000);
}
}
});
Object.extend(NewListingPage,{
GROUP_STEP:1,
LINEUP_STEP:2,
get_instance:function(options){
return(NewListingPage._instance?NewListingPage._instance:(NewListingPage._instance=new NewListingPage()));
}
});
Glyde.page.register_page(NewListingPage.get_instance());
var NewListingInternalMove=Class.create({
initialize:function(listing,scroll_widget,on_done){
var image_wrapper_node=$('image_wrapper');
var img=image_wrapper_node.select('img')[0];
var pos=img.cumulativeOffset();
var dims=Glyde.image.cover_dimensions_for_max_w_h(listing,84,117);
var vp_pos=scroll_widget.get_viewport().cumulativeOffset();
var x_slop=(Glyde.Browser.SAFARI)?1:0;
var x=vp_pos[0]+Math.floor(65-(dims.width/2))+x_slop;
if(Glyde.Browser.APPLE_WEB_KIT||Glyde.Browser.IE){--x;}
var y_slop=1;
var y=(vp_pos[1]+(115-dims.height))+y_slop;
if(Glyde.Browser.IE6){--y;}
var placeholder_node=new Element('div');
var img_dimensions=img.getDimensions();
placeholder_node.setStyle({width:img_dimensions.width+"px",height:img_dimensions.height+"px"});
image_wrapper_node.insert({top:placeholder_node});
document.body.appendChild(img);
img.setStyle({position:'absolute',display:'block',left:pos[0]+"px",top:pos[1]+"px"});
image_wrapper_node.style.backgroundImage='none';
var local_on_done=function(){
(on_done||Glyde.empty_function)();
func=function(){
document.body.removeChild(img);
};
setTimeout(func,1000);
};
var dur=800;
new fx.ImgSize(img,{duration:dur,onComplete:local_on_done}).to(dims.width,dims.height);
new fx.Move(img,{duration:dur}).to(x,y);
}
});
NewListingPage.prototype._render_glu=function(glu){
var _j=new Jaml();
var cover_width=147;
var cover_height=200;
var cover_image_url=Glyde.image.fully_qualified_cover_url_for_max_w_h(glu,cover_width,cover_height);
var background_image_url=Glyde.image.fully_qualified_cover_url_for_max_w_h(glu,cover_width,cover_height,'e','png');
var background_image=(Glyde.Browser.IE6?"":"background-image : url("+background_image_url+")");
_j.ns('<div');_j.s(' class="glu"');_j.s('>');
_j.ns('<div');_j.s(' class="image_wrapper"');_j.s(' id="image_wrapper"');_j.s(' style="'+(background_image)+'"');_j.s('>');
_j.ns('<img');_j.s(' class="sell_cover"');_j.s(' src="'+(cover_image_url)+'"');_j.s(' />');
_j.ns('<div');_j.s(' class="info"');_j.s('>');
var year_str=glu.orig_release_year?(' ('+glu.orig_release_year+')'):'';
var title=(glu.title+year_str);
var empty_class=Glyde.is.empty_string(glu.title)?'extra_info_empty':'';
_j.ns('<div');_j.s(' class="ex_title extra_info sfont_smallest '+(empty_class)+'"');_j.s(' title="'+(title)+'"');_j.s('>');
_j.ns(title.truncate_with_delimiters(35));
_j.ns('</div>');
if(glu.medium_name){
_j.ns('<div');_j.s(' class="extra_info sfont_smallest"');_j.s(' title="'+(glu.medium_name)+'"');_j.s('>');
_j.ns(glu.medium_name.truncate_with_delimiters(40,' - ')||'&nbsp;');
_j.ns('</div>');
}
_j.ns('<div');_j.s(' class="sfont_smallest"');_j.s('>');
_j.ns(glu.product_codes_html);
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
