var base64_keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function Base64(encdec,textstr){
if(encdec>0){
return base64_encode(textstr);
}
return base64_decode(textstr);
}
function base64_encode(input){
var output="";
var chr1,chr2,chr3;
var enc1,enc2,enc3,enc4;
var i=0;
do{
chr1=input.charCodeAt(i++);
chr2=input.charCodeAt(i++);
chr3=input.charCodeAt(i++);
enc1=chr1>>2;
enc2=((chr1&3)<<4)|(chr2>>4);
enc3=((chr2&15)<<2)|(chr3>>6);
enc4=chr3&63;
if(isNaN(chr2)){
enc3=enc4=64;
}else if(isNaN(chr3)){
enc4=64;
}
output=output+base64_keyStr.charAt(enc1)+base64_keyStr.charAt(enc2)+
base64_keyStr.charAt(enc3)+base64_keyStr.charAt(enc4);
}while(i<input.length);
return output;
}
function base64_decode(input){
var output="";
var chr1,chr2,chr3;
var enc1,enc2,enc3,enc4;
var i=0;
input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");
while(i<input.length){
enc1=base64_keyStr.indexOf(input.charAt(i++));
enc2=base64_keyStr.indexOf(input.charAt(i++));
enc3=base64_keyStr.indexOf(input.charAt(i++));
enc4=base64_keyStr.indexOf(input.charAt(i++));
chr1=(enc1<<2)|(enc2>>4);
chr2=((enc2&15)<<4)|(enc3>>2);
chr3=((enc3&3)<<6)|enc4;
output=output+String.fromCharCode(chr1);
if(enc3!=64){
output=output+String.fromCharCode(chr2);
}
if(enc4!=64){
output=output+String.fromCharCode(chr3);
}
}
return output;
}
document.Base64_Loaded=1;
var PeekoRequest=Class.create();
PeekoRequest.handler_names=['onComplete','onFailure','onSuccess','on401'];
PeekoRequest.prototype={
initialize:function(url,caller_options){
this.url=url;
this._set_aside_handlers(caller_options);
this._set_up_options(caller_options);
this.run();
},
run:function(){
Loading.show();
new Ajax.Request(this.url,this.options);
},
_set_aside_handlers:function(caller_options){
this.orig_handler_funcs={};
PeekoRequest.handler_names.each(function(func_name){
this.orig_handler_funcs[func_name]=caller_options[func_name];
if(caller_options[func_name]){delete caller_options[func_name];}
}.bind(this));
},
_set_up_options:function(caller_options){
var options={
asynchronous:true,
evalScripts:true,
method:'get'
};
this.options=Object.extend(options,caller_options||{});
this.options.onComplete=this._on_complete.bind(this);
},
_on_complete:function(resp,o){
var status=resp.status;
var success=(200<=status&&status<300);
if(status==401){
this._on_401(resp,o);
}else{
if(status==200){
var data=resp.responseJSON
if(data&&!data.success&&!data.errors){
return Glyde.page.handle_server_errors(data);
}
}
this._maybe_update(resp.responseText,success);
}
this._orig_callback(status,success)(resp,o);
(this.orig_handler_funcs.onComplete||Prototype.emptyFunction)(resp,o);
Loading.hide();
},
_orig_callback:function(status,success){
return(this.options['on'+status]||this.orig_handler_funcs['on'+status]||
this.orig_handler_funcs[(success?'onSuccess':'onFailure')]||
Prototype.emptyFunction);
},
_on_401:function(transport,o){
var options={
on_success:function(data){
this.run();
}.bind(this)
}
Glyde.page.header.login(options,Glyde.page_id);
},
_maybe_update:function(html,is_success){
if(this.options.update){
var id=this._get_container_id(is_success);
var e=$(id);
if(e){e.update(html);}
}
},
_get_container_id:function(is_success){
var success_container=this.options.update.success||this.options.update;
return(is_success?
success_container:
(this.options.update.failure||(success_container?null:this.options.update))
);
}
};
GlydeCheckbox=Class.create({
initialize:function(el,toggle){
this._elem=$(el);
if(!this._elem)return;
if(this.is_disabled()){
this._remove_onclick();
}
if(toggle){
this.toggle();
}
},
is_checked:function(){
return(this._elem.className.indexOf('checked')!=-1);
},
is_disabled:function(){
return(this._elem.className.indexOf('disabled')!=-1);
},
checked:function(bool){
if(bool){
if(!this.is_checked()){
this._elem.className+=' checked';
}
}else{
this._elem.className=this._elem.className.replace(' checked','');
}
},
toggle:function(){
if(!this.is_disabled()){
this.checked(!this.is_checked());
}
},
dom_element:function(){
return this._elem;
},
id:function(){
return this._elem.id;
},
_restore_onclick:function(){
if(this._elem._onclick){
this._elem.onclick=this._elem._onclick;
this._elem._onclick=null;
}
},
_remove_onclick:function(){
if(!this._elem._onclick){
this._elem._onclick=this._elem.onclick;
this._elem.onclick=Glyde.empty_function;
}
}
});
String.prototype.parseColor=function(){
var color='#';
if(this.slice(0,4)=='rgb('){
var cols=this.slice(4,this.length-1).split(',');
var i=0;do{color+=parseInt(cols[i]).toColorPart()}while(++i<3);
}else{
if(this.slice(0,1)=='#'){
if(this.length==4)for(var i=1;i<4;i++)color+=(this.charAt(i)+this.charAt(i)).toLowerCase();
if(this.length==7)color=this.toLowerCase();
}
}
return(color.length==7?color:(arguments[0]||this));
};
Element.collectTextNodes=function(element){
return $A($(element).childNodes).collect(function(node){
return(node.nodeType==3?node.nodeValue:
(node.hasChildNodes()?Element.collectTextNodes(node):''));
}).flatten().join('');
};
Element.collectTextNodesIgnoreClass=function(element,className){
return $A($(element).childNodes).collect(function(node){
return(node.nodeType==3?node.nodeValue:
((node.hasChildNodes()&&!Element.hasClassName(node,className))?
Element.collectTextNodesIgnoreClass(node,className):''));
}).flatten().join('');
};
Element.setContentZoom=function(element,percent){
element=$(element);
element.setStyle({fontSize:(percent/100)+'em'});
if(Prototype.Browser.WebKit)window.scrollBy(0,0);
return element;
};
Element.getInlineOpacity=function(element){
return $(element).style.opacity||'';
};
Element.forceRerendering=function(element){
try{
element=$(element);
var n=document.createTextNode(' ');
element.appendChild(n);
element.removeChild(n);
}catch(e){}
};
var Effect={
_elementDoesNotExistError:{
name:'ElementDoesNotExistError',
message:'The specified DOM element does not exist, but is required for this effect to operate'
},
Transitions:{
linear:Prototype.K,
sinoidal:function(pos){
return(-Math.cos(pos*Math.PI)/2)+.5;
},
reverse:function(pos){
return 1-pos;
},
flicker:function(pos){
var pos=((-Math.cos(pos*Math.PI)/4)+.75)+Math.random()/4;
return pos>1?1:pos;
},
wobble:function(pos){
return(-Math.cos(pos*Math.PI*(9*pos))/2)+.5;
},
pulse:function(pos,pulses){
return(-Math.cos((pos*((pulses||5)-.5)*2)*Math.PI)/2)+.5;
},
spring:function(pos){
return 1-(Math.cos(pos*4.5*Math.PI)*Math.exp(-pos*6));
},
none:function(pos){
return 0;
},
full:function(pos){
return 1;
}
},
DefaultOptions:{
duration:1.0,fps:100,sync:false,from:0.0,
to:1.0,
delay:0.0,
queue:'parallel'
},
tagifyText:function(element){
var tagifyStyle='position:relative';
if(Prototype.Browser.IE)tagifyStyle+=';zoom:1';
element=$(element);
$A(element.childNodes).each(function(child){
if(child.nodeType==3){
child.nodeValue.toArray().each(function(character){
element.insertBefore(
new Element('span',{style:tagifyStyle}).update(
character==' '?String.fromCharCode(160):character),
child);
});
Element.remove(child);
}
});
},
multiple:function(element,effect){
var elements;
if(((typeof element=='object')||
Object.isFunction(element))&&
(element.length))
elements=element;
else
elements=$(element).childNodes;
var options=Object.extend({
speed:0.1,
delay:0.0
},arguments[2]||{});
var masterDelay=options.delay;
$A(elements).each(function(element,index){
new effect(element,Object.extend(options,{delay:index*options.speed+masterDelay}));
});
},
PAIRS:{
'slide':['SlideDown','SlideUp'],
'blind':['BlindDown','BlindUp'],
'appear':['Appear','Fade']
},
toggle:function(element,effect){
element=$(element);
effect=(effect||'appear').toLowerCase();
var options=Object.extend({
queue:{position:'end',scope:(element.id||'global'),limit:1}
},arguments[2]||{});
Effect[element.visible()?
Effect.PAIRS[effect][1]:Effect.PAIRS[effect][0]](element,options);
}
};
Effect.DefaultOptions.transition=Effect.Transitions.sinoidal;
Effect.ScopedQueue=Class.create(Enumerable,{
initialize:function(){
this.effects=[];
this.interval=null;
},
_each:function(iterator){
this.effects._each(iterator);
},
add:function(effect){
var timestamp=new Date().getTime();
var position=Object.isString(effect.options.queue)?
effect.options.queue:effect.options.queue.position;
switch(position){
case'front':
this.effects.findAll(function(e){return e.state=='idle'}).each(function(e){
e.startOn+=effect.finishOn;
e.finishOn+=effect.finishOn;
});
break;
case'with-last':
timestamp=this.effects.pluck('startOn').max()||timestamp;
break;
case'end':
timestamp=this.effects.pluck('finishOn').max()||timestamp;
break;
}
effect.startOn+=timestamp;
effect.finishOn+=timestamp;
if(!effect.options.queue.limit||(this.effects.length<effect.options.queue.limit))
this.effects.push(effect);
if(!this.interval)
this.interval=setInterval(this.loop.bind(this),15);
},
remove:function(effect){
this.effects=this.effects.reject(function(e){return e==effect});
if(this.effects.length==0){
clearInterval(this.interval);
this.interval=null;
}
},
loop:function(){
var timePos=new Date().getTime();
for(var i=0,len=this.effects.length;i<len;i++)
this.effects[i]&&this.effects[i].loop(timePos);
}
});
Effect.Queues={
instances:$H(),
get:function(queueName){
if(!Object.isString(queueName))return queueName;
return this.instances.get(queueName)||
this.instances.set(queueName,new Effect.ScopedQueue());
}
};
Effect.Queue=Effect.Queues.get('global');
Effect.Base=Class.create({
position:null,
start:function(options){
function codeForEvent(options,eventName){
return(
(options[eventName+'Internal']?'this.options.'+eventName+'Internal(this);':'')+
(options[eventName]?'this.options.'+eventName+'(this);':'')
);
}
if(options&&options.transition===false)options.transition=Effect.Transitions.linear;
this.options=Object.extend(Object.extend({},Effect.DefaultOptions),options||{});
this.currentFrame=0;
this.state='idle';
this.startOn=this.options.delay*1000;
this.finishOn=this.startOn+(this.options.duration*1000);
this.fromToDelta=this.options.to-this.options.from;
this.totalTime=this.finishOn-this.startOn;
this.totalFrames=this.options.fps*this.options.duration;
this.render=(function(){
function dispatch(effect,eventName){
if(effect.options[eventName+'Internal'])
effect.options[eventName+'Internal'](effect);
if(effect.options[eventName])
effect.options[eventName](effect);
}
return function(pos){
if(this.state==="idle"){
this.state="running";
dispatch(this,'beforeSetup');
if(this.setup)this.setup();
dispatch(this,'afterSetup');
}
if(this.state==="running"){
pos=(this.options.transition(pos)*this.fromToDelta)+this.options.from;
this.position=pos;
dispatch(this,'beforeUpdate');
if(this.update)this.update(pos);
dispatch(this,'afterUpdate');
}
};
})();
this.event('beforeStart');
if(!this.options.sync)
Effect.Queues.get(Object.isString(this.options.queue)?
'global':this.options.queue.scope).add(this);
},
loop:function(timePos){
if(timePos>=this.startOn){
if(timePos>=this.finishOn){
this.render(1.0);
this.cancel();
this.event('beforeFinish');
if(this.finish)this.finish();
this.event('afterFinish');
return;
}
var pos=(timePos-this.startOn)/this.totalTime,
frame=(pos*this.totalFrames).round();
if(frame>this.currentFrame){
this.render(pos);
this.currentFrame=frame;
}
}
},
cancel:function(){
if(!this.options.sync)
Effect.Queues.get(Object.isString(this.options.queue)?
'global':this.options.queue.scope).remove(this);
this.state='finished';
},
event:function(eventName){
if(this.options[eventName+'Internal'])this.options[eventName+'Internal'](this);
if(this.options[eventName])this.options[eventName](this);
},
inspect:function(){
var data=$H();
for(property in this)
if(!Object.isFunction(this[property]))data.set(property,this[property]);
return'#<Effect:'+data.inspect()+',options:'+$H(this.options).inspect()+'>';
}
});
Effect.Parallel=Class.create(Effect.Base,{
initialize:function(effects){
this.effects=effects||[];
this.start(arguments[1]);
},
update:function(position){
this.effects.invoke('render',position);
},
finish:function(position){
this.effects.each(function(effect){
effect.render(1.0);
effect.cancel();
effect.event('beforeFinish');
if(effect.finish)effect.finish(position);
effect.event('afterFinish');
});
}
});
Effect.Tween=Class.create(Effect.Base,{
initialize:function(object,from,to){
object=Object.isString(object)?$(object):object;
var args=$A(arguments),method=args.last(),
options=args.length==5?args[3]:null;
this.method=Object.isFunction(method)?method.bind(object):
Object.isFunction(object[method])?object[method].bind(object):
function(value){object[method]=value};
this.start(Object.extend({from:from,to:to},options||{}));
},
update:function(position){
this.method(position);
}
});
Effect.Event=Class.create(Effect.Base,{
initialize:function(){
this.start(Object.extend({duration:0},arguments[0]||{}));
},
update:Prototype.emptyFunction
});
Effect.Opacity=Class.create(Effect.Base,{
initialize:function(element){
this.element=$(element);
if(!this.element)throw(Effect._elementDoesNotExistError);
if(Prototype.Browser.IE&&(!this.element.currentStyle.hasLayout))
this.element.setStyle({zoom:1});
var options=Object.extend({
from:this.element.getOpacity()||0.0,
to:1.0
},arguments[1]||{});
this.start(options);
},
update:function(position){
this.element.setOpacity(position);
}
});
Effect.Move=Class.create(Effect.Base,{
initialize:function(element){
this.element=$(element);
if(!this.element)throw(Effect._elementDoesNotExistError);
var options=Object.extend({
x:0,
y:0,
mode:'relative'
},arguments[1]||{});
this.start(options);
},
setup:function(){
this.element.makePositioned();
this.originalLeft=parseFloat(this.element.getStyle('left')||'0');
this.originalTop=parseFloat(this.element.getStyle('top')||'0');
if(this.options.mode=='absolute'){
this.options.x=this.options.x-this.originalLeft;
this.options.y=this.options.y-this.originalTop;
}
},
update:function(position){
this.element.setStyle({
left:(this.options.x*position+this.originalLeft).round()+'px',
top:(this.options.y*position+this.originalTop).round()+'px'
});
}
});
Effect.MoveBy=function(element,toTop,toLeft){
return new Effect.Move(element,
Object.extend({x:toLeft,y:toTop},arguments[3]||{}));
};
Effect.Scale=Class.create(Effect.Base,{
initialize:function(element,percent){
this.element=$(element);
if(!this.element)throw(Effect._elementDoesNotExistError);
var options=Object.extend({
scaleX:true,
scaleY:true,
scaleContent:true,
scaleFromCenter:false,
scaleMode:'box',scaleFrom:100.0,
scaleTo:percent
},arguments[2]||{});
this.start(options);
},
setup:function(){
this.restoreAfterFinish=this.options.restoreAfterFinish||false;
this.elementPositioning=this.element.getStyle('position');
this.originalStyle={};
['top','left','width','height','fontSize'].each(function(k){
this.originalStyle[k]=this.element.style[k];
}.bind(this));
this.originalTop=this.element.offsetTop;
this.originalLeft=this.element.offsetLeft;
var fontSize=this.element.getStyle('font-size')||'100%';
['em','px','%','pt'].each(function(fontSizeType){
if(fontSize.indexOf(fontSizeType)>0){
this.fontSize=parseFloat(fontSize);
this.fontSizeType=fontSizeType;
}
}.bind(this));
this.factor=(this.options.scaleTo-this.options.scaleFrom)/100;
this.dims=null;
if(this.options.scaleMode=='box')
this.dims=[this.element.offsetHeight,this.element.offsetWidth];
if(/^content/.test(this.options.scaleMode))
this.dims=[this.element.scrollHeight,this.element.scrollWidth];
if(!this.dims)
this.dims=[this.options.scaleMode.originalHeight,
this.options.scaleMode.originalWidth];
},
update:function(position){
var currentScale=(this.options.scaleFrom/100.0)+(this.factor*position);
if(this.options.scaleContent&&this.fontSize)
this.element.setStyle({fontSize:this.fontSize*currentScale+this.fontSizeType});
this.setDimensions(this.dims[0]*currentScale,this.dims[1]*currentScale);
},
finish:function(position){
if(this.restoreAfterFinish)this.element.setStyle(this.originalStyle);
},
setDimensions:function(height,width){
var d={};
if(this.options.scaleX)d.width=width.round()+'px';
if(this.options.scaleY)d.height=height.round()+'px';
if(this.options.scaleFromCenter){
var topd=(height-this.dims[0])/2;
var leftd=(width-this.dims[1])/2;
if(this.elementPositioning=='absolute'){
if(this.options.scaleY)d.top=this.originalTop-topd+'px';
if(this.options.scaleX)d.left=this.originalLeft-leftd+'px';
}else{
if(this.options.scaleY)d.top=-topd+'px';
if(this.options.scaleX)d.left=-leftd+'px';
}
}
this.element.setStyle(d);
}
});
Effect.Highlight=Class.create(Effect.Base,{
initialize:function(element){
this.element=$(element);
if(!this.element)throw(Effect._elementDoesNotExistError);
var options=Object.extend({startcolor:'#ffff99'},arguments[1]||{});
this.start(options);
},
setup:function(){
if(this.element.getStyle('display')=='none'){this.cancel();return;}
this.oldStyle={};
if(!this.options.keepBackgroundImage){
this.oldStyle.backgroundImage=this.element.getStyle('background-image');
this.element.setStyle({backgroundImage:'none'});
}
if(!this.options.endcolor)
this.options.endcolor=this.element.getStyle('background-color').parseColor('#ffffff');
if(!this.options.restorecolor)
this.options.restorecolor=this.element.getStyle('background-color');
this._base=$R(0,2).map(function(i){return parseInt(this.options.startcolor.slice(i*2+1,i*2+3),16)}.bind(this));
this._delta=$R(0,2).map(function(i){return parseInt(this.options.endcolor.slice(i*2+1,i*2+3),16)-this._base[i]}.bind(this));
},
update:function(position){
this.element.setStyle({backgroundColor:$R(0,2).inject('#',function(m,v,i){
return m+((this._base[i]+(this._delta[i]*position)).round().toColorPart());}.bind(this))});
},
finish:function(){
this.element.setStyle(Object.extend(this.oldStyle,{
backgroundColor:this.options.restorecolor
}));
}
});
Effect.ScrollTo=function(element){
var options=arguments[1]||{},
scrollOffsets=document.viewport.getScrollOffsets(),
elementOffsets=$(element).cumulativeOffset();
if(options.offset)elementOffsets[1]+=options.offset;
return new Effect.Tween(null,
scrollOffsets.top,
elementOffsets[1],
options,
function(p){scrollTo(scrollOffsets.left,p.round());}
);
};
Effect.Fade=function(element){
element=$(element);
var oldOpacity=element.getInlineOpacity();
var options=Object.extend({
from:element.getOpacity()||1.0,
to:0.0,
afterFinishInternal:function(effect){
if(effect.options.to!=0)return;
effect.element.hide().setStyle({opacity:oldOpacity});
}
},arguments[1]||{});
return new Effect.Opacity(element,options);
};
Effect.Appear=function(element){
element=$(element);
var options=Object.extend({
from:(element.getStyle('display')=='none'?0.0:element.getOpacity()||0.0),
to:1.0,
afterFinishInternal:function(effect){
effect.element.forceRerendering();
},
beforeSetup:function(effect){
effect.element.setOpacity(effect.options.from).show();
}},arguments[1]||{});
return new Effect.Opacity(element,options);
};
Effect.Puff=function(element){
element=$(element);
var oldStyle={
opacity:element.getInlineOpacity(),
position:element.getStyle('position'),
top:element.style.top,
left:element.style.left,
width:element.style.width,
height:element.style.height
};
return new Effect.Parallel(
[new Effect.Scale(element,200,
{sync:true,scaleFromCenter:true,scaleContent:true,restoreAfterFinish:true}),
new Effect.Opacity(element,{sync:true,to:0.0})],
Object.extend({duration:1.0,
beforeSetupInternal:function(effect){
Position.absolutize(effect.effects[0].element);
},
afterFinishInternal:function(effect){
effect.effects[0].element.hide().setStyle(oldStyle);}
},arguments[1]||{})
);
};
Effect.BlindUp=function(element){
element=$(element);
element.makeClipping();
return new Effect.Scale(element,0,
Object.extend({scaleContent:false,
scaleX:false,
restoreAfterFinish:true,
afterFinishInternal:function(effect){
effect.element.hide().undoClipping();
}
},arguments[1]||{})
);
};
Effect.BlindDown=function(element){
element=$(element);
var elementDimensions=element.getDimensions();
return new Effect.Scale(element,100,Object.extend({
scaleContent:false,
scaleX:false,
scaleFrom:0,
scaleMode:{originalHeight:elementDimensions.height,originalWidth:elementDimensions.width},
restoreAfterFinish:true,
afterSetup:function(effect){
effect.element.makeClipping().setStyle({height:'0px'}).show();
},
afterFinishInternal:function(effect){
effect.element.undoClipping();
}
},arguments[1]||{}));
};
Effect.SwitchOff=function(element){
element=$(element);
var oldOpacity=element.getInlineOpacity();
return new Effect.Appear(element,Object.extend({
duration:0.4,
from:0,
transition:Effect.Transitions.flicker,
afterFinishInternal:function(effect){
new Effect.Scale(effect.element,1,{
duration:0.3,scaleFromCenter:true,
scaleX:false,scaleContent:false,restoreAfterFinish:true,
beforeSetup:function(effect){
effect.element.makePositioned().makeClipping();
},
afterFinishInternal:function(effect){
effect.element.hide().undoClipping().undoPositioned().setStyle({opacity:oldOpacity});
}
});
}
},arguments[1]||{}));
};
Effect.DropOut=function(element){
element=$(element);
var oldStyle={
top:element.getStyle('top'),
left:element.getStyle('left'),
opacity:element.getInlineOpacity()};
return new Effect.Parallel(
[new Effect.Move(element,{x:0,y:100,sync:true}),
new Effect.Opacity(element,{sync:true,to:0.0})],
Object.extend(
{duration:0.5,
beforeSetup:function(effect){
effect.effects[0].element.makePositioned();
},
afterFinishInternal:function(effect){
effect.effects[0].element.hide().undoPositioned().setStyle(oldStyle);
}
},arguments[1]||{}));
};
Effect.Shake=function(element){
element=$(element);
var options=Object.extend({
distance:20,
duration:0.5
},arguments[1]||{});
var distance=parseFloat(options.distance);
var split=parseFloat(options.duration)/10.0;
var oldStyle={
top:element.getStyle('top'),
left:element.getStyle('left')};
return new Effect.Move(element,
{x:distance,y:0,duration:split,afterFinishInternal:function(effect){
new Effect.Move(effect.element,
{x:-distance*2,y:0,duration:split*2,afterFinishInternal:function(effect){
new Effect.Move(effect.element,
{x:distance*2,y:0,duration:split*2,afterFinishInternal:function(effect){
new Effect.Move(effect.element,
{x:-distance*2,y:0,duration:split*2,afterFinishInternal:function(effect){
new Effect.Move(effect.element,
{x:distance*2,y:0,duration:split*2,afterFinishInternal:function(effect){
new Effect.Move(effect.element,
{x:-distance,y:0,duration:split,afterFinishInternal:function(effect){
effect.element.undoPositioned().setStyle(oldStyle);
}});}});}});}});}});}});
};
Effect.SlideDown=function(element){
element=$(element).cleanWhitespace();
var oldInnerBottom=element.down().getStyle('bottom');
var elementDimensions=element.getDimensions();
return new Effect.Scale(element,100,Object.extend({
scaleContent:false,
scaleX:false,
scaleFrom:window.opera?0:1,
scaleMode:{originalHeight:elementDimensions.height,originalWidth:elementDimensions.width},
restoreAfterFinish:true,
afterSetup:function(effect){
effect.element.makePositioned();
effect.element.down().makePositioned();
if(window.opera)effect.element.setStyle({top:''});
effect.element.makeClipping().setStyle({height:'0px'}).show();
},
afterUpdateInternal:function(effect){
effect.element.down().setStyle({bottom:
(effect.dims[0]-effect.element.clientHeight)+'px'});
},
afterFinishInternal:function(effect){
effect.element.undoClipping().undoPositioned();
effect.element.down().undoPositioned().setStyle({bottom:oldInnerBottom});}
},arguments[1]||{})
);
};
Effect.SlideUp=function(element){
element=$(element).cleanWhitespace();
var oldInnerBottom=element.down().getStyle('bottom');
var elementDimensions=element.getDimensions();
return new Effect.Scale(element,window.opera?0:1,
Object.extend({scaleContent:false,
scaleX:false,
scaleMode:'box',
scaleFrom:100,
scaleMode:{originalHeight:elementDimensions.height,originalWidth:elementDimensions.width},
restoreAfterFinish:true,
afterSetup:function(effect){
effect.element.makePositioned();
effect.element.down().makePositioned();
if(window.opera)effect.element.setStyle({top:''});
effect.element.makeClipping().show();
},
afterUpdateInternal:function(effect){
effect.element.down().setStyle({bottom:
(effect.dims[0]-effect.element.clientHeight)+'px'});
},
afterFinishInternal:function(effect){
effect.element.hide().undoClipping().undoPositioned();
effect.element.down().undoPositioned().setStyle({bottom:oldInnerBottom});
}
},arguments[1]||{})
);
};
Effect.Squish=function(element){
return new Effect.Scale(element,window.opera?1:0,{
restoreAfterFinish:true,
beforeSetup:function(effect){
effect.element.makeClipping();
},
afterFinishInternal:function(effect){
effect.element.hide().undoClipping();
}
});
};
Effect.Grow=function(element){
element=$(element);
var options=Object.extend({
direction:'center',
moveTransition:Effect.Transitions.sinoidal,
scaleTransition:Effect.Transitions.sinoidal,
opacityTransition:Effect.Transitions.full
},arguments[1]||{});
var oldStyle={
top:element.style.top,
left:element.style.left,
height:element.style.height,
width:element.style.width,
opacity:element.getInlineOpacity()};
var dims=element.getDimensions();
var initialMoveX,initialMoveY;
var moveX,moveY;
switch(options.direction){
case'top-left':
initialMoveX=initialMoveY=moveX=moveY=0;
break;
case'top-right':
initialMoveX=dims.width;
initialMoveY=moveY=0;
moveX=-dims.width;
break;
case'bottom-left':
initialMoveX=moveX=0;
initialMoveY=dims.height;
moveY=-dims.height;
break;
case'bottom-right':
initialMoveX=dims.width;
initialMoveY=dims.height;
moveX=-dims.width;
moveY=-dims.height;
break;
case'center':
initialMoveX=dims.width/2;
initialMoveY=dims.height/2;
moveX=-dims.width/2;
moveY=-dims.height/2;
break;
}
return new Effect.Move(element,{
x:initialMoveX,
y:initialMoveY,
duration:0.01,
beforeSetup:function(effect){
effect.element.hide().makeClipping().makePositioned();
},
afterFinishInternal:function(effect){
new Effect.Parallel(
[new Effect.Opacity(effect.element,{sync:true,to:1.0,from:0.0,transition:options.opacityTransition}),
new Effect.Move(effect.element,{x:moveX,y:moveY,sync:true,transition:options.moveTransition}),
new Effect.Scale(effect.element,100,{
scaleMode:{originalHeight:dims.height,originalWidth:dims.width},
sync:true,scaleFrom:window.opera?1:0,transition:options.scaleTransition,restoreAfterFinish:true})
],Object.extend({
beforeSetup:function(effect){
effect.effects[0].element.setStyle({height:'0px'}).show();
},
afterFinishInternal:function(effect){
effect.effects[0].element.undoClipping().undoPositioned().setStyle(oldStyle);
}
},options)
);
}
});
};
Effect.Shrink=function(element){
element=$(element);
var options=Object.extend({
direction:'center',
moveTransition:Effect.Transitions.sinoidal,
scaleTransition:Effect.Transitions.sinoidal,
opacityTransition:Effect.Transitions.none
},arguments[1]||{});
var oldStyle={
top:element.style.top,
left:element.style.left,
height:element.style.height,
width:element.style.width,
opacity:element.getInlineOpacity()};
var dims=element.getDimensions();
var moveX,moveY;
switch(options.direction){
case'top-left':
moveX=moveY=0;
break;
case'top-right':
moveX=dims.width;
moveY=0;
break;
case'bottom-left':
moveX=0;
moveY=dims.height;
break;
case'bottom-right':
moveX=dims.width;
moveY=dims.height;
break;
case'center':
moveX=dims.width/2;
moveY=dims.height/2;
break;
}
return new Effect.Parallel(
[new Effect.Opacity(element,{sync:true,to:0.0,from:1.0,transition:options.opacityTransition}),
new Effect.Scale(element,window.opera?1:0,{sync:true,transition:options.scaleTransition,restoreAfterFinish:true}),
new Effect.Move(element,{x:moveX,y:moveY,sync:true,transition:options.moveTransition})
],Object.extend({
beforeStartInternal:function(effect){
effect.effects[0].element.makePositioned().makeClipping();
},
afterFinishInternal:function(effect){
effect.effects[0].element.hide().undoClipping().undoPositioned().setStyle(oldStyle);}
},options)
);
};
Effect.Pulsate=function(element){
element=$(element);
var options=arguments[1]||{},
oldOpacity=element.getInlineOpacity(),
transition=options.transition||Effect.Transitions.linear,
reverser=function(pos){
return 1-transition((-Math.cos((pos*(options.pulses||5)*2)*Math.PI)/2)+.5);
};
return new Effect.Opacity(element,
Object.extend(Object.extend({duration:2.0,from:0,
afterFinishInternal:function(effect){effect.element.setStyle({opacity:oldOpacity});}
},options),{transition:reverser}));
};
Effect.Fold=function(element){
element=$(element);
var oldStyle={
top:element.style.top,
left:element.style.left,
width:element.style.width,
height:element.style.height};
element.makeClipping();
return new Effect.Scale(element,5,Object.extend({
scaleContent:false,
scaleX:false,
afterFinishInternal:function(effect){
new Effect.Scale(element,1,{
scaleContent:false,
scaleY:false,
afterFinishInternal:function(effect){
effect.element.hide().undoClipping().setStyle(oldStyle);
}});
}},arguments[1]||{}));
};
Effect.Morph=Class.create(Effect.Base,{
initialize:function(element){
this.element=$(element);
if(!this.element)throw(Effect._elementDoesNotExistError);
var options=Object.extend({
style:{}
},arguments[1]||{});
if(!Object.isString(options.style))this.style=$H(options.style);
else{
if(options.style.include(':'))
this.style=options.style.parseStyle();
else{
this.element.addClassName(options.style);
this.style=$H(this.element.getStyles());
this.element.removeClassName(options.style);
var css=this.element.getStyles();
this.style=this.style.reject(function(style){
return style.value==css[style.key];
});
options.afterFinishInternal=function(effect){
effect.element.addClassName(effect.options.style);
effect.transforms.each(function(transform){
effect.element.style[transform.style]='';
});
};
}
}
this.start(options);
},
setup:function(){
function parseColor(color){
if(!color||['rgba(0, 0, 0, 0)','transparent'].include(color))color='#ffffff';
color=color.parseColor();
return $R(0,2).map(function(i){
return parseInt(color.slice(i*2+1,i*2+3),16);
});
}
this.transforms=this.style.map(function(pair){
var property=pair[0],value=pair[1],unit=null;
if(value.parseColor('#zzzzzz')!='#zzzzzz'){
value=value.parseColor();
unit='color';
}else if(property=='opacity'){
value=parseFloat(value);
if(Prototype.Browser.IE&&(!this.element.currentStyle.hasLayout))
this.element.setStyle({zoom:1});
}else if(Element.CSS_LENGTH.test(value)){
var components=value.match(/^([\+\-]?[0-9\.]+)(.*)$/);
value=parseFloat(components[1]);
unit=(components.length==3)?components[2]:null;
}
var originalValue=this.element.getStyle(property);
return{
style:property.camelize(),
originalValue:unit=='color'?parseColor(originalValue):parseFloat(originalValue||0),
targetValue:unit=='color'?parseColor(value):value,
unit:unit
};
}.bind(this)).reject(function(transform){
return(
(transform.originalValue==transform.targetValue)||
(
transform.unit!='color'&&
(isNaN(transform.originalValue)||isNaN(transform.targetValue))
)
);
});
},
update:function(position){
var style={},transform,i=this.transforms.length;
while(i--)
style[(transform=this.transforms[i]).style]=
transform.unit=='color'?'#'+
(Math.round(transform.originalValue[0]+
(transform.targetValue[0]-transform.originalValue[0])*position)).toColorPart()+
(Math.round(transform.originalValue[1]+
(transform.targetValue[1]-transform.originalValue[1])*position)).toColorPart()+
(Math.round(transform.originalValue[2]+
(transform.targetValue[2]-transform.originalValue[2])*position)).toColorPart():
(transform.originalValue+
(transform.targetValue-transform.originalValue)*position).toFixed(3)+
(transform.unit===null?'':transform.unit);
this.element.setStyle(style,true);
}
});
Effect.Transform=Class.create({
initialize:function(tracks){
this.tracks=[];
this.options=arguments[1]||{};
this.addTracks(tracks);
},
addTracks:function(tracks){
tracks.each(function(track){
track=$H(track);
var data=track.values().first();
this.tracks.push($H({
ids:track.keys().first(),
effect:Effect.Morph,
options:{style:data}
}));
}.bind(this));
return this;
},
play:function(){
return new Effect.Parallel(
this.tracks.map(function(track){
var ids=track.get('ids'),effect=track.get('effect'),options=track.get('options');
var elements=[$(ids)||$$(ids)].flatten();
return elements.map(function(e){return new effect(e,Object.extend({sync:true},options))});
}).flatten(),
this.options
);
}
});
Element.CSS_PROPERTIES=$w(
'backgroundColor backgroundPosition borderBottomColor borderBottomStyle '+
'borderBottomWidth borderLeftColor borderLeftStyle borderLeftWidth '+
'borderRightColor borderRightStyle borderRightWidth borderSpacing '+
'borderTopColor borderTopStyle borderTopWidth bottom clip color '+
'fontSize fontWeight height left letterSpacing lineHeight '+
'marginBottom marginLeft marginRight marginTop markerOffset maxHeight '+
'maxWidth minHeight minWidth opacity outlineColor outlineOffset '+
'outlineWidth paddingBottom paddingLeft paddingRight paddingTop '+
'right textIndent top width wordSpacing zIndex');
Element.CSS_LENGTH=/^(([\+\-]?[0-9\.]+)(em|ex|px|in|cm|mm|pt|pc|\%))|0$/;
String.__parseStyleElement=document.createElement('div');
String.prototype.parseStyle=function(){
var style,styleRules=$H();
if(Prototype.Browser.WebKit)
style=new Element('div',{style:this}).style;
else{
String.__parseStyleElement.innerHTML='<div style="'+this+'"></div>';
style=String.__parseStyleElement.childNodes[0].style;
}
Element.CSS_PROPERTIES.each(function(property){
if(style[property])styleRules.set(property,style[property]);
});
if(Prototype.Browser.IE&&this.include('opacity'))
styleRules.set('opacity',this.match(/opacity:\s*((?:0|1)?(?:\.\d*)?)/)[1]);
return styleRules;
};
if(document.defaultView&&document.defaultView.getComputedStyle){
Element.getStyles=function(element){
var css=document.defaultView.getComputedStyle($(element),null);
return Element.CSS_PROPERTIES.inject({},function(styles,property){
styles[property]=css[property];
return styles;
});
};
}else{
Element.getStyles=function(element){
element=$(element);
var css=element.currentStyle,styles;
styles=Element.CSS_PROPERTIES.inject({},function(results,property){
results[property]=css[property];
return results;
});
if(!styles.opacity)styles.opacity=element.getOpacity();
return styles;
};
}
Effect.Methods={
morph:function(element,style){
element=$(element);
new Effect.Morph(element,Object.extend({style:style},arguments[2]||{}));
return element;
},
visualEffect:function(element,effect,options){
element=$(element);
var s=effect.dasherize().camelize(),klass=s.charAt(0).toUpperCase()+s.substring(1);
new Effect[klass](element,options);
return element;
},
highlight:function(element,options){
element=$(element);
new Effect.Highlight(element,options);
return element;
}
};
$w('fade appear grow shrink fold blindUp blindDown slideUp slideDown '+
'pulsate shake puff squish switchOff dropOut').each(
function(effect){
Effect.Methods[effect]=function(element,options){
element=$(element);
Effect[effect.charAt(0).toUpperCase()+effect.substring(1)](element,options);
return element;
};
}
);
$w('getInlineOpacity forceRerendering setContentZoom collectTextNodes collectTextNodesIgnoreClass getStyles').each(
function(f){Effect.Methods[f]=Element[f];}
);
Element.addMethods(Effect.Methods);
var ConditionSelectorWidget=Class.create(Glyde.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=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.glu.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');
}
});
ConditionSelectorWidget.instance_id=0;
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();
};
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();
};
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();
};
var 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 PriceAdjuster(containing_element,
this._on_adjuster_stop.bind(this));
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();
},
_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().style.color='red';
}else{
this._adjuster.text_elem().style.color='black';
}
},
_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'$'+PriceAdjuster.dollars_and_cents(this._mailer_cost(),true);
},
_render_transaction_fee:function(){
return'$'+PriceAdjuster.dollars_and_cents(Math.floor(((this.transaction_fee_perc/100)*this.cents)),true);
},
_mailer_cost:function(){
return this._sku.mailer_cost.cents;
},
_render_proceeds:function(){
var proceeds=this._proceeds_cents();
return'$'+PriceAdjuster.dollars_and_cents(proceeds,true);
},
_proceeds_info_title:function(){
var html='$'+PriceAdjuster.dollars_and_cents(this.cents,true)+' -  '+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');
}
});
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();
};
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();
};
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();
};
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('$'+PriceAdjuster.dollars_and_cents(this.sp,true));
_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();
};
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();
};
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();
};
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();
};
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();
};
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();
};
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();
};
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('$'+PriceAdjuster.dollars_and_cents(this.market_price,true));
_j.ns('</li>');
}
else{
_j.ns('<li');_j.s('>');
_j.ns('Your Price is');
_j.ns('$'+PriceAdjuster.dollars_and_cents(this._current_price_difference_from_market,true));
_j.ns(this.set_v_market==-1?'below':'above');
_j.ns('the Market Price of');
_j.ns('$'+PriceAdjuster.dollars_and_cents(this.market_price,true)+'.');
_j.ns('</li>');
}
return _j.v();
};
PriceSelector.prototype._render_proceeds_info=function(){
var _j=new Jaml();
_j.ns('<li');_j.s('>');
_j.ns('Your proceeds will be');
_j.ns(this._render_proceeds()+'.&nbsp;');
var src=Glyde.image.fully_qualified_url('images/information.png');
var title=this._proceeds_info_title();
_j.ns('<img');_j.s(' id="proceeds_info_icon"');_j.s(' src="'+(src)+'"');_j.s(' title="'+(title)+'"');_j.s(' />');
_j.ns('</li>');
return _j.v();
};
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();
};
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('$'+PriceAdjuster.dollars_and_cents(this.sp,true));
_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();
};
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('$'+PriceAdjuster.dollars_and_cents(this.sp,true)+'.&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('$'+PriceAdjuster.dollars_and_cents(this.market_price,true)+'.');
}
_j.ns('</li>');
return _j.v();
};
var Lineup=Class.create(ScrollWidget,{
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('mouseover',this.handle_mouseover.bindAsEventListener(this));
this._element.observe('mouseout',this.handle_mouseout.bindAsEventListener(this));
this._element.observe('click',this.handle_click.bindAsEventListener(this));
},
handle_mouseover:function(e){
var target=Event.element(Event.get(e));
if(target&&target.id.indexOf('image_')!=-1){
var glu_id=target.id.split('image_')[1];
this._on_cell_mouseover({elem:target,id:glu_id,event:e});
}
},
handle_mouseout:function(e){
var target=Event.element(Event.get(e));
if(target&&target.id.indexOf('image_')!=-1){
var glu_id=target.id.split('image_')[1];
this._on_cell_mouseout({elem:target,id:glu_id,event:e});
}
},
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);
}
},
_on_cell_mouseover:function(info){
var glu=this._glus_map[info.id];
var zoomed_image_url=Glyde.image.fully_qualified_cover_url(glu,155,210);
var zoomed_image_is_loaded=Lineup.zoomed_images_loaded[zoomed_image_url];
if(!zoomed_image_is_loaded){return;}
var cell=$('lineup_cell_'+info.id);
cell.className=cell.className+=' hover';
var image=$('image_'+info.id);
var style=image.style;
var dims=Glyde.image.dimensions_from_cover_url(zoomed_image_url);
style.backgroundImage="url("+zoomed_image_url+")";
style.height=dims.height+'px';
style.width=dims.width+'px';
style.zIndex=100;
},
_on_cell_mouseout:function(info){
var cell=$('lineup_cell_'+info.id);
cell.className=cell.className.replace(/ hover/,'');
var glu=this._glus_map[info.id];
if(glu){
var image=$('image_'+info.id);
var style=image.style;
var dims=Glyde.image.dimensions_from_cover_url(Glyde.image.fully_qualified_cover_url_for_max_w_h(glu,140,190));
style.backgroundImage="none";
style.height=dims.height+'px';
style.width=dims.width+'px';
}
},
_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)]
});
glus.each(function(glu){
var zoomed_image_url=Glyde.image.fully_qualified_cover_url_for_max_w_h(glu,155,210);
Glyde.image.preload(zoomed_image_url,function(){
Lineup.zoomed_images_loaded[zoomed_image_url]=true;
});
});
}
(callback||this._on_pages_ready.bind(this))(pages,total_items);
this._fix_ie6_mouseover_shakes();
this._add_to_glus_map(json.glus);
}.bind(this);
this._fetch_lineup_pages(page_range,render_func);
},
_fetch_lineup_pages:function(page_range,callback){
var options={
evalScripts:true,
method:'post',
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)
};
Loading.show();
new Ajax.Request('/glus/listing',options);
},
_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);
},
_fix_ie6_mouseover_shakes:function(){
if(Browser.IE){
var cells=$$('.lineup_cell');
var i=0;
for(i=0;i<cells.length;++i){
cells[i].onmouseenter=cells[i].onmouseover;
cells[i].onmouseover=null;
cells[i].onmouseleave=cells[i].onmouseout;
cells[i].onmouseout=null;
}
}
}
});
Lineup.zoomed_images_loaded={};
Lineup.prototype._render_lineup_cells=function(items,total_items){
var s=[];
s.push('<div class="scroll_item">');
for(var c=0;c<items.length;c++){
s.push('');s.push(this._render_lineup_cell(items[c],total_items));s.push('');
}
s.push('</div>');
return s.join('');
}
Lineup.prototype._render_lineup_cell=function(glu,total_items){
var s=[];
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'
s.push('<div id="lineup_cell_');s.push(glu.id);s.push('" class="actionable sfloatl ');s.push(cell_class);s.push(' ');s.push(type_class);s.push('">');
var background_image_url=Glyde.image.fully_qualified_cover_url_for_max_w_h(glu,140,190,'d')
s.push('<div id="item_info_');s.push(glu.id);s.push('" class="item_info" style="background-image:url(');s.push(background_image_url);s.push(');">');
s.push('<a id="image_');s.push(glu.id);s.push('" style="background-image:none; background-repeat: no-repeat; height:');s.push(s_dims.height);s.push('px; width:');s.push(s_dims.width-1);s.push('px" class="image"></a>');
s.push('<div id="extra_info_');s.push(glu.id);s.push('" class="extra_info" title="');s.push(glu.medium_name);s.push('">');
s.push('');s.push(med_name.truncate_with_delimiters(this.MEDIUM_NAME_CHAR_LIMIT,' - ')||'&nbsp;');s.push('');
s.push('</div>');
s.push('');s.push(glu.product_codes_html);s.push('');
s.push('</div>');
s.push('</div>');
return s.join('');
}
var ListingDetailsWidget=Class.create(Glyde.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)
{
$super(element);
this.show_mode=(show_mode||this.SHOW_BOTH);
this.condition_selector=new ConditionSelectorWidget(this.$$('.condition_control_box')[0],this.on_condition_change.bind(this),(glu?glu.condition_type:null));
this.price_selector=new PriceSelector(element,glu,start_cents,start_condition_id);
this._donation_selector=new 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);
},
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);
}
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();
},
serialize:function(){
return{
'listing[price]':this.price_selector.cents/100,'sku[condition_id]':this.condition_selector.selected_value(),
'sku[glu_id]':this._glu.id,
'listing[charity_id]':this.charity_id(),
'listing[charity_name]':this.charity_name(),
'listing[charity_percentage]':this.charity_percentage()
};
},
_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(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);
}
}
});
AddItemDialog=Class.create(Glyde.Dialog,{
ANCHOR_ID:'add_button',
SEARCH_INPUT:'add_search_input',
SEARCH_BOX:'add_search_box',
DIALOG_ID:'add_item_dialog',
initialize:function(on_add){
this.on_add=on_add||Glyde.empty_function;
Glyde.Dialog.prototype.initialize.call(this,{is_light:true});
this._should_center=false;
this._use_arrow=false;
},
current_state:function(params){
if(this.is_open()||(this.lineup_dialog&&this.lineup_dialog.is_open())
||(this.confirmation_dialog&&this.confirmation_dialog.is_open())){
params.add_open=this.is_open();
if(this._current_req){
params.add_call=this._current_req.options._call;
params.add_p=encodeURIComponent(Hash.toQueryString(this._current_req.options._params));
}
if(this.confirmation_dialog&&this.confirmation_dialog.is_open()){
params.confirm_open=true;
var glu=this.confirmation_dialog.glu();
params.confirm_p=encodeURIComponent(Hash.toQueryString({id:glu.id}));
}
}
return params;
},
restore_from_state:function(params){
var async_req_count=0;
if(params.add_open=='true'){
if(this.lineup_dialog){
this.lineup_dialog.close(true);
}
if(this.confirmation_dialog){
this.confirmation_dialog.close(true);
}
this.open();
}else if(params.confirm_open=='true'){
async_req_count++;
if(this.lineup_dialog){
this.lineup_dialog.close(true);
}
if(this.is_open()){
this.close();
}
var glu=decodeURIComponent(params.confirm_p).toQueryParams();
this._display_confirmation_dialog(glu);
}else if(params.add_call){
if(this.confirmation_dialog){
this.confirmation_dialog.close();
}
var p=decodeURIComponent(params.add_p).toQueryParams();
switch(params.add_call){
case'nt':
async_req_count++;
this._on_new_title(p.vertical,null,p.search_key,true);
break;
}
}else if(this.is_open()){
this.close();
}
return async_req_count;
},
_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 add_item_flow_container';
document.body.appendChild(div);
}
return div;
},
_set_container_ids:function($super,instance_num){
$super(instance_num);
this._dialog_container_id='add_item_dialog_container';
},
_compose_content:function(container,html){
$(this._dialog_container_id).innerHTML=html;
},
open:function(){
Glyde.Dialog.prototype.open.call(this,$(this.ANCHOR_ID),this._to_html());
$(this.SEARCH_BOX).add_focus_halo();
this.live_searcher=new LiveSearcher(this.SEARCH_INPUT,
this._on_new_title.bind(this),
{selected_domains:['books','games','music','videos']},
'Enter new item title');
if(this._old_search){
this.live_searcher.set_text(this._old_search);
this.live_searcher.activate();
}
},
close:function(save_old_search){
if(this.is_open()){
this._old_search=null;
if(save_old_search){
this._old_search=this.live_searcher.current_text();
}
this.live_searcher.reset();
Glyde.Dialog.prototype.close.call(this);
}else{
this._old_search=null;
}
},
cancel_search:function(){
this._old_search=null;
if(this.live_searcher)this.live_searcher.reset();
this._current_req=null;
},
_on_new_title:function(vertical,title,search_key,from_back){
var options={
_call:'nt',
_params:{vertical:vertical,search_key:search_key},
method:'post',
parameters:'res_id='+search_key+'&vertical='+vertical,
onComplete:function(transport){
Loading.hide();
var json=Ajax.evalJSON(transport.responseText);
if(json.success){
this._on_new_title_results(json,vertical,search_key);
if(!from_back){
Glyde.page.end_backable_action();
}
}else{
Glyde.page.handle_server_errors(json);
}
}.bind(this)
};
Loading.show();
this._current_req=new Ajax.Request('/glus/listing',options);
if(!from_back){
Glyde.page.start_backable_action();
}
},
_on_new_title_results:function(json,vertical,search_key){
if(json.success){
if(json.total==1){
var glu=json.glus[0];
this._display_confirmation_dialog(glu);
}else{
this._display_lineup(json,vertical,search_key);
}
}
},
_display_lineup:function(json,vertical,search_key){
var options={
search_key:search_key,
vertical:vertical,
lineup_size:3,
on_close:this._lineup_canceled.bind(this),
is_light:true
};
this.lineup_dialog=new LineupDialog(this.ANCHOR_ID,
this._display_confirmation_dialog_from_lineup.bind(this),
options
);
this._open_lineup();
},
_lineup_canceled:function(){
this.cancel_search();
},
_open_lineup:function(){
this.close(true);
this.lineup_dialog.open();
},
_display_confirmation_dialog_from_lineup:function(glu_id,glu){
this._display_confirmation_dialog(glu);
},
_display_confirmation_dialog:function(glu){
this.confirmation_dialog=new AddConfirmationDialog(this.ANCHOR_ID,this.on_submit_glu.bind(this),glu,{is_light:true});
this._open_confirmation_dialog();
},
_open_confirmation_dialog:function(){
this._current_req=null;
this.close(true);
this.confirmation_dialog.open();
},
on_submit_glu:function(glu_id,condition_id,cancelled){
var me=this;
var on_complete=function(){
me.confirmation_dialog.close(true);
};
this._add(glu_id,condition_id,on_complete,cancelled);
},
_add:function(glu_id,condition_id,on_complete,cancelled){
var local_on_complete=function(){
on_complete();
if(!this.is_open()){
if(!cancelled){
this._old_search=null;
}
this.open();
}
}.bind(this);
if(cancelled){
local_on_complete();
}else{
this.on_add(glu_id,condition_id,local_on_complete);
}
},
_close_on_mouseup:function(event){
var target=Event.element(event);
return!target.descendantOf('suggest_listadd_search_input')&&!this._mouse_down_within_dialog;
},
_show_search:function(){
$('add_search_box').display();
this.live_searcher.set_focus();
},
_position:function(target){
var targ_pos=target.cumulativeOffset();
var targ_dims=target.getDimensions();
var dialog_container=$(this._dialog_container_id);
var style=dialog_container.style;
style.top=(targ_pos.top+targ_dims.height+1)+'px';
style.left=(targ_pos.left-20)+'px';
},
_position_arrow:function(target,arrow){
arrow.style.left='32px';
}
});
AddItemDialog.prototype._to_html=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="dialog_close_box"');_j.s('>');
_j.ns('<a');_j.s(' class="dialog_close_button close_button a_button"');_j.s(' href="'+('javascript:void(0)')+'"');_j.s(' onclick="'+('Glyde.Dialog.close();')+'"');_j.s('>');
_j.ns('</a>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="lineup_title"');_j.s('>');
_j.ns('<span');_j.s(' class="primary_text"');_j.s('>Add');
_j.ns('</span>');
_j.ns('- enter the title of an item you would like to add to your collection');
_j.ns('</div>');
_j.ns('<div');_j.s(' id="add_item_dialog"');_j.s('>');
_j.ns('<div');_j.s(' class="add_input_box"');_j.s(' id="add_search_box"');_j.s(' onclick="'+("$('add_search_input').focus();")+'"');_j.s('>');
_j.ns('<div');_j.s(' id="add_search_box_icon"');_j.s(' onclick="'+("$('add_search_input').focus();")+'"');_j.s('>');
_j.ns('</div>');
_j.ns('<input');_j.s(' id="add_search_input"');_j.s('>');
_j.ns('<a');_j.s(' class="sblock cancel"');_j.s(' id="cancel_search"');_j.s(' style="'+('display:none')+'"');_j.s(' href="'+('javascript:void(0)')+'"');_j.s(' onclick="'+("Glyde.page.page.cancel_search(); return false;")+'"');_j.s('>&nbsp;');
_j.ns('</a>');
_j.ns('</input>');
_j.ns('</div>');
_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 Lineup($('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);
}
},
_position:function(target){
var targ_pos=target.viewportOffset();
var targ_dims=target.getDimensions();
var dialog_container=$(this._dialog_container_id);
var style=dialog_container.style;
style.top=(targ_pos.top+targ_dims.height+1)+'px';
style.left=(targ_pos.left-20)+'px';
},
_position_arrow:function(target,arrow){
arrow.style.left='32px';
}
});
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();
};
AddConfirmationDialog=Class.create(Glyde.Dialog,{
ADD_CONFIRMATION_CONTENT_ID:'add_confirmation_box',
ADD_CONFIRMATION_HOME_ID:'add_confirmation_box_home',
ADD_CONFIRMATION_BUTTON_ID:'add_to_catalog_button',
ADD_CANCEL_BUTTON_ID:'not_my_item_button',
CONDITION_CONTAINER_ID:'add_condition_control_box',
DEFAULT_CONDITION_ID:3,initialize:function(target_id,on_submit,glu,options,should_position){
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;
if(!this._should_position){
this._is_modal=false;
}
this._glu=glu;
},
glu:function(){
return this._glu;
},
_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 add_item_flow_container';
document.body.appendChild(div);
}
return div;
},
_set_container_ids:function(instance_num){
this._dialog_container_id='add_confirmation_dialog_container';
},
_compose_content:function(container,html){
$(this._dialog_container_id).innerHTML=html;
},
open:function(){
if(this._glu.condition_type){
var func=function(){
this._render_dialog();
}.bind(this);
Glyde.page.run_client_backable_action(func);
}else{
var options={
method:'get',
onComplete:function(resp,o){
Loading.hide();
var json=resp.responseJSON;
if(json.success){
this._glu=json.glus[0];
this._render_dialog();
}else{
Glyde.page.handle_server_errors(json);
}
Glyde.page.end_backable_action();
}.bind(this)
};
Loading.show();
Glyde.page.start_backable_action();
new Ajax.Request('/glus/'+this._glu.id,options);
}
},
_render_dialog:function(){
Glyde.Dialog.prototype.open.call(this,$(this._target_id),this._to_html(this._glu));
this._condition_selector=new ConditionSelectorWidget($(this.CONDITION_CONTAINER_ID),this._on_condition_change.bind(this),this._glu.condition_type,this.DEFAULT_CONDITION_ID,'collection_add_desc');
this._condition_selector.set_title("Condition (Optional)");
AnchorButton.create_all();
$(this.ADD_CONFIRMATION_BUTTON_ID).observe('click',this._proxy_submit.bindAsEventListener(this));
$(this.ADD_CANCEL_BUTTON_ID).observe('click',this._proxy_submit.bindAsEventListener(this,true));
this._selection_clicked=false;
},
_on_condition_change:function(){
this._condition_selector.select(this._condition_selector.selected_id(),this._glu.condition_type);
},
_proxy_submit:function(event,cancelled){
if(this._selection_clicked){return;}
this._selection_clicked=true;
this._on_submit(this._glu.id,this._condition_selector.selected_value(),cancelled);
},
_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);
}
}
});
AddConfirmationDialog.prototype._to_html=function(glu){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="dialog_close_box"');_j.s('>');
_j.ns('<a');_j.s(' class="dialog_close_button close_button a_button"');_j.s(' href="'+('javascript:void(0)')+'"');_j.s(' onclick="'+('Glyde.Dialog.close();')+'"');_j.s('>');
_j.ns('</a>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="lineup_title"');_j.s(' id="add_confirmation_title"');_j.s('>');
_j.ns('<span');_j.s(' class="primary_text"');_j.s('>Add');
_j.ns('</span>');
_j.ns('- confirm that this is your item');
_j.ns('</div>');
_j.ns('<div');_j.s(' id="add_confirmation_glu"');_j.s('>');
_j.ns('<div');_j.s(' class="confirmation_glu"');_j.s('>');
var image_url=Glyde.image.fully_qualified_cover_url_for_max_w_h(glu,147,200,'d');
var dims=Glyde.image.dimensions_from_cover_url(image_url);
_j.ns('<div');_j.s(' class="image_wrapper"');_j.s(' style="'+('background-image : url('+image_url+')')+'"');_j.s('>');
_j.ns('<a');_j.s(' class="image_placeholder"');_j.s(' style="'+('width: '+dims.width+'px; height: '+dims.height+'px')+'"');_j.s('>');
_j.ns('</a>');
_j.ns('<div');_j.s(' class="info"');_j.s('>');
var title=new String(glu.title+(glu.orig_release_year?' ('+glu.orig_release_year+')':''));
_j.ns('<div');_j.s(' class="ex_title extra_info sfont_smallest"');_j.s(' title="'+(title)+'"');_j.s('>');
_j.ns(title.truncate_with_delimiters(35));
_j.ns('</div>');
_j.ns('<div');_j.s(' class="extra_info sfont_smallest"');_j.s('>');
_j.ns(glu.medium_name.truncate_with_delimiters(40,' - '));
_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>');
_j.ns('<div');_j.s(' class="confirmation_listing_details listing_details_box"');_j.s('>');
_j.ns('<div');_j.s(' class="condition_box control_box"');_j.s(' id="add_condition_control_box"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' id="add_confirmation_button_container"');_j.s('>');
_j.ns('<a');_j.s(' class="a_button"');_j.s(' id="not_my_item_button"');_j.s(' href="'+('javascript:void(0);')+'"');_j.s('>');
_j.ns('</a>');
_j.ns('<a');_j.s(' class="a_button"');_j.s(' id="add_to_catalog_button"');_j.s(' href="'+('javascript:void(0);')+'"');_j.s('>');
_j.ns('</a>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
ImportDialog=Class.create(Glyde.Dialog,{
DIALOG_ID:'import_dialog',
DIALOG_FADE_AREA_ID:'import_dialog_fade_area',
ANCHOR_ID:'import_button',
DVDSPOT_BUTTON_ID:'dvdspot_button',
LIBRARY_THING_BUTTON_ID:'library_thing_button',
LISTAL_BUTTON_ID:'listal_button',
GOODREADS_BUTTON_ID:'goodreads_button',
FILE_UPLOAD_BUTTON_ID:'file_upload_button',
BACK_BUTTON_ID:'back_button',
FILE_UPLOAD_MODE:1,
SITE_UPLOAD_MODE:2,
EVENT_UNSUPPORTED_FILE_TYPE:'import_dialog:unhandled_content_type',
initialize:function($super,on_add){
$super({is_light:true,use_small_close:true});
this._should_center=false;
this._use_arrow=true;
this._disable_escape=false;
},
open:function($super){
$super($(this.ANCHOR_ID),this._to_html());
AnchorButton.create_all();
this._setup_onclick_handlers();
},
close:function(){
Glyde.Dialog.prototype.close.call(this);
},
_position:function(target){
var targ_pos=target.cumulativeOffset();
var targ_dims=target.getDimensions();
var dialog_container=$(this._dialog_container_id);
var style=dialog_container.style;
var browser_padding=10;
if(Browser.IE6){
browser_padding=2;
}
style.top=(targ_pos.top+targ_dims.height+browser_padding)+'px';
style.left=(targ_pos.left-20)+'px';
},
_position_arrow:function(target,arrow){
arrow.style.left='25px';
},
_setup_onclick_handlers:function(){
$(this.LIBRARY_THING_BUTTON_ID).onclick=this._library_thing_click.bind(this);
$(this.LISTAL_BUTTON_ID).onclick=this._listal_click.bind(this);
$(this.GOODREADS_BUTTON_ID).onclick=this._goodreads_click.bind(this);
$(this.FILE_UPLOAD_BUTTON_ID).onclick=this._file_upload_click.bind(this);
$(this.BACK_BUTTON_ID).onclick=this._reset_mode.bind(this);
},
_reset_mode:function(){
this._switch_mode();
},
_dvdspot_click:function(){
this._click_site('dvdspot');
},
_library_thing_click:function(){
this._click_site('library_thing');
},
_listal_click:function(){
this._click_site('listal');
},
_goodreads_click:function(){
this._click_site('goodreads');
},
_click_site:function(site_name){
this._switch_mode(this.SITE_UPLOAD_MODE,site_name);
this._set_site_logo(site_name);
},
_file_upload_click:function(){
this._switch_mode(this.FILE_UPLOAD_MODE);
this._set_site_logo('');
},
_set_site_logo:function(className){
var logo_el=$('site_logo');
logo_el.className=className;
},
_switch_mode:function(mode,mode_name){
this.__mode=mode;
this.__mode_name=mode_name;
var options={
onComplete:this._switch_mode_after_fade.bind(this),
duration:200
};
this._fade_effect=new fx.Opacity($(this.DIALOG_FADE_AREA_ID),options);
this._fade_effect.toggle();
},
_switch_mode_after_fade:function(){
var dialog=$(this.DIALOG_ID);
dialog.className=dialog.className.replace(/\s*file_state|\s*site_state/,'');
$('password_part').vshow();
switch(this.__mode){
case this.SITE_UPLOAD_MODE:
dialog.className+=' site_state';
this.mode_handler=new SiteUploadModeHandler(this._on_file_upload_finished.bind(this),this.__mode_name);
$$('label[for="collection_import_login"]')[0].innerHTML=
((this.__mode_name=='goodreads')?'email address':'username');
break;
case this.FILE_UPLOAD_MODE:
dialog.className+=' file_state';
this.mode_handler=new FileUploadModeHandler(this._on_file_upload_finished.bind(this),this.__mode_name);
break;
default:
break;
}
this._fade_effect.options.onComplete=Glyde.empty_function;
this._fade_effect.toggle();
},
_on_file_upload_finished:function(json){
this.close();
if(json&&json.exception&&json.exception.message){
if(json.exception.message.match(/Content type is not included in the list/)){
Glyde.notify.publish(this.EVENT_UNSUPPORTED_FILE_TYPE);
}else{
Glyde.page.handle_server_errors(json);
}
}else{
col_import=json&&json.collection_import;
if(col_import){
Glyde.page.import_updater.start_poll(col_import.id);
}
}
}
});
ModeHandler=Class.create({
initialize:function(on_upload_submit){
this._on_upload_submit=on_upload_submit||Glyde.empty_function;
},
import_button_id:function(){
alert('ModeHandler: import_button_id is abstract');
},
_submit_import:function(event){
Glyde.page.update_submit_button(this.import_button_id(),
this.submit_form.bind(this),true);
event.stop();
},
_upload_finished:function(json){
console.log(json);
Glyde.page.reset_submit_button(this.import_button_id());
Glyde.page.server_API.upload_callback=null;
this._on_upload_submit(json);
},
_create_hidden_input:function(name,value){
var input=document.createElement('input');
input.type='hidden';
input.name=name;
input.value=value;
return input;
},
_append_dedupe_value:function(form){
form.appendChild(this._create_hidden_input('collection_import[make_dupes]',
!$('dedupe_checkbox').checked));
}
});
FileUploadModeHandler=Class.create(ModeHandler,{
COLLECTION_UPLOAD_BUTTON_ID:'collection_upload_button',
FORM_ID:'collection_upload_form',
initialize:function($super,on_upload_submit){
$super(on_upload_submit);
var button=new Glyde.ButtonWidget($(this.COLLECTION_UPLOAD_BUTTON_ID),'Import',{color:'blue'});
button.observe('widget:activate',this.handle_upload_click.bindAsEventListener(this));
},
handle_upload_click:function(event){
return this._submit_import(event);
},
import_button_id:function(){
return this.COLLECTION_UPLOAD_BUTTON_ID;
},
submit_form:function(){
Glyde.page.server_API.upload_callback=this._upload_finished.bind(this);
var udata=$('collection_import_attachment_attributes_uploaded_data');
if(udata.value.blank()){
this._upload_finished();
}else{
var form=$('collection_upload_form');
this._append_dedupe_value(form);
form.appendChild(Glyde.page.server_API.hidden_input_for_iframe_pipe());
form.action='/collection_imports';
form.submit();
}
}
});
SiteUploadModeHandler=Class.create(ModeHandler,{
USER_LOGIN_ID:'collection_import_login',
USER_PASSWORD_ID:'collection_import_password',
SITE_IMPORT_FORM_ID:'site_import_form',
SITE_LOGIN_BUTTON_ID:'site_login_button',
image_names:{
'listal':'listal_favicon.ico',
'goodreads':'gr_favicon.ico',
'library_thing':'lib_thing_favicon.ico'
},
initialize:function($super,on_upload_submit,site_name){
$super(on_upload_submit);
$(this.USER_LOGIN_ID).add_focus_halo();
$(this.USER_PASSWORD_ID).add_focus_halo();
var button=new Glyde.ButtonWidget($(this.SITE_LOGIN_BUTTON_ID),'Import',{color:'blue'});
button.observe('widget:activate',this.handle_credential_submit_click.bindAsEventListener(this));
$('site_logo').style.backgroundImage="url(../../images/"+this.image_names[site_name]+')';
this._site_name=site_name;
},
handle_credential_submit_click:function(event){
return this._submit_import(event);
},
submit_form:function(){
Glyde.page.server_API.upload_callback=this._upload_finished.bind(this);
var form=$('site_import_form');
this._append_dedupe_value(form);
form.appendChild(this._create_redirect_input());
form.appendChild(this._create_site_type_input());
form.appendChild(Glyde.page.server_API.hidden_input_for_iframe_pipe());
form.action=Glyde.urls.secure_site_import_url;
form.submit();
},
import_button_id:function(){
return this.SITE_LOGIN_BUTTON_ID;
},
_create_site_type_input:function(){
return this._create_hidden_input('collection_import[import_type]',this._site_name);
},
_create_redirect_input:function(){
return this._create_hidden_input('redirect',true);
}
});
ImportDialog.prototype._to_html=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' id="import_dialog"');_j.s('>');
_j.ns('<div');_j.s(' id="import_dialog_fade_area"');_j.s('>');
_j.ns('<div');_j.s(' id="nav"');_j.s('>');
_j.ns('<div');_j.s(' class="nav_box"');_j.s('>');
_j.ns('<a');_j.s(' class="nav_button"');_j.s(' id="back_button"');_j.s(' href="'+("javascript:void(0)")+'"');_j.s('>Back');
_j.ns('</a>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="vertical_separator"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="choice"');_j.s('>');
_j.ns('<span');_j.s(' class="section_label"');_j.s('>Import from one of these sites');
_j.ns('</span>');
_j.ns('<a');_j.s(' class="import_button"');_j.s(' id="library_thing_button"');_j.s(' href="'+("javascript:void(0)")+'"');_j.s('>');
_j.ns('<img');_j.s(' class="icon"');_j.s(' src="'+("images/lib_thing_favicon.ico")+'"');_j.s(' />');
_j.ns('Library Thing');
_j.ns('</a>');
_j.ns('<a');_j.s(' class="import_button"');_j.s(' id="listal_button"');_j.s(' href="'+("javascript:void(0)")+'"');_j.s('>');
_j.ns('<img');_j.s(' class="icon"');_j.s(' src="'+("images/listal_favicon.ico")+'"');_j.s(' />');
_j.ns('Listal');
_j.ns('</a>');
_j.ns('<a');_j.s(' class="import_button"');_j.s(' id="goodreads_button"');_j.s(' href="'+("javascript:void(0)")+'"');_j.s('>');
_j.ns('<img');_j.s(' class="icon"');_j.s(' src="'+("images/gr_favicon.ico")+'"');_j.s(' />');
_j.ns('Good Reads');
_j.ns('</a>');
_j.ns('<br');_j.s(' />');
_j.ns('<br');_j.s(' />');
_j.ns('<span');_j.s(' class="section_label"');_j.s('>Or upload a file');
_j.ns('</span>');
_j.ns('<a');_j.s(' class="import_button"');_j.s(' id="file_upload_button"');_j.s(' href="'+("javascript:void(0)")+'"');_j.s('>');
_j.ns('File Upload');
_j.ns('</a>');
_j.ns('<span');_j.s(' class="descriptions"');_j.s('>Accepts: Text, Csv, tab-delimited');
_j.ns('</span>');
_j.ns('<div');_j.s(' class="sclear"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="dedupe_box"');_j.s('>');
_j.ns('<input');_j.s(' id="dedupe_checkbox"');_j.s(' type="'+("checkbox")+'"');_j.s(' checked="'+(true)+'"');_j.s('>');
_j.ns('</input>');
_j.ns('<label');_j.s(' for="'+("dedupe_checkbox")+'"');_j.s('>Don\'t import duplicates');
_j.ns('</label>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="site_upload"');_j.s('>');
_j.ns('<center');_j.s('>');
_j.ns('<div');_j.s(' id="site_logo"');_j.s('>');
_j.ns('</div>');
_j.ns('<p');_j.s(' class="section_label"');_j.s('>Enter your credentials to begin');
_j.ns('<br');_j.s(' />');
_j.ns('importing your collection');
_j.ns('</p>');
_j.ns('<p');_j.s('>Note: glyde will not store');
_j.ns('<br');_j.s(' />');
_j.ns('your credentials.');
_j.ns('</p>');
_j.ns('<form');_j.s(' id="site_import_form"');_j.s(' action="'+("")+'"');_j.s(' onsubmit="'+("return false")+'"');_j.s(' target="'+("hidden_upload_frame")+'"');_j.s(' method="'+("POST")+'"');_j.s('>');
_j.ns('<div');_j.s(' class="part"');_j.s(' id="login_part"');_j.s('>');
_j.ns('<label');_j.s(' for="'+("collection_import_login")+'"');_j.s('>username');
_j.ns('</label>');
_j.ns('<br');_j.s(' />');
_j.ns('<input');_j.s(' type="'+("text")+'"');_j.s(' name="'+("collection_import[login]")+'"');_j.s(' id="'+("collection_import_login")+'"');_j.s('>');
_j.ns('</input>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="part"');_j.s(' id="password_part"');_j.s('>');
_j.ns('<label');_j.s(' for="'+("collection_import_password")+'"');_j.s('>password');
_j.ns('</label>');
_j.ns('<img');_j.s(' class="lock_image"');_j.s(' src="'+("images/ssl_lock.gif")+'"');_j.s(' />');
_j.ns('<br');_j.s(' />');
_j.ns('<input');_j.s(' id="collection_import_password"');_j.s(' type="'+("password")+'"');_j.s(' name="'+("collection_import[password]")+'"');_j.s('>');
_j.ns('</input>');
_j.ns('</div>');
_j.ns('<div');_j.s(' id="site_login_button"');_j.s('>');
_j.ns('</div>');
_j.ns('</form>');
_j.ns('</center>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="file_upload"');_j.s('>');
_j.ns('<p');_j.s(' class="section_label"');_j.s('>Import from a file');
_j.ns('</p>');
_j.ns('<form');_j.s(' id="collection_upload_form"');_j.s(' action="'+("")+'"');_j.s(' enctype="'+("multipart/form-data")+'"');_j.s(' target="'+("hidden_upload_frame")+'"');_j.s(' method="'+("POST")+'"');_j.s('>');
_j.ns('<input');_j.s(' id="collection_import_attachment_attributes_uploaded_data"');_j.s(' type="'+("file")+'"');_j.s(' name="'+("collection_import[attachment_attributes][uploaded_data]")+'"');_j.s('>&nbsp;');
_j.ns('</input>');
_j.ns('<input');_j.s(' id="collection_import_import_type"');_j.s(' type="'+("hidden")+'"');_j.s(' name="'+("collection_import[import_type]")+'"');_j.s(' value="'+("generic")+'"');_j.s('>');
_j.ns('</input>');
_j.ns('<br');_j.s(' />');
_j.ns('<div');_j.s(' class="descriptions"');_j.s(' id="file_upload_description"');_j.s('>');
_j.ns('<p');_j.s('>Choose the file you want to import');
_j.ns('</p>');
_j.ns('<p');_j.s('>'+(Glyde.company_name));
_j.ns('will place all your items that contain valid ISBNs or UPCs into your collection');
_j.ns('</p>');
_j.ns('<p');_j.s('>Go to your organize page to put these items for sale');
_j.ns('</p>');
_j.ns('</div>');
_j.ns('<div');_j.s(' id="collection_upload_button"');_j.s('>');
_j.ns('</div>');
_j.ns('</form>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
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:function(source_element_id,position_above,dialog_opener){
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();
Glyde.Dialog.prototype.open.call(this,$(source_element_id),this._to_html(dialog_title,copy_link_panel_title),dialog_opener);
this._show_panel('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+'/invites/share_buy_box?return_to='+encodeURIComponent(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));
return;
}
this._send_share_email_request(this._split_email_string(emails));
},
_send_share_email_request:function(to_emails){
var request_params={
to_emails:to_emails.slice(0,this.MAX_EMAIL_RECIPIENTS).join(' '),
subject_text:this._strip_newlines(this._helper.email_subject()),
salutation:this._helper.email_salutation(),
farewell:this._helper.email_farewell(),
view_link:this._helper.email_view_link(),
user_text:this._email_message_input_value(),
composite_image_url:(this._helper.email_composite_image_url)?this._helper.email_composite_image_url():''
};
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('/share/send_invite_email',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=
(Browser.IE)?this.EMBED_HELP_IE:
(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(!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=
(Browser.IE)?this.COPY_LINK_HELP_IE:
(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(!Browser.IE){copy_link_button.hide();}
with($('copy_link_code')){
focus();
select();
}
},
_on_activate_facebook_button:function(){
var share_url=this._helper.share_url();
var query_params=$H({u:share_url,t:document.title}).toQueryString();
var window_params='toolbar=0,status=0,width=626,height=436';
window.open('http://www.facebook.com/sharer.php?'+query_params,'sharer',window_params);
},
_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';
},
_position_arrow:function(target,arrow){
arrow.style.left='12px';
}
});
ShareCollectionHelper=Class.create({
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;
},
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({
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({
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='http://'+location.host+'/products/'+glu.id+'/'+encodeURIComponent(glu.title.title_for_url());
},
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:'$'+PriceAdjuster.dollars_and_cents(lowest_price,true);
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){
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('Send Email');
_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+'\'s '+this._collection_type_label);
}
else{
_j.ns(Glyde.user.name+' 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+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+' 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.name+'\'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.name+'\'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;
_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:(this._is_owner&&this._is_store)?this._owner.name:Glyde.user.first_name;
_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+' 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+' 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();
if(price!=null){
_j.ns('<p');_j.s('>'+('"'+glu.title+'" is available for sale on <a href="'+this._glu_url+'">glyde.com</a> for as low as '+price+'.'));
_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();
};
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>');
}
_j.ns('<div');_j.s('>');
_j.ns('</div>');
return _j.v();
};
AbstractCollectionDataSource=Class.create({
DEFAULT_VERTICAL:null,
initialize:function(collection_id,collection_type){
this._collection_id=collection_id;
this._collection_type=collection_type;
},
sanitize_vertical:function(vertical_param){
return Glyde.glu.is_valid_vertical(vertical_param)?vertical_param:this.DEFAULT_VERTICAL;
},
find:function(options,on_success_callback){
this._abstract('find');
},
find_by_id:function(listing_id){
this._abstract('find_by_id');
},
refresh:function(callback,elapsed_time){
this._abstract('refresh');
},
refresh_adds_only:function(callback,elapsed_time){
this._abstract('refresh_adds_only');
},
remove:function(listings_for_delete,callback){
this._abstract('remove');
},
mark_to_market_vertical:function(callback,vertical){
this._abstract('mark_to_market_vertical');
},
_abstract:function(method_name){
alert('AbstractCollectionDataSource: #'+method_name+' is abstract');
}
});
ReadOnlyDataSource=Class.create(AbstractCollectionDataSource,{
MESSAGE_ITEMS_REMOVED:'read_only_data_source:listings_removed',
MESSAGE_ITEM_ADDED:'read_only_data_source:listing_added',
initialize:function(collection_id,collection_type){
this._collection_id=collection_id;
this._collection_type=collection_type;
this._items_cache={};
this._current_options={};
this._last_find_time=new Date();
},
find:function(options,on_success_callback){
this._find(options,on_success_callback);
},
find_by_id:function(item_id){
return this._items_cache[item_id];
},
refresh:function(callback,elapsed_time){
this._refresh(callback,elapsed_time);
},
refresh_adds_only:function(callback,elapsed_time){
this._find(this._current_options,callback,elapsed_time);
},
_find:function(options,on_success_callback,elapsed_time){
var now=new Date();
var et=elapsed_time||(now-this._last_find_time);
var opts={
client_on_complete:on_success_callback||Glyde.empty_function,
method:'get'
};
this._current_options=Object.clone(options);
opts=Object.clone(options);
opts.collection_id=this._collection_id;
opts.elapsed_time=et;
opts.view=this._collection_type;
if(this._is_collection()){
this._send_listing_paging_request(opts,on_success_callback);
}else{
this._send_glu_paging_request(opts,on_success_callback);
}
},
_send_listing_paging_request:function(opts,on_success_callback){
opts.onComplete=function(data){
this._last_find_time=new Date();
if(data.success){
var listings=data.listings;
var i=0;
for(i;i<listings.length;++i){
var list=listings[i];
var old_listing=this._items_cache[list.attrs.id];
if(old_listing&&old_listing.modified_attrs.length>0){
list.modified_attrs=old_listing.modified_attrs;
}
this._items_cache[list.attrs.id]=list;
}
on_success_callback(data);
}
}.bind(this);
return new ListingPagingRequest(opts);
},
_send_glu_paging_request:function(opts,on_success_callback){
opts.onComplete=function(data){
this._last_find_time=new Date();
if(data.success){
var glus=data.glus;
var i=0;
for(i;i<glus.length;++i){
var glu=glus[i];
this._items_cache[glu.id]=glu;
}
on_success_callback(data);
}
}.bind(this);
return new GluPagingRequest(opts);
},
_is_collection:function(){
return(this._collection_type=='collection'||
this._collection_type=='public_collection'||
this._collection_type=='inventory');
},
_refresh:function(callback,elapsed_time_secs){
this._send_refresh_request(callback,elapsed_time_secs);
},
_send_refresh_request:function(callback,elapsed_time_secs){
var local_callback=function(data){
this._on_refresh(data);
(callback||Glyde.empty_function)(data);
}.bind(this);
var options={
onComplete:local_callback,
collection_id:this._collection_id,
view:this._collection_type,
elapsed_time:elapsed_time_secs/1000,
vertical:this._current_options.vertical,
search_query:this._current_options.search_query,
queryTime:new Date()
};
new ListingRefreshRequest(options,this);
},
_on_refresh:function(data){
if(data.removed_items.length>0){
this._remove_after_refresh(data.removed_items);
}
if(data.added_items.length>0){
this._add_after_refresh(data.added_items);
}
},
_add_after_refresh:function(added_items_array){
for(var i=0;i<added_items_array.length;++i){
var item=added_items_array[i];
Glyde.notify.publish(this.MESSAGE_ITEM_ADDED,{item:item});
}
},
_remove_after_refresh:function(item_ids_for_delete){
this._remove_local(item_ids_for_delete);
Glyde.notify.publish(this.MESSAGE_ITEMS_REMOVED,
{item_ids:item_ids_for_delete});
},
_remove_local:function(item_ids_for_delete){
ids_arr=item_ids_for_delete;
for(var i=0;i<ids_arr.length;++i){
this._items_cache[ids_arr[i]]=null;
}
}
});
var ServerDataSource=Class.create(ReadOnlyDataSource,{
MESSAGE_MARK_TO_MARKET_VERTICAL:'server_data_source:mark_to_market_vertical',
initialize:function($super,collection_id,collection_type){
$super(collection_id,collection_type);
},
add:function(glu_id,condition_id,callback){
var on_complete=function(resp){
var json=resp.responseJSON;
if(json.success){
var listing=this._create_new_listings_from_data(json);
Glyde.notify.publish(this.MESSAGE_ITEM_ADDED,{item:listing});
(callback||Glyde.empty_function)(listing);
}else{
Glyde.page.handle_server_errors(json);
}
}.bind(this);
var options={
method:'post',
onComplete:on_complete,
parameters:{'sku[glu_id]':glu_id,
'sku[condition_id]':condition_id,
'vertical':this._current_options.vertical,
'search_query':this._current_options.search_query
}
};
new Ajax.Request('/listings/generic_create',options);
},
remove:function(listing_ids_for_delete,callback){
this._remove_local(listing_ids_for_delete);
this._remove_listings_remote(listing_ids_for_delete,callback);
},
bs_remove:function(listing_ids_for_delete,callback){
var listings=[];
var i=0;
for(i;i<listing_ids_for_delete.length;++i){
listings.push(this.find_by_id(listing_ids_for_delete[i]));
}
this._remove_local(listing_ids_for_delete);
this._bs_remove_listings_remote(listings,callback);
},
mark_to_market_vertical:function(callback,vertical){
Glyde.notify.publish(this.MESSAGE_MARK_TO_MARKET_VERTICAL,{});
this._mark_to_market_vertical_remote(callback,vertical);
},
current_page:function(){
return(this._current_options.offset/this._current_options.limit);
},
_remove_listings_remote:function(item_ids_for_delete,callback){
var options={
client_callback:(callback||Glyde.empty_function),
onComplete:this._on_complete_remove.bind(this),
method:'delete',
deleted_item_ids:item_ids_for_delete,
parameters:{ids:item_ids_for_delete.join(',')}
};
new Ajax.Request('/listings/dummy.js',options);
},
_on_complete_remove:function(resp,o){
Glyde.notify.publish(this.MESSAGE_ITEMS_REMOVED,
{'item_ids':resp.request.options.deleted_item_ids});
resp.request.options.client_callback(resp.responseJSON);
},
_create_new_listings_from_data:function(data){
var list=AbstractListingRequest.prototype._create_listing.call(this,data.listing);
list.__is_new=true;
return list;
},
_create_options:function(ids,attr,value,callback){
return{
method:'put',
parameters:this._create_params(ids,attr,value),
onComplete:function(t,o){
(callback||Glyde.empty_function)(t,o);
Loading.hide();
}
};
},
_create_params:function(ids,attr,value){
var params={ids:ids.join(',')};
if(Prototype.is_array(attr)){
for(var i=0;i<attr.length;++i){
params['listing['+attr[i]+']']=value[i];
}
}else{
params['listing['+attr+']']=value;
}
return params;
},
_update_listings_remote:function(ids,attr,value,callback){
Loading.show();
new Ajax.Request('/listings/update_multiple.js',
this._create_options(ids,attr,value,callback));
},
_mark_to_market_vertical_remote:function(callback,vertical){
var options={
method:'post',
parameters:{vertical:vertical||this._current_options.vertical||this.DEFAULT_VERTICAL},
onComplete:function(resp,o){
Loading.hide();
var json=resp.responseJSON;
if(json.success){
this._update_listings(json.listings);
(callback||Glyde.empty_function)(json);
}else{
Glyde.page.handle_server_errors(json);
}
}.bind(this)
};
Loading.show();
new Ajax.Request('/listings/mark_to_market_current_vertical.js',options);
},
_bs_remove_listings_remote:function(listings,callback){
var external_skus=[];
var item_ids_for_delete=[];
var i=0;
for(i;i<listings.length;++i){
e_sku=listings[i].attrs.bs_external_sku;
external_skus.push(base64_encode(e_sku));
item_ids_for_delete.push(listings[i].attrs.id);
}
var options={
client_callback:callback,
onComplete:this._on_complete_bs_remove.bind(this),
method:'delete',
deleted_item_ids:item_ids_for_delete,
parameters:{external_skus:external_skus.join(',')}
};
new Ajax.Request('/stores/'+g_collection.user_id+'/uploads/destroy_listing',
options);
},
_on_complete_bs_remove:function(resp,o){
var data=resp.responseJSON;
if(data.success){
var deleted_item_ids=resp.request.options.deleted_item_ids;
Glyde.notify.publish(this.MESSAGE_ITEMS_REMOVED,{item_ids:deleted_item_ids});
}
resp.request.options.client_callback(data);
}
});
var AbstractCollectionView=Class.create({
PAGE_SIZE:25,
initialize:function(container_id,collection_id){
this._container_id=container_id;
this._collection_id=collection_id;
this._data_source_options={};
this._data_source_options.offset=0;
this._data_source_options.limit=this.PAGE_SIZE;
this._initialize_options_with_globals();
this.data_source=this._create_data_source(g_collection.internal_collection_type);
this._data_source_options.vertical=this.data_source.DEFAULT_VERTICAL;
this._has_rendered=false;
},
_create_data_source:function(internal_collection_type){
var ds=null;
switch(internal_collection_type){
case'public_collection':
case'store':
ds=new ReadOnlyDataSource(g_collection.id,internal_collection_type);
break;
case'inventory':
case'collection':
ds=new ServerDataSource(g_collection.id,internal_collection_type);
break;
}
return ds;
},
_initialize_options_with_globals:function(){
if(g_collection.sort_by){
var sort_by_arr=g_collection.sort_by.split('&');
this._data_source_options.sort_by=sort_by_arr[0];
this._data_source_options.sort_direction=parseInt(sort_by_arr[1]);
}
},
show:function(){
this._showing=true;
},
hide:function(){
this._showing=false;
},
update:function(){
if(!this._has_rendered){
this.render();
}
},
render:function(data_source_options,callback){
if(!this._has_rendered)this._has_rendered=true;
this._data_source_options=data_source_options||this._data_source_options;
if(!this._data_source_callback){
this._data_source_callback=this._on_data_source_data.bind(this);
}
this.data_source.find(this._data_source_options,(callback||this._data_source_callback));
},
remove_listings:function(listings,callback){
alert('AbstractCollectionView.remove_listings is abstract');
},
_render_skeleton:function(count){
var html='';
if(count==0){
if(this._data_source_options.vertical==this.data_source.DEFAULT_VERTICAL){
if(!this._data_source_options.search_query){
html=this._render_no_listings_html();
}else{
html=this._render_no_listings_in_search_html();
}
}else{
html=this._render_no_listings_in_vertical_html();
}
}else{
html=this._render_skeleton_html();
}
$(this._container_id).innerHTML=html;
},
render_items:function(data){
var listings=data.listings;
if(data.total==0||$('no_listing_message_box')){
this._render_skeleton(data.total);
}
var listing_rows_box=this._get_listing_rows_box(data);
if(listing_rows_box)listing_rows_box.innerHTML=this._listings_to_html(listings);
},
_on_data_source_data:function(data){
if(data.success){
this.render_items(data);
}
},
next_page:function(){
if(this._showing){
var curr_offset=this._data_source_options.offset||0;
this._data_source_options.offset=Math.min(curr_offset+this.PAGE_SIZE,this.data_source.count());
this.render();
}
},
prev_page:function(){
if(this._showing){
var curr_offset=this._data_source_options.offset;
this._data_source_options.offset=Math.max(curr_offset-this.PAGE_SIZE,0);
this.render();
}
},
_get_listing_rows_box:function(data){
var listing_rows_box=$(this._container_id+'_listing_rows');
if(!listing_rows_box){
this._render_skeleton(data.total);
listing_rows_box=$(this._container_id+'_listing_rows');
}
return listing_rows_box;
},
_listing_render_func_name:function(){
alert('AbstractCollectionView._listing_render_func_name is abstract');
},
_listings_to_html:function(listings){
if(listings){
var html=[];
var i,listing,extra_class,len=listings.length;
for(i=0;i<len;++i){
listing=listings[i];
index_class=(i%2==0)?'even':'odd';
html.push(listing[this._listing_render_func_name()](index_class,this._last_update_time));
}
return html.join('');
}else{
return'';
}
},
_size_for_page:function(){
alert('AbstractCollectionView._size_for_page is abstract');
},
_is_wrong_search_query:function(data){
return(data.response.request.options.parameters.search_query!=this._data_source_options.search_query);
},
current_state:function(params){
return params;
},
restore_from_state:function(params){
return 1;
}
});
AbstractCollectionView.EVENT_RENDERED='abstract_collection_view: rendered';
AbstractCollectionView.prototype._render_no_listings_html=function(){
var s=[];
s.push('<div id="');s.push(this._container_id);s.push('_pages" class="listing_pages no_items">');
s.push('<div id="no_listing_message_box" class="no_listing_message_box">');
s.push('<p>');
s.push('You currently have no items in your collection.&nbsp;&nbsp;');
s.push('');s.push(this._render_add_item_directions());s.push('');
s.push('</p>');
s.push('</div>');
s.push('</div>');
return s.join('');
}
AbstractCollectionView.prototype._render_no_listings_in_search_html=function(){
var s=[];
s.push('<div id="');s.push(this._container_id);s.push('_pages" class="listing_pages no_items">');
s.push('<div id="no_listing_message_box" class="no_listing_message_box">');
s.push('<p>');
s.push('Your collection doesn\'t have any items matching <span style="font-style:italic">');s.push(this._data_source_options.search_query);s.push('</span>');
s.push('</p>');
s.push('</div>');
s.push('</div>');
return s.join('');
}
AbstractCollectionView.prototype._render_no_listings_in_vertical_html=function(){
var s=[];
s.push('<div id="');s.push(this._container_id);s.push('_pages" class="listing_pages no_items">');
s.push('<div id="no_listing_message_box" class="no_listing_message_box">');
s.push('<p>');
s.push('You currently have no ');s.push(this._data_source_options.vertical);s.push('.&nbsp;&nbsp;');
s.push('');s.push(this._render_add_item_directions());s.push('');
s.push('</p>');
s.push('</div>');
s.push('</div>');
return s.join('');
}
AbstractCollectionView.prototype._render_add_item_directions=function(){
var s=[];
s.push('To list them, either enter them individually (click on Add) or import your entire collection (click on Import).');
return s.join('');
}
var CollectionListView=Class.create(AbstractCollectionView,{
PAGE_SIZE:25,
PAGE_HEIGHT:400,
ROW_HEIGHT:16,
EVENT_SCROLL:'collection_list_view : scroll',
SCROLL_CONTAINER_ID:'list_view_pages_container',
initialize:function($super,container_id,collection_id,data_source){
$super(container_id,collection_id);
this._pages_are_dirty=true;
this._pending_fetches=[];
this._rendered_pages=[];
this._page_thresholds=[];
this._selected_listing_ids=[];
this._total=this.PAGE_SIZE;
this._limit=this.PAGE_SIZE;
this._offset=0;
this._cache_images_for_IE();
$(this._container_id).observe('click',this._click_handler.bindAsEventListener(this));
Glyde.notify.subscribe(this.EVENT_SCROLL,this._handle_list_scroll.bind(this));
Glyde.notify.subscribe(this.data_source.MESSAGE_ITEM_ADDED,
this._on_listing_added_removed.bind(this));
Glyde.notify.subscribe(this.data_source.MESSAGE_MARK_TO_MARKET_VERTICAL,
this._on_data_source_mark_to_market_vertical.bind(this));
Glyde.notify.subscribe(this.data_source.MESSAGE_ITEMS_REMOVED,
this._on_listing_added_removed.bind(this));
Glyde.notify.subscribe(SelectionManager.EVENT_SELECTION_CHANGED,
this._handle_selection_changed.bind(this));
Glyde.notify.subscribe(Glyde.page.page.controller.listing_dialog.EVENT_CLOSE,this._handle_listing_dialog_closed.bind(this));
},
_click_handler:function(e){
var target=$(e.target);
if(target.className=='info_image'&&!Glyde.is.empty_string(target.id)){
if(this._showing){
Collection.get_instance().listing_dialog.open(this.data_source.find_by_id(target.id.split('info_image_')[1]),e.element());
}
}
},
update:function(){
if(!$(this.SCROLL_CONTAINER_ID)){
this.render();
}else{
this._fetch_visible_pages();
}
},
render:function(data_source_options){
if(Glyde.page.is_user_bulk_seller()){
data_source_options.context='bulk_seller_list';
}else{
data_source_options.context='list';
}
this._find_from_data_source(data_source_options);
},
_is_new_query:function(query_hash){
var current_options=this._current_data_source_options||{};
if((query_hash.vertical!=current_options.vertical)||
(query_hash.limit!=current_options.limit)||
(query_hash.sort_by!=current_options.sort_by)||
(query_hash.sort_direction!=current_options.sort_direction)||
(query_hash.search_query!=current_options.search_query)){
return true;
}
return false;
},
_find_from_data_source:function(data_source_options){
this._data_source_options=data_source_options||this._data_source_options;
this._data_source_options.limit=this.PAGE_SIZE;
if(this._is_new_query(this._data_source_options)){
this._mark_pages_dirty();
}
this._current_data_source_options=Object.clone(this._data_source_options);
if(!this._data_source_callback){
this._data_source_callback=this._on_data_source_data.bind(this);
}
this.data_source.find(this._data_source_options,this._data_source_callback);
},
render_items:function(data){
var listings=data.modified_listings;
if(this._are_any_new(listings)||this._listings_removed){
this._set_current_request_data(data);
this._listings_removed=false;
this._fetch_visible_pages();
}else{
for(i=0;i<listings.length;++i){
listing_elem=$('listing_row_'+listings[i].attrs.id);
if(listing_elem)listing_elem.innerHTML=this._render_listing(listings[i],null,true);
}
this._highlight_modified_attributes(listings);
}
},
_render_listing:function(listing,extra_class,inner_only){
if(inner_only){
return Glyde.page.is_user_bulk_seller()?listing._to_bulk_seller_inner_html():listing._to_html_inner_html();
}else{
return listing[this._listing_render_func_name()](extra_class)
}
},
remove_listings:function(listing_ids,callback){
var num_completed=0;
var listing_effect_completed=function(){
if(callback){
num_completed++;
if(num_completed==listing_ids.length){
callback();
}
}
};
listing_ids.each(function(id){
var el=$('listing_row_'+id);
if(el){
new Effect.BlindUp(el,{duration:1.0,afterFinish:listing_effect_completed});
}else{
listing_effect_completed();
}
});
},
_are_any_new:function(listings){
var any_new=false;
for(var i=0;i<listings.length;++i){
if(listings[i].__is_new){
any_new=true;
break;
}
}
return any_new;
},
_on_data_source_mark_to_market_vertical:function(event_name,info){
if(!this._showing){
this.data_source._reset_page_cache();
}
this._rendered_pages=[];
this._page_thresholds=[];
},
_on_listing_added_removed:function(event_name,info){
if(!this._showing)return;
var old_total_pages=this._total_pages();
var total=this._total=this._total-(event_name==this.data_source.MESSAGE_ITEMS_REMOVED?info.item_ids.length:0);
var req_limit=this._limit;
var total_pages=total?Math.ceil(total/req_limit):0;
var last_page_total=total%req_limit;
var rendered_pages_length=this._rendered_pages.length-1;
if(total==0){
}else if(old_total_pages<total_pages){
this._set_container_height(total);
this._mark_pages_dirty();
}else if(old_total_pages>total_pages){
this._set_container_height(total);
this._mark_pages_dirty();
}else{
this._set_container_height(total);
this._mark_pages_dirty();
}
if(event_name==this.data_source.MESSAGE_ITEMS_REMOVED){
this._listings_removed=true;
}
},
_set_container_height:function(total){
var elem=$(this._container_id+'_pages');
if(elem){
elem.style.height=this._total_height(total)+'px';
}
},
_set_current_request_data:function(data){
this._total=data.total;
if(data.response){
this._offset=data.response.request.options.parameters.offset;
this._limit=data.response.request.options.parameters.limit;
}
},
_is_last_page:function(page_num){
var is_last_page=false;
if((this._total%this._limit)==0){
is_last_page=(page_num==this._total_pages());
}else{
is_last_page=(page_num==(this._total_pages()-1));
}
return is_last_page;
},
_render_page_listings:function(data){
var listings=data.listings;
this._set_current_request_data(data);
var page_num=this._response_page_num(data);
if((data.total==0&&page_num==0)||$('no_listing_message_box')||
this._pages_are_dirty){
this._render_skeleton(data.total);
}
var listing_rows_box=this._get_page_listing_rows_box(page_num,data.total);
console.log('rendering page '+page_num+' found box ',listing_rows_box);
if(listing_rows_box){
listing_rows_box.innerHTML=this._listings_to_html(listings);
if(this._is_last_page(page_num)){
var last_page_total=this._total%this._limit||this._limit;
listing_rows_box.style.height=(last_page_total*this.ROW_HEIGHT)+'px';
}
if(this._scroll_into_view){
$(this.SCROLL_CONTAINER_ID).scrollTop=this._scroll_into_view;
this._scroll_into_view=null;
}
this._rendered_pages[page_num]=true;
var len=listings.length;
for(var i=0;i<len;++i){
if(this._selected_listing_ids.include(listings[i].attrs.id)){
listings[i].select();
}
}
this._pages_are_dirty=false;
}
this._update_sort_buttons(this._data_source_options.sort_by);
this._highlight_modified_attributes(listings);
this._nudge_IE_for_catalog_bottom();
Glyde.notify.publish(AbstractCollectionView.EVENT_RENDERED,data);
},
_listings_to_html:function(listings,offset,limit){
var offset=this._offset;
var limit=this._limit;
if(listings){
var html=[];
var i,listing,len=listings.length;;
for(i=0,x=offset;i<len;++i,++x){
listing=listings[i];
index_class=(x%2==0)?'even':'odd';
html.push(this._render_listing(listing,index_class));
}
return html.join('');
}else{
return'';
}
},
_render_skeleton_html:function(){
if(Glyde.page.is_user_bulk_seller()){
return this._render_skeleton_bulk_seller_html();
}else{
return this._render_skeleton_normal_html();
}
},
_total_height:function(total){
var tot=total||this._total;
return(this._total*this.ROW_HEIGHT);
},
_total_pages:function(){
return(this._total?Math.ceil(this._total/this._limit):0);
},
_render_pages:function(){
var s=[];
var req_limit=this._limit;
var total_pages=this._total_pages();
var last_page_total=this._total%req_limit||req_limit;
this._rendered_pages=new Array(total_pages+1);
this._page_thresholds=new Array(total_pages+1);
for(var page_num=0;page_num<total_pages;++page_num){
this._page_thresholds[page_num]=page_num*this.PAGE_HEIGHT;
var is_last_page=(page_num==total_pages-1);
style=is_last_page&&last_page_total<req_limit?'style="height:'+last_page_total*this.ROW_HEIGHT+'px;"':'';
s.push(this._render_page_html(page_num,style));
}
return s.join('');
},
_get_page_listing_rows_box:function(page_num,count){
var listing_rows_box=$(this._container_id+'_listing_rows_page_'+page_num);
var container=$(this._container_id+'_pages');
if(!container||container.hasClassName('no_items')){
this._render_skeleton(count);
}
listing_rows_box=$(this._container_id+'_listing_rows_page_'+page_num);
if(!listing_rows_box){
this._create_page_container(page_num);
listing_rows_box=$(this._container_id+'_listing_rows_page_'+page_num);
}
return listing_rows_box;
},
_create_page_container:function(page_num){
var total_pages=this._total_pages();
var is_last_page=(page_num==total_pages-1);
var style='';
if(is_last_page){
var last_page_total=this._total%this._limit||this._limit;
style=" height:"+last_page_total*this.ROW_HEIGHT+"px;";
}
var container=$(this._container_id+'_pages');
container.insert(this._render_page_html(page_num,style));
},
_fetch_page:function(page_num){
if(this._showing){
if(this._pending_fetches[page_num])return;
this._pending_fetches[page_num]=true;
var total=this._total||0;
this._data_source_options.offset=Math.min(page_num*this.PAGE_SIZE,
total);
this._find_from_data_source();
}
},
_fetch_visible_pages:function(dont_set_scroll_into_view){
var pages_showing=this._visible_pages(this.SCROLL_CONTAINER_ID);
var scroll_container=$(this.SCROLL_CONTAINER_ID);
var total=this._total||1;
for(var i=0;i<pages_showing.length;++i){
var page_num=pages_showing[i];
if((page_num*this.PAGE_SIZE)<total){
if(!dont_set_scroll_into_view){
this._scroll_into_view=scroll_container?scroll_container.scrollTop:null;
}
this._fetch_page(page_num);
}
}
},
_mark_pages_dirty:function(){
this._pages_are_dirty=true;
this._pending_fetches=[];
this._rendered_pages=[];
this._page_thresholds=[];
},
_update_sort_buttons:function(name){
if(this._current_sorted_by==name&&
this._data_source_options.sort_direction==this._current_sort_direction){
this._update_sort_arrow(name);
return;
}
this._revert_all_sort_arrows();
this._current_sorted_by=name;
this._current_sort_direction=this._data_source_options.sort_direction;
this._update_sort_arrow(name);
},
_update_sort_arrow:function(name){
var arrow=$(name+'_sort_arrow');
if(arrow){
if(this.data_source._current_options.sort_direction==1){
arrow.className.replace(/ down/,'');
arrow.className+=' up';
}else{
arrow.className.replace(/ up/,'');
arrow.className+=' down';
}
var div=arrow.parentNode;
div.className=div.className.replace(' selected','');
div.className+=' selected';
}
},
_revert_all_sort_arrows:function(){
['status','title','type','comps','sell','price','condition'].each(function(s){
var arrow=$(s+'_sort_arrow');
if(arrow){
arrow.className=arrow.className.replace(/ up| down/,'');
var div=arrow.parentNode;
div.className=div.className.replace(' selected','');
}
});
},
_response_page_num:function(data){
var opts=data.response.request.options.parameters;
return Math.ceil(opts.offset/opts.limit);
},
_on_data_source_data:function(data){
var page_num=this._response_page_num(data);
this._pending_fetches[page_num]=false;
if(this._is_wrong_search_query(data))return;
if(data.success){
this._render_page_listings(data);
}
if(data.listings.length>0){
this._size_for_page();
}
},
_highlight_modified_attributes:function(listings){
var i=0,listing;
var len=listings.length;
for(i;i<len;++i){
listing=listings[i];
if(listing.__is_new&&!listing.__been_pulsed){
if(this._pulse_listing_row(listing.attrs.id)){
listing.__been_pulsed=true;
listing.__is_new=false;
}
}else{
row=$('listing_row_'+listing.attrs.id);
var color=null;
if(row){
if(row.className.indexOf(' selected')!=-1){
color='#0000F9'
}
}
for(var x=0;x<listing.modified_attrs.length;++x){
var attr=listing.modified_attrs[x];
lid=listing.attrs.id;
switch(attr){
case'is_for_sale':this._pulse_listing_row(lid);break;
case'condition_id':(new fx.FontColorPulse('cond_a_'+lid)).to_color(color);break;
case'cents':(new fx.FontColorPulse('price_a_'+lid)).to_color(color);break;
case'market_price':(new fx.FontColorPulse('release_comp_'+lid)).to_color(color);break;
case'bs_original_price_cents':(new fx.FontColorPulse('bs_orig_price_a_'+lid)).to_color(color);break;
}
}
}
this._reset_modified_attrs(listing);
}
},
_reset_modified_attrs:function(listing){
listing.modified_attrs=[];
var cached_listing=this.data_source.find_by_id(listing.attrs.id);
if(cached_listing)cached_listing.modified_attrs=[];
},
_pulse_listing_row:function(id){
row=$('listing_row_'+id);
if(row){
var color=null;
if(row.className.indexOf(' selected')!=-1){
color='#0000F9'
}
var condition_link=row.select(".cond_col a")[0];
var price_link=row.select(".price_col a")[0];
(new fx.FontColorPulse(row)).to_color(color);
(new fx.FontColorPulse(condition_link)).to_color(color);
if(price_link){(new fx.FontColorPulse(price_link)).to_color(color);}
return true;
}
return false;
},
_listing_render_func_name:function(){
return'to_html';
},
_current_request_total_pages:function(){
var total=this._total;
var limit=this._limit;
var total_pages=Math.ceil(total/limit);
var last_page_total_listings=total%limit;
return total_pages;
},
_handle_selection_changed:function(event_name,info){
this._selected_listing_ids=info.items.clone();
},
_handle_list_scroll:function(event_name,event){
event=Event.get(event);
var pages_showing=this._visible_pages(this.SCROLL_CONTAINER_ID);
var last_page_num=this._current_request_total_pages();
for(var i=0;i<pages_showing.length;++i){
var page_num=pages_showing[i];
if(page_num>last_page_num-1){
continue;
}
this._fetch_page(page_num);
}
Glyde.notify.publish(GlydeSelect.EVENT_ELEMENT_SCROLL,event);
},
_set_inner_height:function(){
var inner=$(this._container_id+'_pages');
var height=parseInt(inner.getHeight());
var new_height=this._total_height();
if(height!=new_height){
var total_height=this._total_height();
if(!isNaN(total_height)){
var elem=$(this._container_id+'_pages');
elem.style.height=total_height+'px';
}
}
},
_visible_pages:function(scroll_container_id){
this._set_inner_height();
var scroll_container=$(scroll_container_id);
if(!scroll_container)return[0];
var scroll_top=scroll_container.scrollTop;
var height=parseInt(scroll_container.getStyle('height'));
var scroll_bottom=scroll_top+height;
var start_page=Math.floor(scroll_top/this.PAGE_HEIGHT);
var end_page=Math.floor(scroll_bottom/this.PAGE_HEIGHT);
var pages_needing_render=[];
for(var page_num=start_page;page_num<=end_page;++page_num){
if(!this._rendered_pages[page_num]){
pages_needing_render.push(page_num);
}
}
return pages_needing_render;
},
_size_for_page:function(){
var viewport=$(this._container_id+'_pages_container');
if(viewport){
var new_height=this._viewport_height();
viewport.style.height=new_height+'px';
this._fetch_visible_pages(true);
}
},
_viewport_height:function(){
var collections_box_height=Browser.IE6?parseInt($('collections_box').style.height):$('collections_box').getHeight();
return(collections_box_height-18);
},
_cache_images_for_IE:function(){
if(Browser.IE){
this._create_cached_img_tag('images/information.png');
this._create_cached_img_tag('images/Arrows/up_down_arrows.gif');
}
},
_create_cached_img_tag:function(src){
var img=document.createElement('img');
img.className='offscreen';
img.src=src;
document.body.appendChild(img);
},
_nudge_IE_for_catalog_bottom:function(){
if(Browser.IE){
document.getElementById('catalog_bottom').style.bottom="-1px";
document.getElementById('catalog_bottom').style.bottom="-2px";
}
},
_handle_listing_dialog_closed:function(event_name,info){
if(this._showing){
var listing=this.data_source.find_by_id(info.listing_id);
if(!listing)console.log('listing not found for '+info.listing_id);
var is_for_sale=info.listing_is_for_sale;
if(!is_for_sale){
if(listing)listing.sell_select.select(0);
}else{
if(listing)listing.sell_select.select(1);
}
}
}
});
CollectionListView.prototype._render_skeleton_normal_html=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="box"');_j.s(' id="list"');_j.s('>');
_j.ns('<div');_j.s(' class="row"');_j.s(' id="header_row"');_j.s('>');
_j.ns('<div');_j.s(' class="select_col col"');_j.s('>');
_j.ns('<div');_j.s(' class="checkbox_button_box"');_j.s('>');
_j.ns('&nbsp;');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="title_col col"');_j.s(' title="'+("sort by title")+'"');_j.s(' onclick="'+("Glyde.notify.publish('collection:sorted', {by:'title'})")+'"');_j.s(' onmouseover="'+("$(this).addClassName('hover')")+'"');_j.s(' onmouseout="'+("$(this).removeClassName('hover')")+'"');_j.s('>');
_j.ns('<span');_j.s(' id="image_toggle"');_j.s('>Title');
_j.ns('</span>');
_j.ns('<div');_j.s(' class="sort_arrow"');_j.s(' id="title_sort_arrow"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="creator_col col"');_j.s(' title="'+("sort by creator")+'"');_j.s(' onclick="'+("Glyde.notify.publish('collection:sorted', {by:'creator'})")+'"');_j.s(' onmouseover="'+("$(this).addClassName('hover')")+'"');_j.s(' onmouseout="'+("$(this).removeClassName('hover')")+'"');_j.s('>');
_j.ns('<span');_j.s(' id="image_toggle"');_j.s('>Creator');
_j.ns('</span>');
_j.ns('<div');_j.s(' class="sort_arrow"');_j.s(' id="creator_sort_arrow"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="type_col col"');_j.s(' title="'+('sort by type')+'"');_j.s(' onclick="'+("Glyde.notify.publish('collection:sorted', {by:'type'})")+'"');_j.s(' onmouseover="'+("$(this).addClassName('hover')")+'"');_j.s(' onmouseout="'+("$(this).removeClassName('hover')")+'"');_j.s('>');
_j.ns('<div');_j.s(' class="sort"');_j.s(' id="type_sort"');_j.s('>Type');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="sort_arrow"');_j.s(' id="type_sort_arrow"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="item_type_col col"');_j.s(' title="'+("sort by subtype")+'"');_j.s(' onclick="'+("Glyde.notify.publish('collection:sorted', {by:'item_type'})")+'"');_j.s(' onmouseover="'+("$(this).addClassName('hover')")+'"');_j.s(' onmouseout="'+("$(this).removeClassName('hover')")+'"');_j.s('>');
_j.ns('<span');_j.s(' id="image_toggle"');_j.s('>Subtype');
_j.ns('</span>');
_j.ns('<div');_j.s(' class="sort_arrow"');_j.s(' id="item_type_sort_arrow"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="sell_col col"');_j.s(' title="'+('sort by status')+'"');_j.s(' onclick="'+("Glyde.notify.publish('collection:sorted', {by:'status'})")+'"');_j.s(' onmouseover="'+("$(this).addClassName('hover')")+'"');_j.s(' onmouseout="'+("$(this).removeClassName('hover')")+'"');_j.s('>');
_j.ns('<span');_j.s(' class="sort"');_j.s(' id="status_sort"');_j.s('>Status');
_j.ns('</span>');
_j.ns('<div');_j.s(' class="sort_arrow"');_j.s(' id="status_sort_arrow"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="cond_col col"');_j.s(' title="'+('sort by condition')+'"');_j.s(' onclick="'+("Glyde.notify.publish('collection:sorted', {by:'condition'})")+'"');_j.s(' onmouseover="'+("$(this).addClassName('hover')")+'"');_j.s(' onmouseout="'+("$(this).removeClassName('hover')")+'"');_j.s('>');
_j.ns('<div');_j.s(' class="sort actionable"');_j.s(' id="condition_sort"');_j.s('>Condition');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="sort_arrow"');_j.s(' id="condition_sort_arrow"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="comps_col col"');_j.s(' title="'+('sort by market price')+'"');_j.s('>');
_j.ns('<div');_j.s(' class="sort"');_j.s(' id="comps_sort"');_j.s('>Market Price');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="sort_arrow"');_j.s(' id="comps_sort_arrow"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="price_col col"');_j.s(' title="'+("sort by price")+'"');_j.s(' onclick="'+("Glyde.notify.publish('collection:sorted', {by:'price'});")+'"');_j.s(' onmouseover="'+("$(this).addClassName('hover')")+'"');_j.s(' onmouseout="'+("$(this).removeClassName('hover')")+'"');_j.s('>');
_j.ns('<div');_j.s(' class="sort"');_j.s(' id="price_sort"');_j.s('>Your Price');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="sort_arrow"');_j.s(' id="price_sort_arrow"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns(this._render_page_container());
_j.ns('</div>');
return _j.v();
};
CollectionListView.prototype._render_skeleton_bulk_seller_html=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="box"');_j.s(' id="list"');_j.s('>');
_j.ns('<div');_j.s(' class="row"');_j.s(' id="header_row"');_j.s('>');
_j.ns('<div');_j.s(' class="select_col col"');_j.s('>');
_j.ns('<div');_j.s(' class="checkbox_button_box"');_j.s('>');
_j.ns('&nbsp;');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="bs_external_sku_col col"');_j.s(' title="'+("sort by your sku")+'"');_j.s(' onclick="'+("Glyde.notify.publish('collection:sorted', {by:'bs_external_sku'})")+'"');_j.s(' onmouseover="'+("$(this).addClassName('hover')")+'"');_j.s(' onmouseout="'+("$(this).removeClassName('hover')")+'"');_j.s('>');
_j.ns('<span');_j.s(' id="image_toggle"');_j.s('>SKU');
_j.ns('</span>');
_j.ns('<div');_j.s(' class="sort_arrow"');_j.s(' id="bs_external_sku_sort_arrow"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="upc_or_isbn_col col"');_j.s(' title="'+("sort by upc/isbn")+'"');_j.s(' onclick="'+("Glyde.notify.publish('collection:sorted', {by:'upc_or_isbn'})")+'"');_j.s(' onmouseover="'+("$(this).addClassName('hover')")+'"');_j.s(' onmouseout="'+("$(this).removeClassName('hover')")+'"');_j.s('>');
_j.ns('<span');_j.s(' id="image_toggle"');_j.s('>UPC/ISBN');
_j.ns('</span>');
_j.ns('<div');_j.s(' class="sort_arrow"');_j.s(' id="upc_or_isbn_sort_arrow"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="title_col col"');_j.s(' title="'+("sort by title")+'"');_j.s(' onclick="'+("Glyde.notify.publish('collection:sorted', {by:'title'})")+'"');_j.s(' onmouseover="'+("$(this).addClassName('hover')")+'"');_j.s(' onmouseout="'+("$(this).removeClassName('hover')")+'"');_j.s('>');
_j.ns('<span');_j.s(' id="image_toggle"');_j.s('>Title');
_j.ns('</span>');
_j.ns('<div');_j.s(' class="sort_arrow"');_j.s(' id="title_sort_arrow"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="type_col col"');_j.s(' title="'+('sort by type')+'"');_j.s(' onclick="'+("Glyde.notify.publish('collection:sorted', {by:'type'})")+'"');_j.s(' onmouseover="'+("$(this).addClassName('hover')")+'"');_j.s(' onmouseout="'+("$(this).removeClassName('hover')")+'"');_j.s('>');
_j.ns('<div');_j.s(' class="sort"');_j.s(' id="type_sort"');_j.s('>Type');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="sort_arrow"');_j.s(' id="type_sort_arrow"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="bs_date_added_col col"');_j.s(' title="'+("sort by date added")+'"');_j.s(' onclick="'+("Glyde.notify.publish('collection:sorted', {by:'bs_date_added'});")+'"');_j.s(' onmouseover="'+("$(this).addClassName('hover')")+'"');_j.s(' onmouseout="'+("$(this).removeClassName('hover')")+'"');_j.s('>');
_j.ns('<div');_j.s(' class="sort"');_j.s(' id="price_sort"');_j.s('>Date Added');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="sort_arrow"');_j.s(' id="bs_date_added_sort_arrow"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="cond_col col"');_j.s(' title="'+('sort by condition')+'"');_j.s(' onclick="'+("Glyde.notify.publish('collection:sorted', {by:'condition'})")+'"');_j.s(' onmouseover="'+("$(this).addClassName('hover')")+'"');_j.s(' onmouseout="'+("$(this).removeClassName('hover')")+'"');_j.s('>');
_j.ns('<div');_j.s(' class="sort actionable"');_j.s(' id="condition_sort"');_j.s('>Condition');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="sort_arrow"');_j.s(' id="condition_sort_arrow"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="price_col col"');_j.s(' title="'+("sort by price")+'"');_j.s(' onclick="'+("Glyde.notify.publish('collection:sorted', {by:'price'});")+'"');_j.s(' onmouseover="'+("$(this).addClassName('hover')")+'"');_j.s(' onmouseout="'+("$(this).removeClassName('hover')")+'"');_j.s('>');
_j.ns('<div');_j.s(' class="sort"');_j.s(' id="price_sort"');_j.s('>Listed Price');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="sort_arrow"');_j.s(' id="price_sort_arrow"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="bs_orig_price_col col"');_j.s(' title="'+("sort by original price")+'"');_j.s(' onclick="'+("Glyde.notify.publish('collection:sorted', {by:'bs_orig_price'});")+'"');_j.s(' onmouseover="'+("$(this).addClassName('hover')")+'"');_j.s(' onmouseout="'+("$(this).removeClassName('hover')")+'"');_j.s('>');
_j.ns('<div');_j.s(' class="sort"');_j.s(' id="price_sort"');_j.s('>Uploaded Price');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="sort_arrow"');_j.s(' id="bs_orig_price_sort_arrow"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="bs_low_price_col col"');_j.s('>');
_j.ns('<div');_j.s(' class="sort"');_j.s(' id="bs_low_price_sort"');_j.s('>Low Price');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="sort_arrow"');_j.s(' id="bs_low_price_sort_arrow"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="quantity_col col"');_j.s('>');
_j.ns('<span');_j.s(' class="sort"');_j.s(' id="quantity_sort"');_j.s('>Quantity');
_j.ns('</span>');
_j.ns('<div');_j.s(' class="sort_arrow"');_j.s(' id="quantity_sort_arrow"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns(this._render_page_container());
_j.ns('</div>');
return _j.v();
};
CollectionListView.prototype._render_page_html=function(page_num,extra_style){
var _j=new Jaml();
var top=page_num*this.PAGE_SIZE*this.ROW_HEIGHT;
console.log('extra style = '+extra_style);
_j.ns('<div');_j.s(' class="listing_rows_page '+(extra_style)+'"');_j.s(' id="'+(this._container_id+'_listing_rows_page_'+page_num)+'"');_j.s(' style="'+('top:'+top+'px; '+extra_style)+'"');_j.s('>');
_j.ns('<div');_j.s(' style="'+('margin-top:'+Math.round(this.PAGE_HEIGHT/2)+'px; text-align:center')+'"');_j.s('>');
_j.ns('Loading');
_j.ns('<br');_j.s(' />');
_j.ns('<img');_j.s(' src="'+(Glyde.image.fully_qualified_url('images/wait.gif'))+'"');_j.s(' />');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
CollectionListView.prototype._render_page_container=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="listing_pages_container"');_j.s(' id="'+(this._container_id+'_pages_container')+'"');_j.s(' onscroll="'+("Glyde.notify.publish(CollectionListView.prototype.EVENT_SCROLL, event)")+'"');_j.s(' style="'+("height:"+this._viewport_height()+'px')+'"');_j.s('>');
_j.ns('<div');_j.s(' class="listing_pages"');_j.s(' id="'+(this._container_id+'_pages')+'"');_j.s(' style="'+("height:"+this._total_height()+'px')+'"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
var CollectionBookshelfView=Class.create(AbstractCollectionView,{
ROW_HEIGHT:180,
ITEMS_PER_ROW:7,
ITEMS_PER_ROW_FACEBOOK:5,
initialize:function($super,container_id,collection_id){
$super(container_id,collection_id);
$(this._container_id).observe('click',this._click_handler.bindAsEventListener(this));
this._clear_restore_state_vars();
Glyde.notify.subscribe(Collection.get_instance().listing_dialog.EVENT_OPEN,this._handle_item_dialog_open.bind(this));
Glyde.notify.subscribe(Collection.get_instance().listing_dialog.EVENT_CLOSE,this._handle_item_dialog_close.bind(this));
Glyde.notify.subscribe(GridScrollWidget.EVENT_LISTINGS_LOADED,this._handle_items_loaded.bind(this));
},
show:function($super){
$('delete').undisplay();
$super();
},
hide:function($super){
$('delete').display();
$super();
},
_handle_item_dialog_open:function(event_name,info){
if(this._showing){
this.grid_scroll.enable_paging();
}
this._item_dialog_open=true;
this._restore_item_id=info.item_id;
Glyde.page.end_backable_action();
},
_handle_item_dialog_close:function(event_name,info){
this._item_dialog_open=false;
Glyde.page.end_backable_action();
},
_handle_items_loaded:function(event_name,info){
if(this._item_dialog_open){
Collection.get_instance().listing_dialog.close();
}
if(this._restore_item_dialog_open){
this._open_item_dialog(this._restore_item_id,
this._restore_item_dialog_to_buy_now);
}
if(this._item_offset_on_render==null){
this._restore_item_id=info.first_item_id;
}
this._restore_current_page=info.current_page;
this._clear_restore_state_vars();
if(info.data)Glyde.notify.publish(AbstractCollectionView.EVENT_RENDERED,info.data);
},
render:function($super,data_source_options,callback){
this._data_source_options=data_source_options||this._data_source_options;
this._data_source_options.context='bookshelf';
var dso=this._data_source_options;
if(this._restore_item_id&&this._restoring_from_state){
this._send_item_offset_request(dso,callback);
this._restoring_from_state=false;
}else{
this._render();
}
},
_render:function(){
this._size_for_page(true);
var func=function(){this.render_items({});}.bind(this);
setTimeout(func,100);
},
_send_item_offset_request:function(dso,callback){
var opts={
method:'get',
parameters:{
'collection_id':this._collection_id,
'search_query':dso.search_query,
'sort_by':dso.sort_by,
'sort_direction':dso.sort_direction,
'vertical':dso.vertical
},
onComplete:function(resp,o){
var json=resp.responseJSON;
if(json.success){
this._item_offset_on_render=json.offset;
}
this._render();
}.bind(this)
};
new Ajax.Request('/listings/'+this._restore_item_id+'/get_offset.js',
opts);
},
render_items:function(data){
if(data.modified_listings&&data.modified_listings.length==0)return;
this._render_skeleton();
if($('grid_scroll')&&this._rows){
var start_page=0;
if(data.modified_listings){
this._item_offset_on_render=this.current_item_offset();
}
if(this._item_offset_on_render){
start_page=Math.floor(this._item_offset_on_render/(this._items_per_row()*this._rows));
}else if(this._restore_current_page&&Glyde.page.is_async_loading()){
start_page=this._restore_current_page;
this._restore_current_page=null;
}
this.grid_scroll=this._create_scroll_widget(start_page);
}
this._size_for_page();
},
_create_scroll_widget:function(start_page){
return new GridScrollWidget($('grid_scroll'),this,this._rows*this._items_per_row(),start_page);
},
_clear_restore_state_vars:function(){
this._restore_item_dialog_open=this._item_offset_on_render=null;
this._restore_item_dialog_to_buy_now=null;
},
current_item_offset:function(){
if(this.grid_scroll){
return this.grid_scroll.current_page*this._items_per_row()*this._rows;
}
return 0;
},
remove_listings:function(listing_ids,callback){
},
_open_item_dialog:function(item_id,show_buy_now){
Collection.get_instance().listing_dialog.open(this.data_source.find_by_id(item_id),$('item_img_'+item_id),(show_buy_now?'buy_now':null));
},
_click_handler:function(e){
if(e.element().className=='item_img'){
if(this._showing){
this.grid_scroll.disable_paging();
this._open_item_dialog(e.element().id.split('item_img_')[1]);
}
}
},
current_state:function($super,params){
params=$super(params);
if(this._item_dialog_open){
if(this._restore_item_id){
params.item=this._restore_item_id;
}
params.open=true;
}
params.page=this._restore_current_page;
return params;
},
restore_from_state:function($super,params){
$super(params);
if(!isNaN(parseInt(params.page,10))){
this._restore_current_page=parseInt(params.page,10);
}
this._restore_item_id=parseInt(params.item,10);
this._restore_item_dialog_open=params.open;
this._restore_item_dialog_to_buy_now=params.buy_now!=null;
this._restoring_from_state=true;
var async_req_count=1;
if(this._restore_item_dialog_open)async_req_count++;
if(!isNaN(this._restore_item_id))async_req_count++;
return async_req_count;
},
_on_mouseover:function(e){
var elem=e.element();
if(elem.id.indexOf('item_img_')!=-1){
if(this._hovered_item_id){
var el=$(this._hovered_item_id);
if(el)el.removeClassName('hover');
}
elem.addClassName('hover');
this._hovered_item_id=elem.id;
}
if(elem.className.indexOf('info_image_wrapper')!=-1){
$(elem.parentNode).addClassName('hover');
}
if(elem.id.indexOf('info_image_')!=-1){
$($(elem.parentNode).parentNode).addClassName('hover');
}
},
_on_mouseout:function(e){
if(e.element().id.indexOf('item_img_')!=-1){
e.element().removeClassName('hover');
}
if(e.element().className.indexOf('info_image_wrapper')!=-1){
$(e.element().parentNode).removeClassName('hover');
}
},
_item_render_func_name:function(){
return'to_grid';
},
_rows_for_container_size:function(){
var collections_box_height=$('collections_box').getHeight();
return Math.floor((collections_box_height-8)/this.ROW_HEIGHT);
},
_items_per_row:function(){
return Glyde.page.is_facebook()?this.ITEMS_PER_ROW_FACEBOOK:this.ITEMS_PER_ROW;
},
_size_for_page:function(no_render){
if(!$('grid_scroll')){
return;
}
if(this._rows_for_container_size()!=this._rows){
if(this._item_dialog_open){
Collection.get_instance().listing_dialog.close();
}
this._item_offset_on_render=this._item_offset_on_render||this.current_item_offset();
this._rows=this._rows_for_container_size();
if(!no_render)this.render();
}
var new_height=this._rows*this.ROW_HEIGHT+8;
$('grid_scroll').style.height=new_height+'px';
var padding=($('collections_box').getHeight()-new_height)/2;
$('grid_scroll').style.padding=padding+'px 0';
}
});
CollectionBookshelfView.prototype._render_skeleton_html=function(){
var s=[];
s.push('<div id="grid_scroll"></div>');
return s.join('');
}
var StoreView=Class.create(CollectionBookshelfView,{
initialize:function($super,container_id,storefront_id,is_charity_store){
$super(container_id,storefront_id);
this._storefront_id=storefront_id;
this._is_charity_store=is_charity_store;
},
render_items:function(data){
this._render_skeleton();
if($('grid_scroll')&&this._rows){
var start_page=0;
if(data.modified_listings){
this._item_offset_on_render=this.current_item_offset();
}
if(this._item_offset_on_render){
start_page=Math.floor(this._item_offset_on_render/(this._items_per_row()*this._rows));
}else if(this._restore_current_page&&Glyde.page.is_async_loading()){
start_page=this._restore_current_page;
}
this.grid_scroll=
new GluGridScrollWidget($('grid_scroll'),
this,this._rows*this._items_per_row(),
start_page,this._storefront_id,
this._is_charity_store);
}
this._size_for_page();
},
_send_item_offset_request:function(dso,callback){
console.log('stores offset');
var opts={
method:'get',
parameters:{
'glu_id':this._restore_item_id,
'storefront_id':this._storefront_id,
'search_query':dso.search_query,
'sort':dso.sort_by,
'sort_direction':dso.sort_direction,
'category':dso.category,
'vertical':dso.vertical
},
onComplete:function(resp,o){
var json=resp.responseJSON;
if(json.success){
this._item_offset_on_render=json.offset;
}
this._render();
}.bind(this)
};
new Ajax.Request('/stores/get_offset.js',
opts);
},
_open_item_dialog:function(item_id,show_buy_now){
Collection.get_instance().listing_dialog.open(this.data_source.find_by_id(item_id),$('item_img_'+item_id),this._storefront_id);
},
_create_scroll_widget:function(start_page){
return new GluGridScrollWidget($('grid_scroll'),this,this._rows*this._items_per_row(),start_page);
}
});
var PagingRequest=Class.create({
initialize:function(url,options){
this._url=url;
this._options=options||{};
this._ajax_request=null;
this._response=null;
this._run(options);
},
_run:function(options){
this._response=null;
this._options=Object.clone(options);
if(this._options.onComplete){
this._options.__client_on_complete=this._options.onComplete;
}
var local_on_complete=function(resp,o){
this._response=resp;
(this._options.__client_on_complete||Glyde.empty_function)(resp,o);
Loading.hide();
};
this._options.onComplete=local_on_complete.bind(this);
Loading.show();
this._ajax_request=new Ajax.Request(this._url,this._options);
}
});
var GluPagingRequest=Class.create(PagingRequest,{
initialize:function($super,options){
$super("/stores/paging.js",options);
},
_run:function($super,options,on_complete){
var request_options={
client_on_complete:options.onComplete||Glyde.empty_function,
method:'get',
parameters:{
storefront_id:options.collection_id,
offset:options.offset,
limit:options.limit,
vertical:options.vertical,
search_query:options.search_query,
sort:options.sort_by,
category:options.category,
sort_direction:options.sort_direction
},
onComplete:this._handle_response.bind(this)
};
$super(request_options);
},
_handle_response:function(resp,o){
var opts=resp.request.options;
var json=resp.responseJSON||{};
var server_glus=[];
if(json.success){
server_glus=this._process_glus(json.glus);
}
var data={
'success':json.success,
'json_glus':server_glus,
'glus':server_glus,
'exception':json.exception,
'response':resp,
'total':(json.total?json.total:0)
};
this._last_find_time=new Date();
opts.client_on_complete(data);
},
_process_glus:function(glus){
for(var i=0;i<glus.length;++i){
glus[i].glu_id=glus[i].id;
}
return glus;
}
});
var AbstractListingRequest=Class.create(PagingRequest,{
initialize:function($super,url,options){
$super(url,options);
},
_create_listings:function(listings_json){
var now=new Date();
var return_listings=[];
var len=listings_json.length;
for(var i=0;i<len;++i){
return_listings.push(this._create_listing(listings_json[i]));
}
return return_listings;
},
_create_listing:function(listing_json){
var list=new Listing(listing_json);
list.__is_new=list.attrs.is_new;
return list;
},
_get_query_page_num:function(options){
return Math.floor(options.offset/options.limit);
}
});
var ListingPagingRequest=Class.create(AbstractListingRequest,{
initialize:function($super,options,on_complete){
$super("/listings/paging.js",options);
},
_run:function($super,options,on_complete){
var options={
client_on_complete:options.onComplete||Glyde.empty_function,
method:'get',
parameters:{
collection_id:options.collection_id,
offset:options.offset,
limit:options.limit,
vertical:options.vertical,
search_query:options.search_query,
elapsed_time:options.elapsed_time,
view:options.view,
sort_by:options.sort_by,
context:options.context,
sort_direction:options.sort_direction
},
onComplete:this._handle_response.bind(this)
};
$super(options);
},
_handle_response:function(resp,o){
var opts=resp.request.options;
var json=resp.responseJSON||{};
var server_listings=[];
if(json.success){
server_listings=json.listings;
}
var page_num=this._get_query_page_num(opts.parameters);
var data={
'success':json.success,
'json_listings':server_listings,
'listings':this._create_listings(server_listings),
'exception':json.exception,
'response':resp,
'page_num':page_num,
'market_value':json.market_value||0,
'collection_histo':json.histo||0,
'total':(json.total?json.total:0)
};
this._last_find_time=new Date();
opts.client_on_complete(data);
}
});
var ListingRefreshRequest=Class.create(AbstractListingRequest,{
initialize:function($super,options,data_source){
$super("/listings.js",options);
this._data_source=data_source;
},
_run:function($super,options,on_complete){
var options={
client_on_complete:options.onComplete||Glyde.empty_function,
method:'get',
parameters:{
collection_id:options.collection_id,
view:options.view,
vertical:options.vertical,
search_query:options.search_query,
elapsed_time:options.elapsed_time
},
onComplete:this._on_refresh.bind(this)
};
$super(options);
},
_on_refresh:function(resp,o){
Loading.hide();
var data=resp.responseJSON||{};
if(data.success){
var opts=resp.request.options;
var update_results=this._update_listings(data.listings);
var listings=this._create_listings(data.listings);
var local_data={
'success':data.success,
'modified_listings':update_results.modified_listings,
'removed_items':update_results.removed_listings,
'added_items':update_results.added_listings,
'listings':listings,
'collection_histo':data.histo
};
resp.request.options.client_on_complete(local_data);
}else{
Glyde.page.handle_server_errors(data);
}
},
_create_new_listings_from_data:function(data){
var list=AbstractListingRequest.prototype._create_listing.call(this,data.listing);
list.__is_new=true;
return list;
},
_update_listings:function(listings_json){
var arr_for_remove=[];
var arr_for_add=[];
var i,listing_data,len=listings_json.length;
var modified_listings=[]
for(i=0;i<len;++i){
listing_data=listings_json[i];
var old_listing=this._data_source.find_by_id(listing_data.id);
if(listing_data.is_removed){
if(old_listing)arr_for_remove.push({attrs:{id:listing_data.id}});
if(old_listing)modified_listings.push(old_listing);
continue;
}
if(old_listing){
var listing_to_add=old_listing;
if(old_listing.modified_attrs.length>0){
listing_to_add=this._create_listing(listing_data);
}else{
old_listing.update_attributes(listing_data);
}
modified_listings.push(listing_to_add);
}else{
var data={listing:listing_data};
var new_listing=this._create_new_listings_from_data(data);
modified_listings.push(new_listing);
arr_for_add.push(new_listing);
}
}
return{'modified_listings':modified_listings,
'removed_listings':arr_for_remove,
'added_listings':arr_for_add};
}
});
var SelectionManager=Class.create({
OP_SELECT_ONE:1,
OP_SELECT_ADD_ONE:2,
OP_SELECT_REMOVE_ONE:3,
initialize:function(){
this._selected_items=[];
},
select_one:function(item){
this._select([item],this.OP_SELECT_ONE);
},
add_one:function(item){
this._select([item],this.OP_SELECT_ADD_ONE)
},
remove_one:function(item){
this._select([item],this.OP_SELECT_REMOVE_ONE)
},
remove:function(items){
var index=null;
var len=items.length;
var items_to_notify=[];
for(var i=0;i<len;++i){
if((index=this._selected_items.indexOf(items[i]))!=-1){
this._selected_items.splice(index,1);
items_to_notify.push(items[i]);
}
}
if(items_to_notify.length>0){
this._notify_deselect_old_items(items_to_notify);
}
},
toggle_one:function(item){
if(this._selected_items.include(item)){
this.remove_one(item);
}else{
this.add_one(item);
}
},
has_selection:function(){
return(this._selected_items.length>0)
},
selected_items:function(){
return this._selected_items.clone();
},
_select:function(items_array,operation){
switch(operation){
case this.OP_SELECT_ONE:
if(items_array.length==1){
this._notify_deselect_old_items();
this._selected_items=items_array;
this._notify_select_items();
}
break;
case this.OP_SELECT_ADD_ONE:
if(items_array.length==1){
this._selected_items=this._selected_items.concat(items_array);
this._notify_select_items(items_array);
}
break;
case this.OP_SELECT_REMOVE_ONE:
if(items_array.length==1){
this._remove_item(items_array[0]);
this._notify_deselect_old_items(items_array);
}
break;
}
Glyde.notify.publish(SelectionManager.EVENT_SELECTION_CHANGED,
{items:this._selected_items});
},
_remove_item:function(item){
var len=this._selected_items.length;
for(var i=0;i<len;++i){
if(this._selected_items[i]==item){
this._selected_items.splice(i,1);
}
}
},
_notify_deselect_old_items:function(items_array){
var selected_items=items_array||this._selected_items;
var len=selected_items.length;
for(var i=0;i<len;++i){
Glyde.notify.publish(SelectionManager.EVENT_ITEM_DESELECT,{item:selected_items[i]});
}
},
_notify_select_items:function(items_array){
var selected_items=items_array||this._selected_items;
var len=selected_items.length;
for(var i=0;i<len;++i){
Glyde.notify.publish(SelectionManager.EVENT_ITEM_SELECT,{item:selected_items[i]});
}
}
});
SelectionManager.EVENT_ITEM_SELECT='selection_manager:item_select';
SelectionManager.EVENT_ITEM_DESELECT='selection_manager:item_deselect';
SelectionManager.EVENT_SELECTION_CHANGED='selection_manager:selection_changed';
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 GlydeCheckbox($('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){
Glyde.page.header.sell_checkout(this.attrs.id,glu,cents,condition,
charity_percentage,charity_id,location.href);
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"$"+PriceAdjuster.dollars_and_cents(this.cents(),true);},
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"$"+PriceAdjuster.dollars_and_cents(this.attrs.bs_original_price_cents,true);}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.glu.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 ($'+PriceAdjuster.dollars_and_cents(this.attrs.charity_proceeds.cents,true)+') 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 ($'+PriceAdjuster.dollars_and_cents(this.attrs.charity_proceeds.cents,true)+') 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.publisher){
_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();
};
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);
this.share_dialog=new ShareDialog();
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:'share_item',text:'Share This Item'},
{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){
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(){
this._listing.update_remote('is_for_sale','0');
this.close();
},
_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));
},
_share_item_request:function(){
if(typeof Collection=='undefined'){
this.share_dialog.open_share_collection_item('listing_share_item_button',this._listing,Glyde.user,true,false,true,this);
}else{
Collection.get_instance().open_share_collection_item_dialog('listing_share_item_button',this._listing,true,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);
},
_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._container_id).select('.edit_container')[0].update(this._edit_data.html);
this._start_price=this._listing.price();
var elem=$(this._container_id).select('.listing_details_widget')[0];
this._listing_details_widget=new 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';
},
_dialog_px_left_from_target:function(){
return 36;
},
_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 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))||
(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.s(' id="listing_share_item_button"');_j.s('>');
_j.ns('</div>');
_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.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();
};
TransactionDialog=Class.create(Glyde.Dialog,{
EVENT_OPEN:'transaction_dialog:open',
EVENT_CLOSE:'transaction_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));
Glyde.notify.subscribe(CouponCodeWidget.prototype.MESSAGE_COUPON_APPLIED,
this._handle_coupon_code_change.bind(this));
Glyde.notify.subscribe(CouponCodeWidget.prototype.MESSAGE_COUPON_CANCELLED,
this._handle_coupon_code_change.bind(this));
Glyde.notify.subscribe(TransactionDialogSkuSelector.prototype.MESSAGE_COUPON_CODE_REMOVED,
this._handle_sku_selector_coupon_code_change.bind(this));
Glyde.notify.subscribe(TransactionDialogSkuSelector.prototype.MESSAGE_COUPON_CODE_ADDED,
this._handle_sku_selector_coupon_code_change.bind(this));
},
open:function($super,glu,target_element,storefront_id){
$super(target_element,'');
this._storefront_id=storefront_id;
this._glu=glu;
this._loading_timeout=setTimeout(function(){$(this._container_id).update(this._render_loading_title());}.bind(this),250);
this._load_info(this.load_finished.bind(this));
Glyde.notify.publish(this.EVENT_OPEN,{'item_id':glu.id});
},
_load_info:function(on_finish){
var on_complete_handler=function(res,o){
var data=res.responseJSON;
if(data.success){
this._glu.listing=new Listing(data.listing);
this._skus=data.best_prices;
this._real_skus=data.listing.extra_info.legit_skus;
this._user_info=data.user_info;
this._set_coupon(data.coupon);
on_finish();
}else{
Glyde.page.handle_server_errors(data);
}
};
var options={
method:'get',
parameters:{
glu_id:this._glu.id,
storefront_id:this._storefront_id
},
onComplete:on_complete_handler.bind(this)
};
if(this._coupon_code()!=null){
options.parameters.coupon_code=this._coupon_code();
}
this._loading_request=new Ajax.Request('/stores/get_glu_info.js',options);
},
_handle_sku_selector_coupon_code_change:function(message_name,info){
this._set_coupon(info.coupon);
},
_handle_coupon_code_change:function(message_name,info){
this._set_coupon({code:info.code});
var on_finish_callback=function(){
this.load_finished();
this._sku_selector.reselect_sku_elem();
(info.client_callback||Glyde.empty_function)();
}.bind(this);
this._load_info(on_finish_callback);
},
close:function($super){
if(this._refetch_buy_timer){
clearTimeout(this._refetch_buy_timer);
}
if(this._loading_request){
this._loading_request.abort();
}
if(this._sku_selector&&this._sku_selector.shipping_address_select){
this._sku_selector.shipping_address_select.destroy();
}
$super();
Glyde.notify.publish(this.EVENT_CLOSE,{'item_id':this._glu.id});
},
_buy_now_button_element:function(){
return $(this._container_id).select('.buy_now_button')[0];
},
load_finished:function(){
clearTimeout(this._loading_timeout);
this._loading_request=null;
$(this._container_id).update(this._render_info());
this._sku_selector=
new TransactionDialogSkuSelector($('sku_selector'),
this._glu,this._skus,
this._real_skus,
this.__coupon,
this._user_info,
this._storefront_id);
if(this._skus.length>0&&!Glyde.page.is_user_bulk_seller()){
this._buy_now_button=new Glyde.ButtonWidget(this._buy_now_button_element(),'Buy Now',{color:'blue',tooltip_text:'clicking the Buy Now button completes your purchase'});
this._buy_now_button.observe('widget:activate',this._buy_now_request.bindAsEventListener(this));
}
(new Glyde.ButtonWidget('transaction_share_item_button','Share This Item')).observe('widget:activate',function(){
Collection.get_instance().open_share_collection_item_dialog('transaction_share_item_button',this._glu,true,this);
}.bind(this));
var cover=$(this._container_id).select('.image_box .cover')[0];
cover.fade_appear_image();
},
_buy_now_after_login:function(){
if(this._sku_selector._coupon_code_widget.coupon_code!=null){
this._sku_selector._coupon_code_widget.apply_code(this._buy_now_request.bind(this));
}else{
this._buy_now_request();
}
},
_buy_now_request:function(){
if(Glyde.user){
if(Glyde.user.is_reg_complete){
var buy_callback=function(){
this._buy_now_button.disable();
if(this._sku_selector.shipping_address_select.selected_address().cvv2_required&&
!this._sku_selector.can_purchase_entirely_from_credit())
{
this._show_cvv2_dialog();
}else{
this._on_buy();
}
}.bind(this);
this._sku_selector._coupon_code_widget.apply_code_if_exists(buy_callback);
}else{
this._send_user_to_signup();
}
}else{
this._send_user_to_signup();
}
},
_on_buy:function(cvv2){
$(this._container_id).select('.buy')[0].update(this._render_loading());
this._buy_item(cvv2,this._sku_selector.shipping_address_select.selected_address().address_id);
},
_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._user_info.card_issuer_name]);
this._cvv2_dialog.open('transaction_dialog_buy_now_button');
},
_on_cvv2_dialog_close:function(){
this._buy_now_button.enable();
},
_on_cvv2_dialog_purchase:function(cvv2){
this._on_buy(cvv2);
},
_send_user_to_signup:function(){
var context=$H({a:window.location.pathname+'#buy',i:this._glu.id}).toQueryString();
var return_to=Glyde.page.is_facebook()?Glyde.page.query_str_params().checkout_next:window.location.toString();
var hash={return_to:return_to,ctx:context,storefront_id:this._storefront_id};
if(this._coupon_code())hash.coupon_code=this._coupon_code();
Glyde.page.header.checkout(this._sku_selector.selected_id(),
this._glu.title,hash);
},
_buy_item:function(cvv2,address_id){
function on_complete(res,o){
var data=res.responseJSON;
if(data.success){
this._buy_now_button_element().innerHTML='';
this._buy_complete(data);
}else{
if(data.html){
this._buy_now_button_element().innerHTML='';
this._buy_failed(data);
}else{
Glyde.page.handle_server_errors(data);
}
}
}
var cents=this._sku_selector.selected_price();
var parameters={
storefront_id:this._storefront_id,
'sku[id]':this._sku_selector.selected_id(),
'price[cents]':cents
};
if(this._coupon_code()){parameters.coupon_code=this._coupon_code();}
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(cents);
new Ajax.Request('/purchase_orders',options);
},
_coupon_code:function(){
var code=null;
if(this.__coupon){
code=this.__coupon.code;
}
return code;
},
_set_coupon:function(coupon){
this.__coupon=coupon;
},
_buy_complete:function(data){
$(this._container_id).select('.buy')[0].update(this._render_purchased());
this._receipt=new Glyde.BuyReceiptWidget($(this._container_id).select('.receipt_container')[0],data);
},
_handle_purchase_cancelled:function(msg_name,info){
var func=function(){
this._load_info(this.load_finished.bind(this));
}.bind(this);
this._refetch_buy_timer=setTimeout(func,10000);
},
_buy_failed:function(data){
$(this._container_id).select('.buy')[0].update(this._render_purchased());
$(this._container_id).select('.receipt_container')[0].update(data.html);
},
_is_owner:function(){
if(Glyde.user){
return this._storefront_id==Glyde.user.id;
}else{
return false;
}
},
_set_container_ids:function(instance_num){
this._dialog_container_id='transaction_dialog_container';
this._container_id='transaction_dialog_content';
this._arrow_id='transaction_dialog_arrow';
this._close_button_id='transaction_dialog_close_button';
},
_dialog_px_left_from_target:function(){
return 36;
},
_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;
return element.descendantOf(this._dialog_container_id)||
(shipping_address_menu&&element.descendantOf(shipping_address_menu));
}
});
TransactionDialogSkuSelector=Class.create(Glyde.Widget,{
MESSAGE_COUPON_CODE_REMOVED:'transaction_dialog_sku_selector:coupon_code_removed',
MESSAGE_COUPON_CODE_ADDED:'transaction_dialog_sku_selector:coupon_code_added',
DOM_CLASS:'transaction_dialog_sku_selector_widget',
initialize:function($super,element,glu,skus,real_skus,
coupon,user_info,storefront_id){
$super(element);
if(skus.length==0){
this._element.update(this._render_no_skus());
}else{
this._skus=skus;
this._real_skus=real_skus;
this._glu=glu;
this._storefront_id=storefront_id;
this._coupon_code=coupon?coupon.code:null;
this._coupon=coupon;
if(user_info){
this._shipping_addresses=user_info.shipping_addresses;
this._credit_card=user_info.credit_card;
this._available_credit=user_info.available_credit;
}
this._element.update(this._render());
this._coupon_code_widget=new CouponCodeWidget($$('.coupon_box')[0],
this._glu,
this._glu,
this._storefront_id);
if(this._shipping_addresses){
this.shipping_address_select=new ShippingAddressSelect('shipping_address_select',
this._shipping_addresses,20000);
}
var sku=this._skus.detect(function(sku){
return sku.cents==this._glu.lowest_price_cents;
}.bind(this));
if(sku){
this.select_sku_elem(this.$$first('.sku_'+sku.sku_id));
}else{
this.select_sku_elem(this.$$first('.select_sku'));
}
this.$$('.select_sku').each(function(elem){
elem.observe('click',this._click_handler.bindAsEventListener(this,elem));
}.bind(this));
if(this._coupon_code&&this.selected_price()>999){
var total_line=this.$$('.sku_info_box #total_line')[0];
total_line.addClassName('total_line_wide_coupon');
}
}
},
selected_id:function(){
return this._selected_id;
},
_dollar_format:function(cents){
return('$'+Glyde.money.format_cents(cents));
},
reselect_sku_elem:function(){
this.select_sku_elem($$('.sku_'+this._selected_id)[0]);
},
select_sku_elem:function(elem){
var selected_sku_id=$w(elem.className).grep(/sku_/,function(n){
return n.split('_')[1];
})[0];
this._selected_id=parseInt(selected_sku_id,10);
elem.addClassName('selected');
elem.select('INPUT')[0].checked=true;
var sku=this._real_skus.detect(function(sku){
return(sku.sku_id==this._selected_id);
}.bind(this));
var bp=this._skus.detect(function(sku){
return(sku.sku_id==this._selected_id);
}.bind(this));
var total_price_cents=bp.total_price_with_coupon_cents;if(bp.shipping_cents!=null){
$$('.totals_box .shipping')[0].innerHTML=this._dollar_format(bp.shipping_cents);
}
if(this._coupon&&
(bp.cents>(this._coupon.minimum_item_price_cents||0))){
Glyde.notify.publish(this.MESSAGE_COUPON_CODE_ADDED,{coupon:this._coupon});
if(bp.total_price_with_coupon_cents!=null&&
bp.total_price_cents!=null){
$('total_cost').innerHTML=this._dollar_format(bp.total_price_cents);
$('total_cost').addClassName('strike_through');
var disc=$('total_cost_with_discount');
if(disc){
disc.innerHTML=this._dollar_format(bp.total_price_with_coupon_cents);
disc.display('inline');
}
}
}else{
if(bp.total_price_cents!=null){
$('total_cost').innerHTML=this._dollar_format(bp.total_price_cents);
}
if(this._coupon&&
(bp.cents<(this._coupon.minimum_item_price_cents||0))){
$('total_cost').removeClassName('strike_through');
var disc=$('total_cost_with_discount');
if(disc){
disc.undisplay();
}
Glyde.notify.publish(this.MESSAGE_COUPON_CODE_REMOVED,{coupon:{code:null}});
var msg=('Coupon code '+this._coupon.code+
' has a minimum purchase price of $'+
Glyde.money.format_cents(this._coupon.minimum_item_price_cents));
new GlydeAlert(msg,elem,
'Warning',
{position_preference:Glyde.Dialog.prototype.POSITION_ABOVE});
}
}
if(this._available_credit){
this._from_available=Math.min(this._available_credit,total_price_cents);
this._from_user=total_price_cents>this._available_credit?total_price_cents-this._available_credit:0;
var payment_elem=this.$$first('.payment');
if(payment_elem){
payment_elem.update(this._render_payment_info());
}
}
},
selected_price:function(){
for(var i=0;i<this._skus.length;i++){
if(this._skus[i].sku_id==this._selected_id){
return this._skus[i].cents;
}
}
return null;
},
can_purchase_entirely_from_credit:function(){
return this._from_user==0;
},
_click_handler:function(event,elem){
var element=elem;
var last_selected=this.$$first('.selected');
if(last_selected!=element){
last_selected.select('INPUT')[0].checked=false;
this.$$first('.selected').removeClassName('selected');
this.select_sku_elem(element);
}
},
_get_condition_name_from_id:function(condition_id){
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[this._glu.condition_type],condition_id);
},
_get_condition_desc_from_id:function(condition_id){
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[this._glu.condition_type],condition_id);
}
});
TransactionDialog.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();
};
TransactionDialog.prototype._render_info=function(){
var _j=new Jaml();
_j.ns(this._glu.listing._render_title());
_j.ns('<div');_j.s(' class="listing_details"');_j.s('>');
_j.ns('<div');_j.s(' class="'+('image_box'+(this._glu.listing.attrs.product_type=="CD"?" image_box_cd":""))+'"');_j.s('>');
_j.ns('<img');_j.s(' class="cover"');_j.s(' src="'+(Glyde.image.cover_path_for_max_w_h(this._glu.listing,100,140).replace('.jpg','h.jpg'))+'"');_j.s(' title="'+(this._glu.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._glu.listing.render_owner_info());
}
else{
_j.ns(this._glu.listing.render_non_owner_info(true));
}
_j.ns(this._glu.listing.render_vertical_info());
_j.ns('</div>');
_j.ns('<div');_j.s(' class="buy"');_j.s('>'+(this._render_buy_now()));
_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="transaction_share_item_button"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="right"');_j.s('>');
_j.ns('<div');_j.s(' class="button_box"');_j.s('>');
_j.ns('<div');_j.s(' class="buy_now_button"');_j.s(' id="transaction_dialog_buy_now_button"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
TransactionDialog.prototype._render_buy_now=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' id="sku_selector"');_j.s('>');
_j.ns('</div>');
return _j.v();
};
TransactionDialog.prototype._render_loading=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="buy_loading_wrapper"');_j.s('>');
_j.ns('<div');_j.s(' class="buy_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="buy_loading_message"');_j.s('>');Jaml.x();_j.s('Processing...');Jaml.x();
Jaml.x();_j.ns('</span>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
TransactionDialog.prototype._render_purchased=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="receipt_container"');_j.s('>');
_j.ns('</div>');
return _j.v();
};
TransactionDialogSkuSelector.prototype._render_no_skus=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="sold_out_msg"');_j.s('>We\'ve sold out of this item. Please check back soon.');
_j.ns('</div>');
return _j.v();
};
TransactionDialogSkuSelector.prototype._render=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="sku_info_box"');_j.s('>');
for(var i=0;i<this._skus.length;i++){
var sku=this._skus[i];
_j.ns('<div');_j.s(' class="'+('select_sku sku_'+sku.sku_id)+'"');_j.s(' title="'+(this._get_condition_desc_from_id(sku.condition_id).replace(/\n/g,' '))+'"');_j.s('>');
_j.ns('<input');_j.s(' type="'+('radio')+'"');_j.s('>');
_j.ns('</input>');
_j.ns('<div');_j.s(' class="price_information"');_j.s('>');
_j.ns('<div');_j.s(' class="line_one"');_j.s('>');
_j.ns('<div');_j.s(' class="condition"');_j.s('>');
_j.ns('<div');_j.s(' class="name"');_j.s('>'+(this._get_condition_name_from_id(sku.condition_id)));
_j.ns('</div>');
_j.ns('<div');_j.s(' class="icon"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="best_price"');_j.s('>'+('$'+PriceAdjuster.dollars_and_cents(sku.cents,true)));
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
}
_j.ns('<div');_j.s(' class="totals_box shipping_totals_box"');_j.s('>');
_j.ns('<div');_j.s(' class="plus_icon"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="shipping"');_j.s('>');
_j.ns('$'+PriceAdjuster.dollars_and_cents(this._real_skus[0].shipping.cents,true));
_j.ns('</div>');
_j.ns('<div');_j.s(' class="shipping_label label"');_j.s('>Shipping');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="equals_underline"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="totals_box total_cost"');_j.s(' id="total_line"');_j.s('>');
_j.ns('<div');_j.s(' class="cost"');_j.s('>');
if(this._coupon_code==null){
_j.ns('<div');_j.s(' id="total_cost"');_j.s('>');
_j.ns('$'+PriceAdjuster.dollars_and_cents(this._skus[0].total_price_cents,true));
_j.ns('</div>');
}
else{
_j.ns('<span');_j.s(' class="strike_through"');_j.s(' id="total_cost"');_j.s('>');
_j.ns('$'+PriceAdjuster.dollars_and_cents(this._skus[0].total_price_cents,true));
_j.ns('</span>');
_j.ns('<span');_j.s(' class="with_discount"');_j.s(' id="total_cost_with_discount"');_j.s('>');
_j.ns('$'+PriceAdjuster.dollars_and_cents(this._real_skus[0].total_with_coupon.cents,true));
_j.ns('</span>');
}
_j.ns('</div>');
_j.ns('<div');_j.s(' class="total_label label"');_j.s('>Total');
_j.ns('</div>');
_j.ns('</div>');
coupon_state_class=(this._coupon_code==null)?'coupon_link':'coupon_accepted';
_j.ns('<div');_j.s(' class="'+("coupon_box "+coupon_state_class)+'"');_j.s('>');
_j.ns('<a');_j.s(' class="enter_link"');_j.s(' href="'+('javascript: void(0)')+'"');_j.s('>Have a coupon code?');
_j.ns('</a>');
_j.ns('<div');_j.s(' class="coupon_input_box"');_j.s('>');
_j.ns('<input');_j.s(' type="'+('text')+'"');_j.s('>');
_j.ns('</input>');
_j.ns('<a');_j.s(' class="apply"');_j.s(' href="'+('javascript: void(0)')+'"');_j.s('>apply');
_j.ns('</a>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="coupon_accepted_box"');_j.s('>');
_j.ns('<span');_j.s(' class="text"');_j.s('>Coupon Applied');
_j.ns('</span>');
_j.ns('<a');_j.s(' class="cancel_coupon"');_j.s(' href="'+('javascript:void(0)')+'"');_j.s('>Cancel');
_j.ns('</a>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="personal_info_box"');_j.s('>');
if(this._shipping_addresses){
_j.ns('<div');_j.s(' class="shipping buy_boxlet"');_j.s('>');
_j.ns('<div');_j.s(' class="label"');_j.s('>Shipping:');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="value"');_j.s('>');
_j.ns('<div');_j.s(' id="shipping_address_select"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
}
if(this._credit_card){
_j.ns('<div');_j.s(' class="payment buy_boxlet"');_j.s('>');
_j.ns(this._render_payment_info());
_j.ns('</div>');
}
_j.ns('</div>');
return _j.v();
};
TransactionDialogSkuSelector.prototype._render_payment_info=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="label"');_j.s('>Payment:');
_j.ns('</div>');
if(this._from_available&&this._from_user){
_j.ns('<div');_j.s(' class="value"');_j.s('>');
_j.ns('<div');_j.s(' class="payment_row"');_j.s('>');
_j.ns('<div');_j.s(' class="attr"');_j.s('>Glyde Credit');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="amount"');_j.s('>'+('$'+PriceAdjuster.dollars_and_cents(this._from_available,true)));
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="payment_row"');_j.s('>');
_j.ns('<div');_j.s(' class="attr"');_j.s('>'+(this._credit_card));
_j.ns('</div>');
_j.ns('<div');_j.s(' class="amount"');_j.s('>'+('$'+PriceAdjuster.dollars_and_cents(this._from_user,true)));
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
}
else if(this._from_available){
_j.ns('<div');_j.s(' class="value"');_j.s('>'+('Glyde Credit'));
_j.ns('</div>');
}
else{
_j.ns('<div');_j.s(' class="value"');_j.s('>'+(this._credit_card));
_j.ns('</div>');
}
return _j.v();
};
Glyde.BuyReceiptWidget=Class.create(Glyde.Widget,{
MESSAGE_PURCHASE_CANCELLED:'buy_receipt_widget:purchase_cancelled',
initialize:function($super,element,server_data){
$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');
oops_button.onclick=this._handle_undo_clicked.bind(this);
this._undo_timer=setTimeout(this._handle_undo_expired.bind(this),30000);
}
},
cancel_timer:function(){
if(this._undo_timer){
clearTimeout(this._undo_timer);
this._undo_timer=null;
}
},
_handle_undo_clicked:function(){
var options={
parameters:{id:this._purchase_order_id},
onComplete: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)
};
new Ajax.Request(this._purchase_orders_cancel_url(),options);
},
_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_delivery_date:function(){
this._clear_undo();
this.$$first('.delivery').display();
},
_show_purchase_cancelled_message:function(){
this._clear_undo();
this.$$first('.oops_message').display();
this.$$first('.receipt_bottom').undisplay();
},
_show_soft_error_message:function(){
this._clear_undo();
this.$$first('.errors_in_oops').display();
},
_handle_undo_expired:function(){
this._hide_undo_button();
}
});
var Collection=Class.create({
PAGE_SIZE:25,
DISPLAY_AS_LIST:1,
DISPLAY_AS_GRID:2,
DEFAULT_SEARCH_TEXT:"Enter a title or tag",
listings:null,
sorted_by:'title',
auto_refresh_interval:5*(60*1000),initialize:function(){},
find_listing_by_id:function(listing_id){
return this.view.data_source.find_by_id(listing_id);
},
onload:function(params,is_back){
Event.observe(window,'resize',
this._handle_window_resize.bindAsEventListener(this));
Glyde.notify.subscribe('collection:sorted',this._on_sort_change.bind(this));
this.page_params=params;
this._data_source_options={};
this._data_source_options.offset=0;
this._data_source_options.limit=this.PAGE_SIZE;
Glyde.notify.subscribe(Listing.EVENT_UPDATED,
this.handle_listing_object_update.bind(this));
Glyde.notify.subscribe(Listing.EVENT_DELETED,
this.handle_listing_object_delete.bind(this));
Glyde.notify.subscribe(ImportDialog.prototype.EVENT_UNSUPPORTED_FILE_TYPE,
this._handle_unsupported_import_file_type.bind(this));
Glyde.notify.subscribe(ImportStatusUpdater.prototype.EVENT_IMPORT_DONE,
this._handle_import_complete.bind(this));
Glyde.notify.subscribe(ImportStatusUpdater.prototype.EVENT_IMPORT_START,
this._handle_import_start.bind(this));
Glyde.notify.subscribe(ImportStatusUpdater.prototype.EVENT_IMPORT_CANCELLED,
this._handle_import_cancelled.bind(this));
Glyde.notify.subscribe(AbstractCollectionView.EVENT_RENDERED,
this.after_render.bind(this));
this._selection_manager=new SelectionManager();
Glyde.notify.subscribe(SelectionManager.EVENT_ITEM_SELECT,
this._handle_listing_select.bind(this));
Glyde.notify.subscribe(SelectionManager.EVENT_ITEM_DESELECT,
this._handle_listing_deselect.bind(this));
Glyde.notify.subscribe(AddBulkItemDialog.prototype.EVENT_LISTING_ADDED,
this._handle_bulk_seller_item_add.bind(this));
Glyde.notify.subscribe(UpdatePriceDialog.prototype.EVENT_PRICE_UPDATED,
this._handle_bulk_seller_price_updated.bind(this));
this._grab_globals();
this._setup_selector();
if(this._should_show_invite_notice()){this._show_invite_notice();}
this._setup_header();
this._setup_dialogs();
this._setup_views();
this._last_update_time=new Date();
this.restart_refresh_timer();
this._setup_css_class_names();
$('collection_container').vshow();
if(params.display_as==null){
params.display_as=g_collection.view||null;
}
this._resize_collection_box();
return this.restore_from_state(params);
},
_setup_selector:function(){
var vertical_options=[
{value:null,display_value:'all items'},
{value:'videos',display_value:'dvds'},
{value:'music',display_value:'cds'},
{value:'games'},
{value:'books'}
];
this.vertical_select=new GlydeSelect('vertical_select',vertical_options);
this.vertical_select.onchange=this._on_vertical_select_change.bind(this);
this._setup_sort_select(this._setup_sort_select_options());
},
_sync_selector_ui:function(){
this._sync_sort_ui();
this._sync_vertical_ui();
},
_setup_css_class_names:function(){
if(this.is_owner_state()){
$('collection').addClassName('owner');
}
},
_should_show_invite_notice:function(){
return!Glyde.user;
},
_setup_sort_select_options:function(){
var sort_options=[
{value:'title'},
{value:'creator'},
{value:'type'},
{value:'item_type',display_value:'subtype'},
{value:'status'},
{value:'condition'},
{value:'price',display_value:'your price'}
];
return sort_options;
},
_setup_sort_select:function(sort_options){
var sort_option_values=sort_options.map(function(sort){
return sort.value;
});
if(!sort_option_values.include(this._data_source_options.sort_by)){
this._data_source_options.sort_by=sort_option_values[0];
}
this.sort_select=new GlydeSelect('sort_select',sort_options);
this.sort_select.onchange=this._on_sort_select_change.bind(this);
},
_setup_header:function(){
this._filter_box=new FilterBoxWidget($$('#collection .search_box')[0])
this._filter_box.observe('widget:filter_request',this.search.bindAsEventListener(this));
},
_setup_dialogs:function(){
var add_item_callback=this._add_new_listing_remote.bind(this);
this._add_item_dialog=new AddItemDialog(add_item_callback);
this.listing_dialog=new ListingDialog(this.card_issuers);
this.share_dialog=new ShareDialog();
},
_setup_views:function(){
this.list_view=new CollectionListView('list_view',this.id);
this.grid_view=new CollectionBookshelfView('grid_view',this.id);
},
_grab_globals:function(){
this.id=g_collection.id;
this.user_id=g_collection.user_id;
this.owner=g_collection.owner;
this.is_scrollable=g_collection.is_scrollable;
this.total=g_collection.listings_count;
this.card_issuers=g_collection.issuers;
if(g_collection.sort_by){
this._set_sort_options(g_collection.sort_by);
}else{
this._set_default_sort_options();
}
},
_set_sort_options:function(sort_by){
var sort_by_arr=sort_by.split('&');
this._data_source_options.sort_by=sort_by_arr[0];
this._data_source_options.sort_direction=parseInt(sort_by_arr[1]);
},
_set_default_sort_options:function(){
this._data_source_options.sort_by='title';
this._data_source_options.sort_direction=1;
},
_handle_bulk_seller_price_updated:function(event_name,info){
this.refresh();
},
_handle_bulk_seller_item_add:function(event_name,info){
var json=info;
Glyde.page.flash_notice(json.title+" has been added to your inventory.");
this.refresh();
},
_on_vertical_select_change:function(vertical){
this._data_source_options.vertical=vertical;
this._data_source_options.offset=0;
this._data_source_options.limit=this.PAGE_SIZE;
this.display();
},
toggle_add_dialog:function(){
var action=function(){
this._add_item_dialog.open();
}.bind(this);
Glyde.page.run_client_backable_action(action);
},
_add_new_listing_remote:function(glu_id,condition_id,callback){
if(this._add_glu_key==('glu_'+glu_id)){
return;
}
var on_complete=function(listing){
Glyde.page.flash_notice('"'+listing.attrs.title+'"'+' was added to your collection');
this.refresh();
(callback||Glyde.empty_function)();
this._add_glu_key=null;
Glyde.page.end_backable_action();
}.bind(this);
this._add_glu_key='glu_'+glu_id;
Glyde.page.start_backable_action();
this.view.data_source.add(glu_id,condition_id,on_complete);
},
current_state:function(params){
params.display_as=this.display_as;
if(this.display_as==this.DISPLAY_AS_GRID){
params.sort_by=this._data_source_options.sort_by;
if(this._data_source_options.vertical!=null){
params.vert=this._data_source_options.vertical;
}
params.sort_dir=this._data_source_options.sort_direction;
if(this._data_source_options.search_query){
params.s_query=this._data_source_options.search_query;
}
params=this.view.current_state(params);
}
params=this._add_item_dialog.current_state(params);
return params;
},
on_in_page_back:function(params){
return this.restore_from_state(params);
},
change_view:function(view){
var collection_element=$('collection');
switch(view){
case'list_view':
collection_element.removeClassName('grid_view');
break;
case'grid_view':
collection_element.removeClassName('list_view');
break;
}
collection_element.addClassName(view);
},
restore_from_state:function(params){
var async_req_count=0;
if(this.is_owner_state()&&this.is_inventory()){
this.display_as=this.DISPLAY_AS_LIST;
}else if(this.is_owner_state()){
this.display_as=params.display_as||this.DISPLAY_AS_GRID;
}else{
this.display_as=this.DISPLAY_AS_GRID;
}
this.view=this.display_as==this.DISPLAY_AS_LIST?this.list_view:this.grid_view;
if(params.sort_by)this._data_source_options.sort_by=params.sort_by;
if(params.sort_dir)this._data_source_options.sort_direction=parseInt(params.sort_dir);
this._data_source_options.vertical=this.view.data_source.sanitize_vertical(params.vert);
this._data_source_options.search_query=params.s_query;
if(this._filter_box){this._filter_box.set_query(params.s_query||'');}
async_req_count=this.view.restore_from_state(params)||0;
this.view.show();
this.change_view(this.display_as==this.DISPLAY_AS_LIST?'list_view':'grid_view');
this.display();
this._sync_selector_ui();
async_req_count=async_req_count+(this._add_item_dialog.restore_from_state(params)||0);
return async_req_count;
},
on_state_change:function(event_name,info){
console.log(info.first_listing_id);
},
select_row:function(listing_id,cbox,event){
var checkbox=new GlydeCheckbox(cbox);
if(checkbox.is_disabled())return false;
var listing=this.find_listing_by_id(listing_id);
if((Browser.WIN&&event.ctrlKey)||(Browser.MAC&&event.metaKey)){
this._selection_manager.toggle_one(listing.attrs.id);
}else{
this._selection_manager.select_one(listing.attrs.id);
}
this._update_button_enablement();
},
toggle_row_selection:function(listing_id,cbox,event){
var event=Event.extend(Event.get(event));
var checkbox=new GlydeCheckbox(cbox);
if(checkbox.is_disabled())return false;
var listing=this.find_listing_by_id(listing_id);
if(event.shiftKey){
this._handle_multiple_select(listing,checkbox,event);
}else if((Browser.WIN&&event.ctrlKey)||(Browser.MAC&&event.metaKey)){
this._selection_manager.toggle_one(listing.attrs.id);
}else{
if(checkbox.is_checked()){
this._selection_manager.remove_one(listing.attrs.id);
}else{
this._selection_manager.add_one(listing.attrs.id);
}
this._marker_listing_id=listing.attrs.id;
}
this._update_button_enablement();
event.stop();
},
_handle_listing_select:function(event_name,info){
var listing_id=info.item;
var listing=this.find_listing_by_id(listing_id);
listing.select();
},
_handle_listing_deselect:function(event_name,info){
var listing_id=info.item;
var listing=this.find_listing_by_id(listing_id);
if(listing)listing.deselect();
},
_handle_multiple_select:function(listing,checkbox,event){
var listings=this.view.data_source.current_listings();
var marker=this.find_listing_by_id(this._marker_listing_id)||listings[0];
var index_marker=listings.indexOf(marker);
var index_clicked=listings.indexOf(listing);
var clicked_first=(index_clicked>index_marker);
var start=clicked_first?index_marker:index_clicked;
var end=clicked_first?index_clicked:index_marker;
for(var x=start;x<=end;++x){
checkbox.is_checked()?listings[x].deselect():listings[x].select();
}
},
search:function(event){
var search_term=event.memo.query;
if(this._current_search_term!=search_term){
this._data_source_options.offset=0;
this._data_source_options.search_query=search_term.empty()?null:search_term;
this.display();
this._current_search_term=search_term;
}
},
remove_selected:function(){
var selected_listing_ids=this._selection_manager.selected_items();
if(selected_listing_ids.length==0){
alert('No listings were selected.');
return;
}
this._remove_listings(selected_listing_ids);
},
_remove_listings:function(listing_ids){
var confirm_str='Remove the listing'+(listing_ids.length>1?'s':'')+' from your collection?';
if(!confirm(confirm_str)){return;}
var rm=function(){
if(Glyde.page.is_user_bulk_seller()){
this.view.data_source.bs_remove(listing_ids,
this._on_bs_remove_complete.bind(this));
}else{
this.view.data_source.remove(listing_ids,
this._on_remove_complete.bind(this));
}
this._selection_manager.remove(listing_ids);
}.bind(this);
this.view.remove_listings(listing_ids,rm);
},
_on_bs_remove_complete:function(data){
if(data.success){
this.refresh();
}else{
Glyde.page.handle_server_errors(data);
}
},
_on_remove_complete:function(data){
if(data.success){
this.refresh();
}else{
Glyde.page.handle_server_errors(data);
}
},
_update_market_value:function(data){
var histo=data.collection_histo;
$('collection_description').innerHTML=this._render_page_title(histo);
},
refresh:function(force_import_refresh){
this.restart_refresh_timer();
var now=new Date();
var elapsed_time=now.getTime()-this._last_update_time.getTime();
if(elapsed_time<=0)return;
if(force_import_refresh||Glyde.page.import_updater.is_importing()){
this.view.data_source.refresh_adds_only(this._on_adds_only_refresh.bind(this),
elapsed_time);
}else{
this.view.data_source.refresh(this._on_normal_refresh.bind(this),
elapsed_time);
}
},
_on_refresh_for_listings:function(data,listings_attr_to_look_at){
this._last_update_time=new Date();
if(!data.modified_listings)data.modified_listings=data.listings;
this.view.render_items(data);
this._update_market_value(data);
},
_on_adds_only_refresh:function(data){
this._on_refresh_for_listings(data,'listings');
},
_on_normal_refresh:function(data){
this._on_refresh_for_listings(data,'modified_listings');
},
restart_refresh_timer:function(){
if(this.refresh_timeout_id){clearTimeout(this.refresh_timeout_id);}
this.refresh_timeout_id=setTimeout('Collection.get_instance().refresh()',this.auto_refresh_interval);
},
display:function(){
this.view.render(this._data_source_options);
},
after_render:function(event_name,info){
this._update_button_enablement();
this._update_market_value(info);
},
_update_button_enablement:function(){
var any_selected=false;
var selected_items=this._selection_manager.selected_items();
for(var i=0;i<selected_items.length;++i){
if($('listing_row_'+selected_items[i])){
any_selected=true;
break;
}
}
var in_list_view=this.display_as==this.DISPLAY_AS_LIST;
if(in_list_view&&any_selected){
this._enable_button('delete');
}else{
this._disable_button('delete');
}
if(Glyde.page.import_updater&&Glyde.page.import_updater.is_importing()){
this._disable_button('import_button');
}
},
open_import_dialog:function(){
this._import_dialog=this._create_import_dialog();
this._import_dialog.open();
return this._import_dialog;
},
_create_import_dialog:function(){
return new ImportDialog();
},
_handle_unsupported_import_file_type:function(event_name,info){
Glyde.page.flash_notice("The file type you tried to import is unsupported.");
},
_handle_import_start:function(event_name,info){
this.auto_refresh_interval=10*1000;this.refresh();
this._disable_button('import_button');
},
_handle_import_complete:function(event_name,info){
this.auto_refresh_interval=5*60*1000;if(this._import_cancelled){
this._import_cancelled=false;
console.log('canceled import');
this.display();
}else{
console.log('successful import');
this.display();
}
this._enable_button('import_button');
},
open_share_collection_dialog:function(source_element_id){
this.share_dialog.open_share_collection(source_element_id,this.owner,
this.is_owner_state(),this.is_store(),g_collection);
},
open_share_collection_item_dialog:function(source_element_id,listing,
position_above,dialog_opener){
this.share_dialog.open_share_collection_item(source_element_id,listing,
this.owner,this.is_owner_state(),
this.is_store(),position_above,
dialog_opener,g_collection);
},
update_price_dialog:function(){
if(this._update_price_dialog==null){
this._update_price_dialog=new UpdatePriceDialog();
}
return this._update_price_dialog;
},
_handle_import_cancelled:function(event_name,info){
this._import_cancelled=true;
},
_disable_button:function(id){
var button=$(id);
button.className=button.className.replace(/ unavailable/g,'');
button.className+=' unavailable';
if(!button._onclick){
button._onclick=button.onclick;
button.onclick=Glyde.empty_function;
}
},
_enable_button:function(id){
var button=$(id);
button.className=button.className.replace(/ unavailable/g,'');
if(button._onclick){
button.onclick=button._onclick;
button._onclick=null;
}
},
sort_by:function(name,direction,do_not_display,do_not_update_server){
this._data_source_options.sort_by=name;
this._data_source_options.sort_direction=direction;
if(!do_not_display){
this.display();
}
if(!do_not_update_server&&this.is_owner_state()){
this._update_server_sort(name,direction);
}
},
_on_sort_select_change:function(sort){
Glyde.notify.publish('collection:sorted',{by:sort});
},
_on_sort_change:function(event_name,info){
var direction;
if(this._data_source_options.sort_by!=info.by){
direction=1;
}else{
direction=this._data_source_options.sort_direction==0?1:0;
}
this.sort_by(info.by,direction);
this._sync_sort_ui();
},
_sync_sort_ui:function(){
var sort_by=this._data_source_options.sort_by;
var sort_direction=this._data_source_options.sort_direction;
this.sort_select.select(this.sort_select.get_index_from_value(sort_by),false);
$('sort_ascdsc').className=sort_direction?'asc':'dsc';
$('sort_ascdsc').title=sort_direction?'switch to descending order':'switch to ascending order';
},
_sync_vertical_ui:function(){
var vertical=this._data_source_options.vertical;
this.vertical_select.select(this.vertical_select.get_index_from_value(vertical),false);
},
_update_server_sort:function(name,direction){
var server_sort_by=(name+'&'+direction);
var options={
method:'put',
parameters:{'config[collection_sort_by]':server_sort_by},
onComplete:function(resp,o){}
};
this._update_user_configuration(options);
},
handle_listing_object_update:function(event_name,listing){
if(listing.just_set_for_sale()){
Glyde.page.flash_notice('"'+listing.attrs.title+'"'+' has been listed for sale. We\'ll email you when it sells.');
}
this.refresh();
},
handle_listing_object_delete:function(event_name,listing){
this.view.remove_listings([listing.attrs.id]);
this.refresh();
},
_update_user_configuration:function(options){
new Ajax.Request('/user_configurations/'+this.user_id+'.js',options);
},
save_view_preference:function(){
var options={
method:'put',
parameters:{'config[collection_view]':this.display_as},
onComplete:function(resp,o){
}
};
this._update_user_configuration(options);
},
view_as_list:function(){
this._change_view_to('list');
},
view_as_grid:function(){
this._change_view_to('grid');
},
_change_view_to:function(view_str){
var upcase_view_str=view_str.toUpperCase();
var lcase_view_str=view_str.toLowerCase();
if(this.display_as!=this['DISPLAY_AS_'+upcase_view_str]){
var action=function(){
this.display_as=this['DISPLAY_AS_'+upcase_view_str];
this.change_view(lcase_view_str+'_view');
$(this.view._container_id).innerHTML='';
this._show_view(this[lcase_view_str+'_view']);
this._data_source_options.offset=0;
this.display();
}.bind(this);
Glyde.page.run_client_backable_action(action);
this.save_view_preference();
}
},
_show_view:function(view){
this.view.hide();
this.view=view;
view.show();
},
listing_click_mark_to_market:function(listing_id){
this.find_listing_by_id(listing_id).mark_to_market_static();
},
_on_complete_mark_to_market:function(data){
this._update_market_value(data);
new fx.FontColorPulse('total_collection_value').to_color();
if(data.success&&data.listings.length>0){
var vert=this.__vertical_display_value.indexOf('items')!=-1?'items':this.__vertical_display_value;
this.__vertical_display_value=null;
Glyde.page.flash_notice('All of your '+vert+' have been marked for sale');
this.view.update();
}
},
_handle_window_resize:function(event){
this._resize_collection_box();
this.view._size_for_page();
},
_resize_collection_box:function(){
var new_height=document.viewport.getHeight()-223;
$('collections_box').style.height=new_height+'px';
},
is_owner_state:function(){
if(Glyde.user&&Glyde.user.id==this.user_id){
return true;
}else{
return false;
}
},
is_store:function(){
return g_collection.collection_type=='store';
},
is_charity_store:function(){
return g_collection.collection_type=='store'&&g_collection.is_charity_store;
},
is_inventory:function(){
return g_collection.collection_type=='inventory';
},
_show_invite_notice:function(){
var notice=$('notice_wrapper');
if(notice){
var get_invite_message='Want to create your own virtual collection? Click here.';
var link_styles='color: dodgerblue';
notice.innerHTML='<a style="'+link_styles+'"href="javascript:Glyde.page.header.organize()">'+
get_invite_message+'</a>';
}
}
});
Object.extend(Collection,{
get_instance:function(){
return g_organize_page.controller;
}
});
Collection.prototype._render_page_title=function(histo){
var _j=new Jaml();
if(Glyde.page.is_user_bulk_seller()){
_j.ns(this._render_page_title_bulk_seller(histo));
}
else{
_j.ns(this._render_page_title_normal(histo));
}
return _j.v();
};
Collection.prototype._render_page_title_bulk_seller=function(histo){
var _j=new Jaml();
var show_comma=false;
_j.ns('<div');_j.s(' id="collection_values"');_j.s('>');
var total_value_string=histo.total.toString().format_number()+" "+(histo.total==1?"item":"items");
_j.ns('<span');_j.s(' id="total_items"');_j.s(' title="'+(total_value_string)+'"');_j.s('>');
_j.ns(total_value_string);
_j.ns('</span>');
if(histo.total){
_j.ns('&nbsp;&bull;&nbsp;');
}
if(histo.videos){
var num_dvds=histo.videos.count;
var dvd_value_string=num_dvds.toString().format_number()+" "+(num_dvds==1?"dvd":"dvds");
_j.ns('<span');_j.s(' id="total_videos"');_j.s(' title="'+(dvd_value_string)+'"');_j.s('>');
_j.ns(dvd_value_string);
_j.ns('</span>');
show_comma=true;
}
if(histo.music){
if(show_comma){
_j.ns('&nbsp;&bull;&nbsp;');
}
var num_cds=histo.music.count;
var cd_value_string=num_cds.toString().format_number()+" "+(num_cds==1?"cd":"cds");
_j.ns('<span');_j.s(' id="total_cds"');_j.s(' title="'+(cd_value_string)+'"');_j.s('>');
_j.ns(cd_value_string);
_j.ns('</span>');
show_comma=true;
}
if(histo.games){
if(show_comma){
_j.ns('&nbsp&bull;&nbsp;');
}
var num_games=histo.games.count;
var game_value_string=num_games.toString().format_number()+" "+(num_games==1?"game":"games");
_j.ns('<span');_j.s(' id="total_games"');_j.s(' title="'+(game_value_string)+'"');_j.s('>');
_j.ns(game_value_string);
_j.ns('</span>');
show_comma=true;
}
if(histo.books){
if(show_comma){
_j.ns('&nbsp;&bull;&nbsp;');
}
var num_books=histo.books.count;
var book_value_string=num_books.toString().format_number()+" "+(num_books==1?"book":"books");
_j.ns('<span');_j.s(' id="total_books"');_j.s(' title="'+(book_value_string)+'"');_j.s('>');
_j.ns(book_value_string);
_j.ns('</span>');
show_comma=true;
}
_j.ns('</div>');
return _j.v();
};
Collection.prototype._render_page_title_normal=function(histo){
var _j=new Jaml();
var show_comma=false;
_j.ns('<div');_j.s(' id="collection_values"');_j.s('>');
var total_value_string=histo.total.toString().format_number()+" "+(histo.total==1?"item":"items")+" worth "+histo.total_market_value_str;
_j.ns('<span');_j.s(' id="total_items"');_j.s(' title="'+(total_value_string)+'"');_j.s('>');
_j.ns(total_value_string);
_j.ns('</span>');
if(histo.total){
_j.ns('&nbsp;&bull;&nbsp;');
}
if(histo.videos){
var num_dvds=histo.videos.count;
var dvd_value_string=num_dvds.toString().format_number()+" "+(num_dvds==1?"dvd":"dvds")+" ("+histo.videos.market_price_str+")";
_j.ns('<span');_j.s(' id="total_videos"');_j.s(' title="'+(dvd_value_string)+'"');_j.s('>');
_j.ns(dvd_value_string);
_j.ns('</span>');
show_comma=true;
}
if(histo.music){
if(show_comma){
_j.ns('&nbsp;&bull;&nbsp;');
}
var num_cds=histo.music.count;
var cd_value_string=num_cds.toString().format_number()+" "+(num_cds==1?"cd":"cds")+" ("+histo.music.market_price_str+")";
_j.ns('<span');_j.s(' id="total_cds"');_j.s(' title="'+(cd_value_string)+'"');_j.s('>');
_j.ns(cd_value_string);
_j.ns('</span>');
show_comma=true;
}
if(histo.games){
if(show_comma){
_j.ns('&nbsp&bull;&nbsp;');
}
var num_games=histo.games.count;
var game_value_string=num_games.toString().format_number()+" "+(num_games==1?"game":"games")+" ("+histo.games.market_price_str+")";
_j.ns('<span');_j.s(' id="total_games"');_j.s(' title="'+(game_value_string)+'"');_j.s('>');
_j.ns(game_value_string);
_j.ns('</span>');
show_comma=true;
}
if(histo.books){
if(show_comma){
_j.ns('&nbsp;&bull;&nbsp;');
}
var num_books=histo.books.count;
var book_value_string=num_books.toString().format_number()+" "+(num_books==1?"book":"books")+" ("+histo.books.market_price_str+")";
_j.ns('<span');_j.s(' id="total_books"');_j.s(' title="'+(book_value_string)+'"');_j.s('>');
_j.ns(book_value_string);
_j.ns('</span>');
show_comma=true;
}
_j.ns('</div>');
return _j.v();
};
var GridScrollWidget=Class.create(ScrollWidget,{
PAGE_SIZE:1,
initialize:function($super,element,view,item_size,start_page,is_charity_store){
this._view=view;
this._item_size=item_size;
this._page_to_first_listing_id=[];
this._is_charity_store=is_charity_store;
$super(element,this.PAGE_SIZE,start_page);
},
disable_paging:function(){
this.__page_forward=this.page_forward;
this.page_forward=Glyde.empty_function;
this.__page_back=this.page_back;
this.page_back=Glyde.empty_function;
},
enable_paging:function(){
if(this.__page_forward){
this.page_forward=this.__page_forward;
this.__page_forward=null;
}
if(this.__page_back){
this.page_back=this.__page_back;
this.__page_back=null;
}
},
_on_listings_loaded:function(first_listing_id,data){
Glyde.notify.publish(GridScrollWidget.EVENT_LISTINGS_LOADED,{'first_item_id':first_listing_id,'data':data,'current_page':this.current_page});
Glyde.page.end_backable_action();
},
_advance_scroll_left:function(num_px){
return Browser.IE7?Math.round(num_px*0.45):Math.round(num_px*0.15);
},
_scroll_interval:function(){
return Browser.IE?(Browser.IE7?15:10):17;
},
set_page:function($super,page){
Glyde.page.start_backable_action();
$super(page);
},
_after_animate:function(){
Loading.hide();
if(this._dynamic_after_animate){
this._dynamic_after_animate();
this._dynamic_after_animate=null;
}else if(this.current_page){
}
},
_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;
function on_data_ready(data){
if(this._view._is_wrong_search_query(data))return;
var total_items=Math.ceil(data.total/this._item_size);
var pages=[];
if(data&&data.listings.size()==0){
pages.push({page_index:0,items:[this._render_no_items()]});
}else{
var items=data.listings;
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);
if(start<items.size()){
this._page_to_first_listing_id[c]=items[start].attrs.id;
pages.push({page_index:c,items:[this._item_html(items.slice(start,stop))]});
}
}
}
(callback||this._on_pages_ready.bind(this))(pages,total_items);
if(Browser.IE6){
this._dynamic_after_animate=function(){
this._on_listings_loaded(this._page_to_first_listing_id[this.current_page],data);
}.bind(this);
}else{
this._on_listings_loaded(this._page_to_first_listing_id[this.current_page],data);
}
}
this._view._data_source_options.offset=item_start*this._item_size;
this._view._data_source_options.limit=(item_end-item_start)*this._item_size;
this._view.data_source.find(this._view._data_source_options,on_data_ready.bind(this));
}
});
GridScrollWidget.EVENT_LISTINGS_LOADED='grid_scroll_widget: listings_loaded';
GridScrollWidget.prototype._item_html=function(item){
var s=[];
var last_item_label=null;
var data_source_options=this._view._data_source_options;
function needs_item_label(index){
if(index==0){
return true;
}
switch(data_source_options.sort_by){
case'title':
case'creator':
case'item_type':
case'sell':
case'type':
case'condition':
case'status':
case'comps':
case'price':
if(item_label(last_item_label)!=item_label(index)){
return true;
}
break;
}
return false;
}
function item_should_have_title(index){
var should_have_title=false;
switch(data_source_options.sort_by){
case'title':
break;
case'creator':
break;
case'item_type':
should_have_title=true;
break;
case'sell':
break;
case'type':
break;
case'condition':
break;
case'comps':
break;
case'price':
break;
case'status':
break;
}
return should_have_title;
}
function item_label(index,truncate){
var label='';
var listing=item[index];
var is_sellable=listing.is_modifiable()&&listing.is_sellable();
var only_sellable=!listing.is_modifiable()&&listing.is_sellable();
switch(data_source_options.sort_by){
case'title':
label=listing.attrs.sort_chars.toUpperCase();
break;
case'creator':
var creator=listing.attrs.creator?listing.attrs.creator:'';
label=creator.charAt(0).toUpperCase();
break;
case'item_type':
var type_for_vertical=listing.attrs.type_for_vertical||'';
label=type_for_vertical;
if(truncate){
label=type_for_vertical.truncate_with_delimiters(20);
}
break;
case'sell':
label=listing.is_for_sale()?'for sale':'not for sale';
break;
case'type':
label=Glyde.glu.friendly_vertical_name(listing.attrs.vertical,true);
break;
case'condition':
label=listing.condition_str().toLowerCase();
break;
case'comps':
label=(is_sellable||only_sellable)?listing._valid_price_str(listing.attrs.market_price.price.cents):'not sellable';
break;
case'price':
label=listing.is_for_sale()?listing.price_str():'Not for sale';
break;
case'status':
label=listing.status();
switch(label){
case'&nbsp;':label='no status';break;
case'Sold (Delivered)':label='Delivered';break;
case'Sold (Sale in Process)':label='Sold';break;
case'Buyer Returning':label='Return';break
default:'pending sale';break;
}
break;
}
return label;
}
s.push('<div class="scroll_item">');
for(var c=0;c<item.length;c++){
s.push('<div class="item">');
s.push('');s.push(item[c]._to_grid());s.push('');
if(needs_item_label(c)){
s.push('<div class="label_wrapper">');
s.push('<div class="label">');
s.push('<div class="label-left"></div>');
s.push('<div class="label-center" ');s.push(item_should_have_title()?"title='"+item_label(c)+"'":"");s.push('>');s.push(item_label(c,true));s.push('</div>');
s.push('<div class="label-right"></div>');
s.push('</div>');
s.push('</div>');
last_item_label=c;
}
s.push('</div>');
}
s.push('</div>');
return s.join('');
}
GridScrollWidget.prototype._render_no_items=function(item){
var s=[];
s.push('<div class="scroll_item">');
s.push('<center>');
s.push('<div>');
if(this._is_charity_store){
s.push('There are no items for sale in this charity store.');
}else{
var vertical=this._view._data_source_options.vertical
if(this._view._data_source_options.search_query){
s.push('There are no items that match your query.');
}else if(!vertical){
s.push('You have no items in your collection.');
}else if(vertical){
s.push('You have no ');s.push(vertical);s.push('.');
}
}
s.push('</div>');
s.push('<center>');
s.push('</div>');
return s.join('');
}
var GluGridScrollWidget=Class.create(GridScrollWidget,{
initialize:function($super,element,view,item_size,start_page,storefront_id,is_charity_store){
$super(element,view,item_size,start_page,is_charity_store);
this._storefront_id=storefront_id;
},
_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;
function on_data_ready(data){
if(this._view._is_wrong_search_query(data))return;
var total_items=Math.ceil(data.total/this._item_size);
var pages=[];
if(data&&data.glus.size()==0){
pages.push({page_index:0,items:[this._render_no_items()]});
}else{
var items=data.glus;
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);
if(start<items.size()){
this._page_to_first_listing_id[c]=items[start].id;
pages.push({page_index:c,items:[this._glu_html(items.slice(start,stop))]});
}
}
}
(callback||this._on_pages_ready.bind(this))(pages,total_items);
this._on_listings_loaded(this._page_to_first_listing_id[this.current_page],data);
}
this._view._data_source_options.offset=item_start*this._item_size;
this._view._data_source_options.limit=(item_end-item_start)*this._item_size;
this._view.data_source.find(this._view._data_source_options,on_data_ready.bind(this));
}
});
GluGridScrollWidget.prototype._glu_html=function(item){
var s=[];
var last_item_label=null;
var data_source_options=this._view._data_source_options;
function needs_item_label(index){
if(index==0){
return true;
}
switch(data_source_options.sort_by){
case'title':
case'creator':
case'item_type':
case'sell':
case'type':
case'condition':
case'status':
case'comps':
case'price':
if(item_label(last_item_label)!=item_label(index)){
return true;
}
break;
}
return false;
}
function item_should_have_title(index){
var should_have_title=false;
switch(data_source_options.sort_by){
case'title':
break;
case'creator':
break;
case'item_type':
should_have_title=true;
break;
case'sell':
break;
case'type':
break;
case'condition':
break;
case'comps':
break;
case'price':
break;
case'status':
break;
}
return should_have_title;
}
function item_label(index,truncate){
var label='';
var glu=item[index];
switch(data_source_options.sort_by){
case'title':
label=glu.sort_chars.toUpperCase();
break;
case'creator':
var creator=glu.creator?glu.creator:'';
label=creator.charAt(0).toUpperCase();
break;
case'item_type':
var type_for_vertical=glu.type_for_vertical||'';
label=type_for_vertical;
if(truncate){
label=type_for_vertical.truncate_with_delimiters(20);
}
break;
case'type':
label=Glyde.glu.friendly_vertical_name(glu.vertical,true);
break;
case'price':
label=PriceAdjuster.dollars_and_cents(glu.cents,true);
break;
case'rank':
label=null
break;
}
return label;
}
s.push('<div class="scroll_item">');
for(var c=0;c<item.length;c++){
s.push('<div class="item">');
s.push('');s.push(this._render_glu(item[c]));s.push('');
if(needs_item_label(c)){
s.push('<div class="label_wrapper">');
s.push('<div class="label">');
var label=item_label(c,true)
if(label!=null){
s.push('<div class="label-left"></div>');
s.push('<div class="label-center" ');s.push(item_should_have_title()?"title='"+item_label(c)+"'":"");s.push('>');s.push(label);s.push('</div>');
s.push('<div class="label-right"></div>');
}
s.push('</div>');
s.push('</div>');
last_item_label=c;
}
s.push('</div>');
}
s.push('</div>');
return s.join('');
}
GluGridScrollWidget.prototype._render_glu=function(glu){
var s=[];
var dims=Glyde.image.cover_dimensions_for_max_w_h(glu,100,140);
var image_url=Glyde.image.fully_qualified_cover_url_for_max_w_h(glu,100,140,'d');
s.push('<div class="img_buffer" style="background-image: url(\'');s.push(image_url);s.push('\');">');
s.push('<div class="item_img" id="item_img_');s.push(glu.id);s.push('"');
s.push('style="background-image: url(\'');s.push(image_url);s.push('\'); width:');s.push(dims.width);s.push('px; height:');s.push(dims.height);s.push('px;"title="');s.push(glu.title);s.push('">');
if(glu.msrp_percent_off){
s.push('<div class="sticker save_sticker small_save percent_');s.push(glu.msrp_percent_off);s.push('"></div>');
}
s.push('</div>');
s.push('</div>');
if(true||Glyde.page.is_buydown_store(this._storefront_id)){
s.push('<div class="scroll_item_info">');
s.push('');s.push('$'+PriceAdjuster.dollars_and_cents(glu.lowest_price_cents,true));s.push('');
s.push('</div>');
}
return s.join('');
}
AddBulkItemDialog=Class.create(Glyde.Dialog,{
PARENT_BUTTON_ID:'add_button',
GENERIC_ERROR:'The item could not be added at this time. Please try again later',
GENERIC_CONDITION_DESCRIPTIONS:[
'Factory sealed. Never opened. Appropriate for retail.',
'Item is fully intact and functional. Original cover or case has no more than a few minor scratches. No personal markings. Not a previous library book or rental.',
'Visible wear but item can be read or watched perfectly. May be missing dust jacket or not have original case or art. May be a former library book or rental.',
'Considerable wear, but readable. All pages and cover intact. May have writing, highlighting, folded or yellowed pages. Dust jacket may be missing. May be a former library book.',
'Disc plays perfectly. No case. Original copyrighted work. May be a former rental.'
],
EVENT_LISTING_ADDED:'AddBulkItemDialog:liting_added',
initialize:function(on_add){
var opts={is_light:true,on_enter_key:this._add_by_enter_key.bind(this)}
Glyde.Dialog.prototype.initialize.call(this,opts);
this._should_center=false;
this._use_arrow=true;
this._use_small_close=true;
this.on_add=on_add||Glyde.empty_function;
},
open:function(){
Glyde.Dialog.prototype.open.call(this,$(this.PARENT_BUTTON_ID),this._to_html());
this._on_condition_change();
$('add_item_condition').observe('change',this._on_condition_change.bindAsEventListener(this));
$('add_item_quantity').value=1;
$('add_item_product_id').focus();
},
close:function(){
InputErrorNotice.clear_all();
Glyde.Dialog.prototype.close.call(this);
},
current_state:function(params){
if(this.is_open()){params.add_open=true;}
return params;
},
restore_from_state:function(params){
if(params.add_open=='true'){
this.open();
}else if(this.is_open()){
this.close();
}
},
_add_by_enter_key:function(){
this.add_button_click();
},
add_button_click:function(){
InputErrorNotice.clear_all();
var errors=this._validate_form();
if(errors){
this._display_errors(errors);
return;
}
this._send_add_item_request();
},
cancel_button_click:function(){
this.close();
},
_send_add_item_request:function(){
var options={
method:'post',
parameters:this._add_item_form_parameters(),
onSuccess:function(resp,o){
this._on_end_add_request();
var json=resp.responseJSON;
if(json.success){
this._on_add_item_success(json);
}else{
if(json.errors){
this._display_errors(json.errors);
}else{
Glyde.page.flash_notice(this.GENERIC_ERROR);
}
}
}.bind(this),
onFailure:function(resp,o){
this._on_end_add_request();
Glyde.page.flash_notice(this.GENERIC_ERROR);
}.bind(this)
}
new Ajax.Request('/stores/'+g_collection.user_id+'/uploads/create_listing.js',options);
this._on_start_add_request();
},
_add_item_form_parameters:function(){
var normalized_product_id=$('add_item_product_id').value.replace(/[- ]/g,'');
var params={
product_id:normalized_product_id
};
['external_sku','condition','price','quantity'].each(function(field_name){
params[field_name]=$('add_item_'+field_name).value;
});
return params;
},
_on_start_add_request:function(){
Loading.show();
this._disable_add_item_form();
},
_on_end_add_request:function(){
Loading.hide();
this._enable_add_item_form();
},
_on_add_item_success:function(json){
Glyde.notify.publish(this.EVENT_LISTING_ADDED,json);
this._reset_add_item_form();
},
_on_condition_change:function(event){
var selected_value=$('add_item_condition').value;
$('condition_info_icon').title=this.GENERIC_CONDITION_DESCRIPTIONS[selected_value-1];
},
_enable_add_item_form:function(){
$('add_item_form').enable();
Glyde.dom.enable_link('add_item_button','add_button_disabled');
Glyde.dom.enable_link('cancel_item_button','cancel_button_disabled')
},
_disable_add_item_form:function(){
$('add_item_form').disable();
Glyde.dom.disable_link('add_item_button','add_button_disabled');
Glyde.dom.disable_link('cancel_item_button','cancel_button_disabled')
},
_reset_add_item_form:function(){
$('add_item_form').getInputs().each(function(input_element){
input_element.value='';
});
$('add_item_quantity').value=1;
$('add_item_product_id').focus();
},
_validate_form:function(){
var errors=this._validate_fields_are_not_empty();
if(errors){return errors;}
return this._validate_fields_content();
},
_validate_fields_are_not_empty:function(){
var errors=[];
var field_names_map={
'add_item_product_id':'UPC or ISBN code',
'add_item_external_sku':'SKU',
'add_item_price':'price',
'add_item_quantity':'quantity'
}
$H(field_names_map).keys().each(function(text_field_id){
var value=$(text_field_id).value;
if(value.length==0){
var field_string=field_names_map[text_field_id];
var error_string='Enter the item '+field_string;
errors.push(this._create_error(text_field_id,error_string));
}
}.bind(this));
['add_item_quantity','add_item_price'].each(function(numeric_field_id){
if($(numeric_field_id).value=='0'){
errors.push(this._create_error(numeric_field_id,'Enter a non-zero value'))
}
}.bind(this));
return errors.length?errors:null;
},
_validate_fields_content:function(){
var errors=[];
if(!Glyde.is_valid.upc($('add_item_product_id').value)){
errors.push(this._create_error('add_item_product_id','This field must be a 10-13 digit number'));
}
if(!Glyde.is_valid.external_sku($('add_item_external_sku').value)){
errors.push(this._create_error('add_item_external_sku','This field must contain 2 or more characters'));
}
if(!Glyde.is_valid.money_string($('add_item_price').value)){
errors.push(this._create_error('add_item_price','This field must contain a monetary value, e.g \'3.50\''))
}
if(isNaN(parseInt($('add_item_quantity').value),10)){
errors.push(this._create_error('add_item_quantity','This field must contain a number'))
}
return(errors.length)?errors:null;
},
_create_error:function(id,error_string){
return{id:id,value:error_string};
},
_display_errors:function(errors){
for(var i=0;i<errors.length;++i){
if(!/^add_item_/.test(errors[i].id)){
errors[i].id='add_item_'+errors[i].id;
}
}
InputErrorNotice.create_all_no_load(errors);
InputErrorNotice.focusFirstError();
},
_position:function(target){
var targ_pos=target.cumulativeOffset();
var targ_dims=target.getDimensions();
var dialog_container=$(this._dialog_container_id);
var style=dialog_container.style;
var vertical_padding=(Browser.IE6)?2:10;
style.top=(targ_pos.top+targ_dims.height+vertical_padding)+'px';
style.left=(targ_pos.left-16)+'px';
},
_position_arrow:function(target,arrow){
arrow.style.left='18px';
}
});
AddBulkItemDialog.prototype._to_html=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="common_dialog"');_j.s(' id="add_bulk_item_dialog"');_j.s('>');
_j.ns('<div');_j.s(' class="title"');_j.s('>');
_j.ns('Add Item');
_j.ns('</div>');
_j.ns('<form');_j.s(' id="add_item_form"');_j.s(' onsubmit="'+('return false;')+'"');_j.s('>');
_j.ns('<div');_j.s(' class="field"');_j.s('>');
_j.ns('<label');_j.s(' for="'+('add_item_upc')+'"');_j.s('>UPC/ISBN');
_j.ns('</label>');
_j.ns('<input');_j.s(' class="value"');_j.s(' id="add_item_product_id"');_j.s(' type="'+('text')+'"');_j.s(' name="'+('product_id')+'"');_j.s(' tabIndex="'+('1')+'"');_j.s('>');
_j.ns('</input>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="field"');_j.s('>');
_j.ns('<label');_j.s(' for="'+('add_item_sku')+'"');_j.s('>SKU');
_j.ns('</label>');
_j.ns('<input');_j.s(' class="value"');_j.s(' id="add_item_external_sku"');_j.s(' type="'+('text')+'"');_j.s(' name="'+('external_sku')+'"');_j.s(' tabIndex="'+('2')+'"');_j.s('>');
_j.ns('</input>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="field"');_j.s('>');
_j.ns('<label');_j.s(' for="'+('add_item_condition')+'"');_j.s(' id="'+('condition_label')+'"');_j.s('>Condition');
_j.ns('</label>');
_j.ns('<img');_j.s(' id="condition_info_icon"');_j.s(' src="'+('../../images/information.png')+'"');_j.s(' />');
_j.ns('<select');_j.s(' class="value"');_j.s(' id="add_item_condition"');_j.s(' name="'+('condition')+'"');_j.s(' tabIndex="'+('3')+'"');_j.s('>');
_j.ns('<option');_j.s(' value="'+('1')+'"');_j.s('>New');
_j.ns('</option>');
_j.ns('<option');_j.s(' value="'+('2')+'"');_j.s('>Excellent');
_j.ns('</option>');
_j.ns('<option');_j.s(' value="'+('3')+'"');_j.s('>Good');
_j.ns('</option>');
_j.ns('<option');_j.s(' value="'+('4')+'"');_j.s('>Acceptable (Books only)');
_j.ns('</option>');
_j.ns('<option');_j.s(' value="'+('5')+'"');_j.s('>Disc/Cartridge Only');
_j.ns('</option>');
_j.ns('</select>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="field"');_j.s('>');
_j.ns('<label');_j.s(' for="'+('add_item_price')+'"');_j.s('>Price');
_j.ns('</label>');
_j.ns('<input');_j.s(' class="value"');_j.s(' id="add_item_price"');_j.s(' type="'+('text')+'"');_j.s(' name="'+('price')+'"');_j.s(' tabIndex="'+('4')+'"');_j.s('>');
_j.ns('</input>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="field"');_j.s('>');
_j.ns('<label');_j.s(' for="'+('quantity')+'"');_j.s('>Quantity');
_j.ns('</label>');
_j.ns('<input');_j.s(' class="value"');_j.s(' id="add_item_quantity"');_j.s(' type="'+('text')+'"');_j.s(' name="'+('quantity')+'"');_j.s(' tabIndex="'+('5')+'"');_j.s('>');
_j.ns('</input>');
_j.ns('</div>');
_j.ns('</form>');
_j.ns('<div');_j.s(' class="small_buttons_row"');_j.s('>');
_j.ns('<a');_j.s(' class="cancel_button"');_j.s(' id="cancel_item_button"');_j.s(' href="'+('javascript: void(0)')+'"');_j.s(' onclick="'+('Collection.get_instance()._add_item_dialog.cancel_button_click()')+'"');_j.s('>');
_j.ns('</a>');
_j.ns('<a');_j.s(' class="add_button"');_j.s(' id="add_item_button"');_j.s(' href="'+('javascript: void(0)')+'"');_j.s(' onclick="'+('Collection.get_instance()._add_item_dialog.add_button_click()')+'"');_j.s('>');
_j.ns('</a>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
UpdatePriceDialog=Class.create(Glyde.Dialog,{
EVENT_PRICE_UPDATED:'UpdatePriceDialog:listing_updated',
initialize:function(on_add){
var opts={is_light:true,on_enter_key:this._update_by_enter_key.bind(this)}
Glyde.Dialog.prototype.initialize.call(this,opts);
this._should_center=false;
this._use_arrow=true;
this._use_small_close=true;
this.on_add=on_add||Glyde.empty_function;
},
open:function(target_id,listing){
this._listing=listing;
Glyde.Dialog.prototype.open.call(this,$(target_id),this._to_html());
var q_input=$('update_price_quantity');
q_input.value=listing.attrs.quantity;
var price_input=$('update_price_price');
var cents=listing.attrs.bs_original_price_cents;
if(cents){
price_input.value=PriceAdjuster.dollars_and_cents(cents,true);
price_input.select();
}
price_input.focus();
},
close:function(){
InputErrorNotice.clear_all();
Glyde.Dialog.prototype.close.call(this);
},
_update_by_enter_key:function(){
this.update_button_click();
},
update_button_click:function(){
InputErrorNotice.clear_all();
var errors=this._validate_form();
if(errors){
this._display_errors(errors);
return;
}
var options={
method:'post',
parameters:{
price:$('update_price_price').value,
quantity:$('update_price_quantity').value,
external_sku:this._listing.attrs.bs_external_sku
},
onComplete:function(resp,o){
var data=resp.responseJSON;
if(data&&data.success){
Glyde.notify.publish(this.EVENT_PRICE_UPDATED,data);
this.close();
}else{
this._display_errors(data.errors)
}
}.bind(this)
};
var url='/stores/'+g_collection.user_id+'/uploads/update_listing_price';
new Ajax.Request(url,options);
},
_validate_form:function(){
var errors=[];
var updated_price=$('update_price_price').value;
if(updated_price.length==0){
errors.push(this._create_error('update_price_price','Enter an updated price'));
}else if(!Glyde.is_valid.money_string(updated_price)){
errors.push(this._create_error('update_price_price','Enter a monetary value, e.g \'3.50\''));
}
return errors.length?errors:null;
},
_create_error:function(id,error_string){
return{id:id,value:error_string};
},
_display_errors:function(errors){
var i=0;
for(i;i<errors.length;++i){
if(errors[i].id=='price')errors[i].id='update_price_price';
}
InputErrorNotice.create_all_no_load(errors);
InputErrorNotice.focusFirstError();
},
_dialog_px_left_from_target:function(){
if(Browser.IE){
return 36;
}
return 0;
}
});
UpdatePriceDialog.prototype._to_html=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="common_dialog"');_j.s(' id="update_price_dialog"');_j.s('>');
_j.ns('<div');_j.s(' class="title"');_j.s('>');
_j.ns('Update Price');
_j.ns('</div>');
_j.ns('<form');_j.s(' id="update_price_form"');_j.s(' onsubmit="'+('return false;')+'"');_j.s('>');
_j.ns('<div');_j.s(' class="field"');_j.s('>');
_j.ns('<label');_j.s(' for="'+('update_price_price')+'"');_j.s('>Price');
_j.ns('</label>');
_j.ns('<input');_j.s(' class="value"');_j.s(' id="update_price_price"');_j.s(' type="'+('text')+'"');_j.s(' name="'+('price')+'"');_j.s(' tabIndex="'+('1')+'"');_j.s('>');
_j.ns('</input>');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="field"');_j.s('>');
_j.ns('<label');_j.s(' for="'+('update_price_quantity')+'"');_j.s('>Quantity');
_j.ns('</label>');
_j.ns('<input');_j.s(' class="value"');_j.s(' id="update_price_quantity"');_j.s(' type="'+('text')+'"');_j.s(' name="'+('quantity')+'"');_j.s(' tabIndex="'+('2')+'"');_j.s('>');
_j.ns('</input>');
_j.ns('</div>');
_j.ns('</form>');
_j.ns('<div');_j.s(' class="small_buttons_row"');_j.s('>');
_j.ns('<a');_j.s(' class="cancel_button"');_j.s(' id="cancel_item_button"');_j.s(' href="'+('javascript: void(0)')+'"');_j.s(' onclick="'+('Collection.get_instance()._update_price_dialog.close()')+'"');_j.s('>');
_j.ns('</a>');
_j.ns('<a');_j.s(' class="update_button"');_j.s(' id="update_price_button"');_j.s(' href="'+('javascript: void(0)')+'"');_j.s(' onclick="'+('Collection.get_instance()._update_price_dialog.update_button_click()')+'"');_j.s('>');
_j.ns('</a>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
var BulkSellerImportDialog=Class.create(Glyde.Dialog,{
ANCHOR_ID:'import_button',
EVENT_UPLOAD_FINISHED:'bs_upload_finished',
initialize:function(report_name,display_name,user_id,on_upload_finished){
Glyde.Dialog.prototype.initialize.call(this,{is_light:true});
this._user_id=user_id;
this._report_name=report_name;
this._display_name=display_name;
this._should_center=false;
this._use_arrow=true;
this._use_small_close=true;
this.on_upload_finished=on_upload_finished||Glyde.empty_function;
},
open:function(){
Glyde.Dialog.prototype.open.call(this,$(this.ANCHOR_ID),this._to_html());
this._add_hidden_iframe();
this._setup_onclick_handlers();
},
close:function(){
InputErrorNotice.clear_all();
Glyde.Dialog.prototype.close.call(this);
},
_add_hidden_iframe:function(){
var iframe=$('hidden_upload_frame');
if(!iframe){
iframe=document.createElement('iframe');
iframe.name='hidden_upload_frame';
iframe.id='hidden_upload_frame';
iframe.className='offscreen';
document.body.appendChild(iframe);
}
},
_setup_onclick_handlers:function(){
$('bs_import_button').onclick=this._handle_upload_click.bind(this)
},
_handle_upload_click:function(){
var selected_file_name=$('bs_import_attachment_attributes_uploaded_data').value;
if(selected_file_name==''){
this._show_file_input_error('Select a file to import');
return;
}
InputErrorNotice.clear_all();
Glyde.page.update_submit_button('bs_import_button',
this.submit_form.bind(this),true,
'import_button_disabled');
},
_show_file_input_error:function(error_string){
var file_input_id='bs_import_attachment_attributes_uploaded_data';
var error={
id:file_input_id,
value:error_string
};
InputErrorNotice.create_all_no_load([error]);
if(Browser.FF3){
InputErrorNotice.all[0]._display_note();
}else{
InputErrorNotice.focusFirstError();
}
},
_display_errors:function(errors){
for(var i=0;i<errors.length;++i){
if(!/^add_item_/.test(errors[i].id)){
errors[i].id='add_item_'+errors[i].id;
}
}
InputErrorNotice.create_all_no_load(errors);
InputErrorNotice.focusFirstError();
},
submit_form:function(){
Glyde.page.server_API.upload_callback=this._upload_finished.bind(this);
var udata=$('bs_import_attachment_attributes_uploaded_data');
if(udata.value.blank()){
this._upload_finished();
}else{
var form=$('bs_import_form');
form.appendChild(Glyde.page.server_API.hidden_input_for_iframe_pipe());
var controller=null;
switch(this._report_name){
case'BulkSellerShippingInfo':
controller='bulk_seller_shipping_infos';
break;
case'BulkSellerBatchRefund':
controller='bulk_seller_batch_refunds';
break;
case'BulkSellerUpload':
controller='uploads';
break;
}
form.action='/stores/'+this._user_id+'/'+controller+'/upload';
form.submit();
}
},
_upload_finished:function(json){
Glyde.page.reset_submit_button('bs_import_button','import_button_disabled');
Glyde.page.server_API.upload_callback=null;
this.on_upload_finished(json);
this.close();
},
_position:function(target){
var targ_pos=target.cumulativeOffset();
var targ_dims=target.getDimensions();
var dialog_container=$(this._dialog_container_id);
var style=dialog_container.style;
var vertical_padding=(Browser.IE6)?2:10;
style.top=(targ_pos.top+targ_dims.height+vertical_padding)+'px';
style.left=(targ_pos.left-16)+'px';
},
_position_arrow:function(target,arrow){
arrow.style.left='16px';
}
});
BulkSellerImportDialog.prototype._to_html=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="common_dialog"');_j.s(' id="bulk_import_dialog"');_j.s('>');
_j.ns('<div');_j.s(' class="title"');_j.s('>');
_j.ns(this._display_name+' Import');
_j.ns('</div>');
_j.ns('<form');_j.s(' id="bs_import_form"');_j.s(' enctype="'+("multipart/form-data")+'"');_j.s(' target="'+("hidden_upload_frame")+'"');_j.s(' method="'+("POST")+'"');_j.s(' onsubmit="'+("return false")+'"');_j.s('>');
_j.ns('<div');_j.s(' class="field"');_j.s('>');
_j.ns('<input');_j.s(' class="file_input"');_j.s(' id="bs_import_attachment_attributes_uploaded_data"');_j.s(' type="'+("file")+'"');_j.s(' name="'+("import_file")+'"');_j.s('>');
_j.ns('</input>');
_j.ns('<input');_j.s(' id="bs_import_type"');_j.s(' type="'+("hidden")+'"');_j.s(' name="'+("import_type")+'"');_j.s(' value="'+(this._report_name)+'"');_j.s('>');
_j.ns('</input>');
_j.ns('</div>');
_j.ns(this._render_import_import_text_which_no_one_reads());
_j.ns('<p');_j.s('>');
_j.ns(this._render_import_template_junk());
_j.ns('</p>');
_j.ns('</form>');
_j.ns('<div');_j.s(' class="small_buttons_row"');_j.s('>');
_j.ns('<a');_j.s(' class="import_button"');_j.s(' id="bs_import_button"');_j.s(' href="'+('javascript: void(0)')+'"');_j.s(' onclick="'+('')+'"');_j.s('>');
_j.ns('</a>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
BulkSellerImportDialog.prototype._render_import_import_text_which_no_one_reads=function(){
var _j=new Jaml();
_j.ns('<p');_j.s('>');
if(this._report_name=='BulkSellerUpload'){
_j.ns('Choose the tab-delimited file you want to import.');
_j.ns(Glyde.company_name);
_j.ns('will place all your items that contain valid ISBNs or UPCs into your inventory.');
}
else if(this._report_name=='BulkSellerShippingInfo'){
_j.ns('Choose the tab-delimited shipping info file you want to import.');
}
else if(this._report_name=='BulkSellerBatchRefund'){
_j.ns('Choose the tab-delimited batch refund file you want to import.');
}
_j.ns('</p>');
return _j.v();
};
BulkSellerImportDialog.prototype._render_import_template_junk=function(){
var _j=new Jaml();
_j.ns('<p');_j.s('>');
if(this._report_name=='BulkSellerUpload'){
_j.ns('<a');_j.s(' href="'+('html/bulk_seller_templates/inventory_template.txt')+'"');_j.s('>Download');
_j.ns('</a>');
}
else if(this._report_name=='BulkSellerShippingInfo'){
_j.ns('<a');_j.s(' href="'+('html/bulk_seller_templates/shipping_info_template.txt')+'"');_j.s('>Download');
_j.ns('</a>');
}
else if(this._report_name=='BulkSellerBatchRefund'){
_j.ns('<a');_j.s(' href="'+('html/bulk_seller_templates/batch_refund_template.txt')+'"');_j.s('>Download');
_j.ns('</a>');
}
_j.ns('import template (tab-delimited)');
_j.ns('</p>');
return _j.v();
};
var InventoryPage=Class.create(Collection,{
initialize:function($super){
$super();
},
onload:function($super,params,is_back){
return $super(params,is_back);
},
_setup_dialogs:function(){
var add_item_callback=this._add_new_listing_remote.bind(this);
this._add_item_dialog=new AddBulkItemDialog(add_item_callback);
this.listing_dialog=new ListingDialog();
this.share_dialog=new ShareDialog();
},
_setup_css_class_names:function($super){
$super();
$('collection').addClassName('inventory');
},
_create_import_dialog:function(){
return new BulkSellerImportDialog('BulkSellerUpload','Inventory',null,
this._handle_upload_finished.bind(this))
},
_handle_upload_finished:function(json){
console.log("UPLOAD FINISHED: ",json);
Glyde.page.flash_notice("Your upload is being processed");
}
});
var CollectionPage=Class.create(Collection,{
initialize:function($super){
$super();
},
onload:function($super,params,is_back){
return $super(params,is_back);
}
});
var PublicCollectionPage=Class.create(Collection,{
initialize:function($super){
$super();
},
onload:function($super,params,is_back){
return $super(params,is_back);
},
_setup_sort_select_options:function(){
var sort_options=[
{value:'title'},
{value:'creator'},
{value:'item_type',display_value:'subtype'},
{value:'status'},
{value:'condition'},
{value:'price',display_value:(this.is_owner_state()?'your price':'market price')}
];
return sort_options;
},
_setup_css_class_names:function(){
if(!this.is_owner_state()){
$('collection').addClassName('viewer');
}
}
});
var StorePage=Class.create(Collection,{
auto_refresh_interval:5*(60*1000),initialize:function($super){
$super();
this.auto_refresh_interval=30*1000;
},
onload:function($super,params,is_back){
return $super(params,is_back);
},
restart_refresh_timer:function(){
return;
},
current_state:function($super,params){
params=$super(params);
delete params.sort_by;
delete params.sort_dir;
if(this._data_source_options.category!=null){
params.cat=this._data_source_options.category;
}
return params;
},
restore_from_state:function($super,params){
if(params.cat)this._data_source_options.category=params.cat;
return $super(params);
},
_setup_header:function($super){
if(this.is_charity_store()){
this._charity_info_dialog=new CharityInfoDialog($('collection_title'));
this._charity_search=new CharitySearchWidget($$('#collection .search_box')[0],285,38,'find a charity store...');
Glyde.notify.subscribe(this._charity_search.EVENT_CHARITY_SELECTED,this._on_charity_selected.bind(this));
}else{
$super();
}
},
_on_charity_selected:function(event_name,event_info){
var selected_store_url='/charities/'+this._charity_name_for_url(event_info.name);
location.href=selected_store_url;
},
_charity_name_for_url:function(charity_name){
return charity_name.toLowerCase().gsub(/[.'"]/,'').gsub(/[^-0-9a-z]+/,'_');
},
_setup_dialogs:function(){
var add_item_callback=this._add_new_listing_remote.bind(this);
this._add_item_dialog=new AddItemDialog(add_item_callback);
this.listing_dialog=new TransactionDialog(this.card_issuers);
this.share_dialog=new ShareDialog();
},
_setup_views:function(){
this.list_view=null;
this.grid_view=new StoreView('grid_view',this.id,this.is_charity_store());
},
_setup_selector:function(){
this.genre_selector=new GenreSelector(g_collection.available_categories);
Glyde.notify.subscribe(this.genre_selector.MESSAGE_SELECT_CHANGED,this._on_genre_selector_change.bind(this));
},
_on_genre_selector_change:function(msg_name,info){
this._data_source_options.vertical=info.vertical;
this._data_source_options.category=info.category;
this._data_source_options.offset=0;
this._data_source_options.limit=this.PAGE_SIZE;
this.display();
},
_sync_selector_ui:function(){
this.genre_selector.select(this._data_source_options.vertical,this._data_source_options.category);
},
_set_sort_options:function(sort_by){
this._set_default_sort_options();
},
_set_default_sort_options:function(){
this._data_source_options.sort_by='rank';
this._data_source_options.sort_direction=1;
},
_should_show_invite_notice:function(){
return false;
},
_setup_css_class_names:function($super){
$super();
$('collection').addClassName('store');
var icon_path='/images/bulk_seller/'+this.user_id+'.png';
if(Browser.IE6){
$('collection_icon').setStyle({filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+icon_path+"', sizingMethod='crop')"});
}else{
$('collection_icon').setStyle({backgroundImage:'url('+icon_path+')'});
}
},
_update_market_value:function(data){
}
});
var GenreSelector=Class.create({
MESSAGE_SELECT_CHANGED:'genre_selector:select_changed',
initialize:function(available_categories){
this._available_categories=$H(available_categories);
this._create_genre_select();
},
NONFICTION_CATEGORIES:['biographies_nonfiction','business_nonfiction','childrens_nonfiction','computers_nonfiction','historical_nonfiction','politics_nonfiction','food_wine_nonfiction','religion_nonfiction','wellness_nonfiction'],
OTHER_CATEGORIES:['arts_photos_nonfiction','entertainment_nonfiction','home_garden_nonfiction','professional_nonfiction','science_nonfiction','social_science_nonfiction','sports_nonfiction','textbooks_nonfiction','travel_nonfiction'],
FICTION_CATEGORIES:['childrens_fiction','graphic_novels_fiction','historical_fiction','humor_fiction','literature_fiction','mystery_thriller_fiction','romance_fiction','scifi_fiction','sports_fiction','westerns_fiction'],
get_genre_menu:function(available_categories){
var config=[];
config.push([{text:'all items',value:{key:'all_items',vertical:null,category:null,selected_text:'all items'}}]);
category_for_display=this._category_for_display.bind(this);
vertical_config=available_categories.map(function(pair){
var vertical=pair.key;
var categories=pair.value;
var display_vertical=Glyde.glu.friendly_vertical_name(vertical,true);
var category_menu=[];
if(vertical=='games'){
category_menu=[{text:'all consoles',value:{key:'all_'+vertical,vertical:vertical,category:null,selected_text:'all consoles'}}];
}else{
category_menu=[{text:'all genres',value:{key:'all_'+vertical,vertical:vertical,category:null,selected_text:'all '+display_vertical}}];
}
if(vertical=='books'){
category_menu=category_menu.concat(this._construct_book_category_menu(categories));
}else{
category_menu.push(categories.sort().map(this._category_to_menu_hash.bind(this,vertical)));
}
return{
text:display_vertical,
value:{key:vertical,vertical:vertical,category:null,selected_text:display_vertical},
submenu:{
id:YAHOO.util.Dom.generateId(null,'menu'),
itemdata:category_menu
}
};
}.bind(this));
config.push(vertical_config);
return{items:config,titles:null};
},
_construct_book_category_menu:function(categories){
var category_menu=[];
var fiction_cats=categories.grep(/_fiction/);
if(fiction_cats.length>0){
var fiction_menu=[{text:'all fiction',value:{key:'fiction_books',vertical:'books',category:'fiction',selected_text:'all fiction books'}}];
var fiction_menu_cats=fiction_cats.select(function(c){
return this.FICTION_CATEGORIES.indexOf(c)!=-1;
}.bind(this)).sort();
fiction_menu.push(fiction_menu_cats.sort().map(this._category_to_menu_hash.bind(this,'books')));
category_menu.push(fiction_menu.flatten());
}
var nonfiction_cats=categories.grep(/_nonfiction/);
if(nonfiction_cats.length>0){
var nonfiction_menu=[{text:'all nonfiction',value:{key:'nonfiction_books',vertical:'books',category:'nonfiction',selected_text:'all nonfiction books'}}];
var nonfiction_menu_cats=nonfiction_cats.select(function(c){
return this.NONFICTION_CATEGORIES.indexOf(c)!=-1;
}.bind(this)).sort();
nonfiction_menu.push(nonfiction_menu_cats.sort().map(this._category_to_menu_hash.bind(this,'books')));
nonfiction_menu=nonfiction_menu.flatten();
other_nonfiction_cats=nonfiction_cats.select(function(c){
return this.OTHER_CATEGORIES.indexOf(c)!=-1;
}.bind(this)).sort();
if(other_nonfiction_cats.length>0){
nonfiction_menu.push({text:'&nbsp;&nbsp;other',
value:{key:'other_books',vertical:'books',category:'other',selected_text:'other books'},
submenu:{
id:YAHOO.util.Dom.generateId(null,'menu'),
itemdata:other_nonfiction_cats.map(this._category_to_menu_hash.bind(this,'books'))
}});
}
category_menu.push(nonfiction_menu.flatten());
}
return category_menu;
},
_category_to_menu_hash:function(vertical,category){
var display_cat=this._category_for_display(vertical,category);
var text=(vertical=='books'?'&nbsp;&nbsp;':'')+display_cat;
var display_vertical=Glyde.glu.friendly_vertical_name(vertical,true);
var selected_text=display_cat+' '+display_vertical;
return{text:text,value:{key:category+'_'+vertical,vertical:vertical,category:category,selected_text:selected_text}};
},
selected_vertical:function(){
return this.genre_select.selected_item().value.vertical;
},
selected_category:function(){
return this.genre_select.selected_item().value.category;
},
select:function(vertical,category){
category=category||'all';
vertical=vertical||'items';
var key=category+'_'+vertical;
this.genre_select.select(key);
},
_create_genre_select:function(){
if(this.genre_select){
this.genre_select.stopObserving('select_widget:change',this._genre_select_observer);
}
this.genre_select=new SelectWidget($('genre_select'),this.get_genre_menu(this._available_categories));
this._genre_select_observer=this._on_genre_select_change.bindAsEventListener(this);
this.genre_select.observe('select_widget:change',this._genre_select_observer);
},
_on_genre_select_change:function(event){
Glyde.notify.publish(this.MESSAGE_SELECT_CHANGED,{vertical:this.selected_vertical(),category:this.selected_category()});
},
CATEGORY_TO_DISPLAY:{
scifi:'sci-fi',
rb:'r&amp;b',
hiphop:'hip hop',
xbox360:'xbox 360',
childrens:"children's",
food_wine:'food &amp; wine',
arts_photos:'arts &amp; photo',
home_garden:'home &amp; garden',
mystery_thriller:'mystery &amp; thriller'
},
_category_for_display:function(vertical,category){
if(vertical=='books'){
if(category=='historical_nonfiction'){
category='history';
}else{
category=category.match(/(.*)_(non)?fiction/)[1];
}
}
category=this.CATEGORY_TO_DISPLAY[category]||category;
if(vertical=='books'){
return category.gsub('_',' ');
}else{
return category;
}
}
});
var OrganizePage=Class.create({
initialize:function(){},
onload:function(params,is_back){
this.controller=null;
switch(g_collection.internal_collection_type){
case'public_collection':
this.controller=new PublicCollectionPage();
break;
case'store':
this.controller=new StorePage();
break;
case'inventory':
this.controller=new InventoryPage();
break;
case'collection':
this.controller=new CollectionPage();
break;
default:
this.controller=new CollectionPage();
break;
}
return this.controller.onload(params,is_back);
},
current_state:function(params){
return this.controller.current_state(params);
},
on_in_page_back:function(params){
return this.controller.on_in_page_back(params);
}
});
var g_organize_page=new OrganizePage();
Glyde.page.register_page(g_organize_page);
CharityInfoDialog=Class.create(Glyde.HoverDialog,{
initialize:function($super,hover_target_id){
$super(hover_target_id);
},
_dialog_px_up_from_target:function(){
return 10;
}
});
CharityInfoDialog.prototype._render=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' id="charity_info_dialog"');_j.s('>');
_j.ns('<h3');_j.s('>');
_j.ns('Buying Never Felt So Good');
_j.ns('</h3>');
_j.ns('<p');_j.s('>');
_j.ns('Support your favorite charity by purchasing pledged items. Enjoy fantastic deals on new and pre-owned DVDs, CDs, video games, and books, and feel great about your purchase - your money is going to a good cause.');
_j.ns('</p>');
_j.ns('<p');_j.s('>');
_j.ns('<a');_j.s(' class="about_charities_link"');_j.s(' href="'+('/about_charity')+'"');_j.s('>');
_j.ns('Click here');
_j.ns('</a>');
_j.ns('to find out more about Glyde Charities.');
_j.ns('</p>');
_j.ns('</div>');
return _j.v();
};
var ShippingAddressSelect=Class.create(SelectWidget,{
MAX_SHORT_ADDRESS_LENGTH:16,
NEW_ADDRESS_KEY:'new_address',
NEW_SHIPPING_ADDDRESS_ADDED_MESSAGE:'new_shipping_address_dialog:address_added',
initialize:function($super,container_id,shipping_addresses,z_index,short_address_max_length){
this._short_address_max_length=(short_address_max_length||
this.MAX_SHORT_ADDRESS_LENGTH);
$super(container_id,{items:this._menu_items(shipping_addresses),titles:null});
var menu_config=this._menu.cfg;
menu_config.setProperty('maxheight',175);
menu_config.setProperty('scrollincrement',2);
if(z_index){menu_config.setProperty("zindex",z_index);}
$(this._menu.element).addClassName('shipping_address_menu');
$(this._menu.getItem(0).element).addClassName('new_address_menu_item')
this.select(this._menu.getItem(0,1).value.key);
this._new_shipping_address_handler=this._on_new_shipping_address.bind(this);
Glyde.notify.subscribe(this.NEW_SHIPPING_ADDDRESS_ADDED_MESSAGE,this._new_shipping_address_handler);
},
destroy:function($super){
Glyde.notify.unsubscribe(this.NEW_SHIPPING_ADDDRESS_ADDED_MESSAGE,this._new_shipping_address_handler);
$super();
},
selected_address:function(){
return{
address_id:this._selected_item.value.key,
cvv2_required:this._selected_item.value.cvv2_required
};
},
on_menu_click:function($super,event_string,args){
var menu_item=args[1];
if(menu_item.value.key==this.NEW_ADDRESS_KEY){
Glyde.notify.publish('shipping_address_select:new_address');
}else{
$super(event_string,args);
}
},
_on_new_shipping_address:function(event_name,address){
address.cvv2_required=true;
this._menu.addItem(this._address_menu_item(address),1);
this._menu.render($('widget_overlays'));
this.select(address.id);
},
_menu_items:function(shipping_addresses){
var items=[];
items.push([{text:'use new address...',value:{key:this.NEW_ADDRESS_KEY,selected_text:''}}]);
items.push(shipping_addresses.inject([],function(array,address){
array.push(this._address_menu_item(address));
return array;
},this));
return items;
},
_address_menu_item:function(address){
return{
text:this._full_address_string(address),
value:{
key:address.id,
cvv2_required:address.cvv2_required,
selected_text:this._short_address_string(address),
tooltip:'Ship to '+this._full_address_string(address,true)
}
};
},
_short_address_string:function(address){
return address.street_1.truncate_with_delimiters(this._short_address_max_length);
},
_full_address_string:function(addr,no_html){
var buffer=[];
var br=(no_html)?' ':'<br/>';
buffer.push(addr.name,',',br,addr.street_1);
if(addr.street_2){buffer.push(',',br,addr.street_2);}
buffer.push(',',br,addr.city,' ',addr.state,' ',addr.zip);
return buffer.join('');
}
});
NewShippingAddressDialog=Class.create(Glyde.Dialog,{
initialize:function($super){
$super();
this.on_open=this._on_open.bind(this);
this._on_enter_key=this._on_submit.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"];
},
open:function($super){
$super(null,this._render());
},
close:function($super){
InputErrorNotice.clear_all();
$super();
},
_on_open:function(){
var container=$(this._container_id);
this._populate_state_select();
container.select('#address_name')[0].focus();
new Glyde.ButtonWidget(container.select('.cancel_button')[0],'Cancel').observe('widget:activate',function(e){this.close();}.bindAsEventListener(this));
this._submit_button=new Glyde.ButtonWidget(container.select('.submit_button')[0],'Ship to this address',{color:'blue'});
this._submit_button.observe('widget:activate',this._on_submit.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(){
this._submit_button.disable();
var options={
method:'post',
parameters:this._add_extra_params(Form.serialize($(this._container_id).select('#address_form')[0],true)),
onComplete:function(resp,o){
this._submit_button.enable();
var json=resp.responseJSON;
if(json.success){
var address=json.address;
Glyde.notify.publish('new_shipping_address_dialog:address_added',{id:address.id,name:address.name,street_1:address.street_1,street_2:address.street_2,city:address.locale.city,state:address.locale.state,zip:address.locale.zip});
this.close();
}else{
this._show_errors(json.errors);
}
}.bind(this)
};
new Ajax.Request('/shipping_addresses',options);
},
_add_extra_params:function(parm_obj){
parm_obj['user[is_admin]']=false;
parm_obj['user[is_glyde]']=true;
parm_obj['user[is_suspended]']=true;
return parm_obj;
},
_show_errors:function(errors){
InputErrorNotice.create_all_no_load(errors);
InputErrorNotice.focusFirstError();
}
});
Glyde.notify.subscribe('shipping_address_select:new_address',function(){(new NewShippingAddressDialog()).open();}.bind(this));
NewShippingAddressDialog.prototype._render=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="new_shipping_address_dialog_content"');_j.s('>');
_j.ns('<h2');_j.s('>New shipping 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="description"');_j.s('>Your purchase will be shipped to this address. Your primary buying (and selling) address will not be changed.');
_j.ns('</div>');
_j.ns('<div');_j.s(' class="buttons"');_j.s('>');
_j.ns('<div');_j.s(' class="cancel_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>');
return _j.v();
};
CvvDialog=Class.create(Glyde.Dialog,{
initialize:function($super,on_close,on_purchase,card_issuer,use_small_close){
var dialog_options={
should_center:false,
use_arrow:true,
position_preference:this.POSITION_ABOVE,
disable_escape:false,
on_close:on_close
};
if(use_small_close){dialog_options.use_small_close=true;}
$super(dialog_options);
this._on_enter_key=this._on_activate_purchase_button.bind(this);
this._on_purchase=on_purchase;
this._card_issuer=card_issuer;
this._num_digits=card_issuer.num_code_digits;
},
open:function($super,target_id){
$super(target_id,this._render());
var cvv_number_input=$('cvv_number_input');
cvv_number_input.allow_only_numeric_input();
cvv_number_input.activate();
var card_image=$('card_image');
Glyde.image.preload(card_image.src,function(){card_image.fade_in(300);});
this._cancel_button=new Glyde.ButtonWidget('cvv_cancel_button','Cancel');
this._cancel_button.observe('widget:activate',this._on_activate_cancel_button.bind(this));
this._purchase_button=new Glyde.ButtonWidget('cvv_purchase_button','Complete Purchase',{color:'blue'});
this._purchase_button.observe('widget:activate',this._on_activate_purchase_button.bind(this));
},
_on_activate_cancel_button:function(){
this.close();
},
_on_activate_purchase_button:function(){
var cvv_value=$('cvv_number_input').value;
var cvv_input_container=$('cvv_input_container');
var error_text;
if(cvv_value.length==0){
var issuer_name=this._card_issuer.name;
var issuer_string=issuer_name+(issuer_name=='MasterCard'?'':' card');
error_text='Enter the '+this._num_digits+' digit security code for your '+issuer_string+'.';
}else if(cvv_value.length!=this._num_digits){
error_text='The security code must be '+this._num_digits+' digits.';
}
if(error_text){
InputErrorNotice.create_all_no_load([{id:'cvv_number_input',value:error_text}]);
InputErrorNotice.focusFirstError();
cvv_input_container.addClassName('cvv_error');
return;
}
InputErrorNotice.clear_all();
cvv_input_container.removeClassName('cvv_error');
if(this._on_purchase){
this.close(true);
this._on_purchase(cvv_value);
}
},
_card_image_url:function(){
var filename_lookup={
'Visa':'visa',
'MasterCard':'mastercard',
'American Express':'amex'
};
return Glyde.image.fully_qualified_url('images/CreditCards/cvv/'+filename_lookup[this._card_issuer.name]+'.png');
},
_dialog_px_left_from_target:function(){
return 280;
},
_position_arrow:function(){
$(this._arrow_id).style.left='344px';
}
});
CvvDialog.prototype._render=function(){
var _j=new Jaml();
_j.ns('<div');_j.s(' class="common_dialog"');_j.s(' id="cvv_dialog"');_j.s('>');
_j.ns('<div');_j.s(' id="cvv_content"');_j.s('>');
_j.ns('<img');_j.s(' id="card_image"');_j.s(' src="'+(this._card_image_url())+'"');_j.s(' />');
_j.ns('<div');_j.s(' class="field"');_j.s('>');
_j.ns('<label');_j.s(' for="'+('cvv_number_input')+'"');_j.s('>');
_j.ns('Security Code');
_j.ns('</label>');
_j.ns('<div');_j.s(' id="cvv_input_container"');_j.s('>');
_j.ns('<input');_j.s(' id="cvv_number_input"');_j.s(' type="'+('text')+'"');_j.s(' name="'+('cvv')+'"');_j.s(' autocomplete="'+('off')+'"');_j.s(' maxlength="'+(this._num_digits)+'"');_j.s('>');
_j.ns('</input>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('<div');_j.s(' id="cvv_instructions"');_j.s('>');
_j.ns('<p');_j.s('>');
_j.ns('For the security of your account, please enter the CVV2 code for your credit card.');
_j.ns('</p>');
_j.ns('<p');_j.s('>');
_j.ns('The code is '+this._num_digits+' digits and is located on the back of the card to the right of the signature strip.');
_j.ns('</p>');
_j.ns('</div>');
_j.ns('<div');_j.s(' id="cvv_buttons_row"');_j.s('>');
_j.ns('<div');_j.s(' id="cvv_purchase_button"');_j.s('>');
_j.ns('</div>');
_j.ns('<div');_j.s(' id="cvv_cancel_button"');_j.s('>');
_j.ns('</div>');
_j.ns('</div>');
_j.ns('</div>');
return _j.v();
};
TransactionCvvDialog=Class.create(CvvDialog,{
initialize:function($super,on_close,on_purchase,card_issuer){
$super(on_close,on_purchase,card_issuer,true);
},
_dialog_px_left_from_target:function(){
return 294;
}
});
var CharitySearchWidget=Class.create(Glyde.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',
LIST_TOP_OFFSET:12,
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,this.LIST_TOP_OFFSET,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,
list_top_offset,
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,list_top_offset,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();
};
var DonationSelectorWidget=Class.create(Glyde.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=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 GlydeCheckbox(checkbox_node);
this.$$first('.checkbox_container').observe('click',this._on_checkbox_click.bindAsEventListener(this));
if(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);
}
});
DonationSelectorWidget.instance_id=0;
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();
};
