YUI.add("flickr-galleries-getPhotos-fetcher",(function(e,o){"use strict";e.namespace("ListFetchers")["flickr-galleries-getPhotos"]={run:function(t,l){var r=this;return e.Promise.all([l.callAPI("flickr.galleries.getPhotos",this._processParams(t),!0),l.getModelRegistry("photo-models"),l.getModelRegistry("person-models"),l.getModelRegistry("gallery-models"),l.getModelRegistry("photo-engagement-models"),l.getModelRegistry("photo-stats-models"),l.getModelRegistry("gallery-info-models"),l.getModelRegistry("gallery-photo-models")]).then((function(e){return r._processResponse(e,t)}),e.FetcherErrorLogger(o))},_processResponse:function(o,t){var l,r=o[0],s=o[1],a=o[2],g=o[3],i=o[4],n=o[5],p=o[6],d=o[7];if(r&&r.gallery)return r.gallery.owner=r.user,r.gallery.title=r.gallery.title&&r.gallery.title.content?r.gallery.title.content:r.gallery.title,r.gallery.description=r.gallery.description&&r.gallery.description.content?r.gallery.description.content:r.gallery.description,r.gallery.photoCount=r.gallery.countPhotos,r.gallery.videoCount=r.gallery.countVideos,e.APIHelper.response.addContextToRegistry(r.gallery,g,a),l=e.APIHelper.response.parsePhotos({photos:r.photos.photo,personModelRegistry:a,photoModelRegistry:s,photoEngagementModelRegistry:i,photoStatsModelRegistry:n}),g.setValue(t.id,"photoPageList",l),p.exists(t.id)&&p.getValue(t.id,"photoList").addPage({page:r.photos.page,perPage:r.photos.perpage,pageContent:l,totalItems:parseInt(r.photos.total||0,10)}),r.photos.photo.forEach((function(e,o){d.addOrUpdate({id:r.gallery.id+"-"+e.id,galleryId:r.gallery.id,photoId:e.id,remark:e.comment?e.comment._content:null})})),l},_processParams:function(o){return{gallery_id:o.id,extras:e.APIHelper.request.getRebootPhotoExtras(),per_page:o.perPage||1,page:o.page||1,get_user_info:1,get_gallery_info:1,primary_photo_extras:"url_sq, url_q, url_t, url_s, url_m"}}}}),"@VERSION@",{requires:["flickr-promise","api-helper"],optional:["photo-models","person-models","gallery-models","photo-engagement-models","photo-stats-models","gallery-info-models"]});YUI.add("flickr-galleries-getContext-fetcher",(function(e,o){"use strict";e.namespace("ListFetchers")["flickr-galleries-getContext"]={run:function(t,s){var r=this;return e.Promise.all([s.callAPI("flickr.galleries.getContext",this._processParams(t),!0),s.getModelRegistry("gallery-models"),s.getModelRegistry("photo-models"),s.getModelRegistry("person-models"),s.getModelRegistry("photo-engagement-models"),s.getModelRegistry("photo-stats-models")]).then((function(e){return r._processResponse(e,t)}),(function(e){throw 3===e.code&&"Photo not in gallery"===e.message&&(e.notInContext=!0),e})).then(null,e.FetcherErrorLogger(o))},_processParams:function(o){return{gallery_id:o.compoundId||o.id,photo_id:o.photoId,extras:e.APIHelper.request.getRebootPhotoExtras(),num_prev:o.numPrev,num_next:o.numNext,user_id:o.ownerId}},_processResponse:function(o,t){var s,r,n,l,p,a,i,d,g=o[0],h=o[1],u=o[2],m=o[3],c=o[4],y=o[5],x=[],M=u.proxy(t.photoId);return r=g.nextphotos,n=g.prevphotos,s=e.APIHelper.response.parsePhotos({photos:r.photo,personModelRegistry:m,photoModelRegistry:u,photoEngagementModelRegistry:c,photoStatsModelRegistry:y}),x=e.APIHelper.response.parsePhotos({photos:n.photo,personModelRegistry:m,photoModelRegistry:u,photoEngagementModelRegistry:c,photoStatsModelRegistry:y}),p=!!(i=h.getValue(t.id,"photoContextList")).hasMinBoundary&&i.hasMinBoundary(),a=!!i.hasMaxBoundary&&i.hasMaxBoundary(),l=i.getList(),d=e.APIHelper.response.addOrReplaceListByContext({model:M,next:s,prev:x.reverse(),current:l,hasMin:p,hasMax:a,numNext:t.numNext,numPrev:t.numPrev}),h.setValue(t.id,"photoContextList",d),{next:s,previous:x.reverse()}}}}),"@VERSION@",{requires:["flickr-promise","api-helper"],optional:["gallery-models","photo-models","person-models","photo-engagement-models","photo-stats-models"]});YUI.add("flickr-galleries-addPhoto-creator",(function(o,e){"use strict";o.namespace("ModelCreators")["flickr-galleries-addPhoto"]={run:function(t,l){var i={full_response:1},r=t.galleryCompoundID?t.galleryCompoundID.split("-").pop():t.galleryID,a=[];return i.photo_id=Array.isArray(t.photoID)?t.photoID.join(","):t.photoID,i.gallery_id=r,Array.isArray(t.photoID)?t.photoID.forEach((function(o){a.push(l.getModel("photo-models",o))})):a.push(l.getModel("photo-models",t.photoID)),o.Promise.all([l.callAPI("flickr.galleries.addPhoto",i),l.getModel("gallery-models",r),o.Promise.all(a),l.getModelRegistry("photo-galleries-models"),l.getModelRegistry("photo-contexts-models"),l.getModelRegistry("gallery-info-models"),l.getModelRegistry("gallery-photo-association-models")]).then((function(e){var t,l,i,a,s=e[0],d=e[1],g=e[2],h=e[3],n=e[4],u=e[5],p=e[6];if("ok"===s.stat){i=s.gallery,a=s.failures;var c=[];if(g.forEach((function(e){!1,a&&a.some((function(o){return o.photo_id&&o.photo_id.toString()===e.id}))||(d&&!d.hasPhoto(e.getValue("id"))&&(d.addPhoto(e),d.getValue("primary")!==i.primaryPhotoId&&e.id===i.primaryPhotoId&&(t=e.getValue("sizes"),l={},o.Object.each(t,(function(o,e){["m","s","sq","t"].indexOf(e)>-1&&(l[e]={width:o.width,height:o.height,src:o.url})})),d.setValue("primaryPhotoSizes",l))),u.exists(r)&&!u.hasPhoto(r,e.getValue("id"))&&u.getValue(r,"photoList").prependToList(e),h.exists(e.id)&&!h.getValue(e.id,"galleries").getFromListByID(d.getValue("id"))&&(h.getValue(e.id,"galleries").prependToList(d),h.setValue(e.id,"total",h.getValue(e.id,"total")+1)),n.exists(e.id)&&!n.getValue(e.id,"contexts").getFromListByID(d.getValue("id"))&&(n.setValue(e.id,"totalGalleries",n.getValue(e.id,"totalGalleries")+1),n.getValue(e.id,"contexts").appendToList(d)),p.addOrUpdate({id:r+"-"+e.id,galleryId:r,photoId:e.id}),c.push(e.id))})),d&&d.setValues({photoCount:i.countPhotos,videoCount:i.countVideos,primary:i.primaryPhotoId}),u.exists(r)&&(u.setValues(r,{photoCount:i.countPhotos,videoCount:i.countVideos,currentState:i.currentState,primaryPhotoId:i.primaryPhotoId}),u.getValue(r,"photoList").totalItems=i.countPhotos+i.countVideos||0),o.Snowplough){var y={id:d.getValue("id"),photoIds:c};o.Snowplough.sendStructuredEvent({category:"gallery",action:"add_photo"},o.Snowplough.getGalleryContext(y))}return{galleryModel:d,apiResponse:s}}}),o.FetcherErrorLogger(e))}}}),"@VERSION@",{requires:["flickr-promise"],optional:["gallery-models","gallery-info-models","photo-models","photo-galleries-models","photo-contexts-models","gallery-photo-association-models"]});YUI.add("smart-galleries-models",(function(e){function t(e){t.superclass.constructor.call(this,e)}e.Models[this.name]=t,e.extend(t,e.FlickrModelRegistry,{name:this.name,remote:{read:function(t){return e.ListFetchers["flickr-galleries-getList"].run(t,this.appContext)},readNextGalleries:function(t,r){return e.ListFetchers["flickr-galleries-getList"].run(t,r)}},readNextGalleriesRemote:function(e,t){var r=t||{};return r.id=e,r.continuation=this.getValue(e,"continuation"),this.remote.readNextGalleries(r,this.appContext)},attributes:{id:{},pathAlias:{},galleries:{isCollection:!0,pageFetch:{listFetcher:e.ListFetchers["smart-galleries-getList"]}},continuation:{validator:function(t){return e.AttributeHelpers.validateString(t)},setter:function(t){return e.AttributeHelpers.coerceString(t)},defaultValue:0},totalItems:{validator:function(t){return e.AttributeHelpers.validateInteger(t)},setter:function(t){return e.AttributeHelpers.coerceInteger(t)}}}})}),"@VERSION@",{requires:["flickr-model-registry","flickr-promise","flickr-galleries-getList-fetcher"]});YUI.add("flickr-galleries-getList-fetcher",(function(e,o){"use strict";e.namespace("ListFetchers")["flickr-galleries-getList"]={run:function(t,r,s){var i=this,a=this._processParams(t);return e.Promise.all([r.callAPI("flickr.galleries.getList",a),r.getModelRegistry("person-galleries-models"),r.getModelRegistry("gallery-models"),r.getModel("person-models",t.id||{pathAlias:t.pathAlias}),r.getModelRegistry("gallery-photo-association-models"),r.getModelRegistry("smart-galleries-models")]).then((function(e){return i._processResponse(e,t)}),e.FetcherErrorLogger(o))},_processResponse:function(o,t){var r=o[0],s=o[1],i=o[2],a=o[3],l=o[4],n=o[5],p=r.galleries,d={},c=[],g={};if(p)return p.gallery&&e.Array.each(p.gallery,(function(o,t){var r,s,n=o.hasRequestedPhotos,p=o.coverPhotos?o.coverPhotos.photo:[];r=o.id.split("-")[1],p.forEach((function(o){o.url=e.APIHelper.response.removeProtocolFromURL(o.url)})),s={id:r,compoundId:o.id,title:o.title.content,description:o.description.content,owner:a,primary:o.primaryPhotoId,primaryPhotoSizes:e.APIHelper.response.parsePrimaryPhotoSizes(o),photoCount:o.countPhotos,videoCount:o.countVideos,viewCount:o.countViews,commentCount:o.countComments,coverPhotosData:p},c.push(i.addOrUpdate(s)),n&&n.forEach((function(e){l.addOrUpdate({id:r+"-"+e,galleryId:r,photoId:e})}))})),d={id:a.getValue("id"),pathAlias:a.getValue("pathAlias"),totalItems:p.total||p.gallery.length},g={perPage:t.perPage||500,page:p.page||1,pageContent:c,totalItems:p.total||p.gallery.length},p&&p.continuation?(d.continuation=p.continuation,n.addOrUpdate(d).getValue("galleries").appendToListMulti(c)):s.addOrUpdate(d).getValue("galleriesList").addPage(g),g.pageContent},_processParams:function(e){var o={primary_photo_extras:"url_sq, url_q, url_t, url_s, url_m",page:e.page||1,per_page:e.perPage||500,photo_ids:e.photoIds?e.photoIds.join():"",sort_groups:e.sortGroups?e.sortGroups.join():""};if(e.id)o.user_id=e.id;else{if(!e.pathAlias)throw new Error("[flickr-galleries-getList-fetcher] `id` or `pathAlias` is required.");o.path_alias=e.pathAlias}return e.withGalleryId&&(o.jump_to=e.withGalleryId),void 0!==e.continuation?o.continuation=e.continuation:(o.cover_photos=e.coverPhotos||1,o.primary_photo_cover_size=e.primaryPhotoCoverSize||"m",o.cover_photos_size=e.coverPhotosSize||"q"),o}}}),"@VERSION@",{requires:["flickr-promise","api-helper"],optional:["person-galleries-models","gallery-models","person-models","gallery-photo-association-models","smart-galleries-models"]});YUI.add("person-galleries-models",(function(e){function t(e){t.superclass.constructor.call(this,e)}e.Models[this.name]=t,e.extend(t,e.FlickrModelRegistry,{name:this.name,remote:{read:function(t){return e.ListFetchers["flickr-galleries-getList"].run(t,this.appContext)}},attributes:{id:{},pathAlias:{},url:{readOnly:!0,derivedBy:["pathAlias","id"],getter:function(e,t){var r=this.getValue(t,"pathAlias");return r?"/photos/"+r+"/galleries":"/photos/"+t+"/galleries"}},galleriesList:{isCollection:!0,pageFetch:{listFetcher:e.ListFetchers["flickr-galleries-getList"]}},totalItems:{validator:function(t){return e.AttributeHelpers.validateInteger(t)},setter:function(t){return e.AttributeHelpers.coerceInteger(t)}}}})}),"@VERSION@",{requires:["flickr-model-registry","flickr-promise","flickr-galleries-getList-fetcher"]});YUI.add("flickr-galleries-create-creator",(function(e,o){"use strict";e.namespace("ModelCreators")["flickr-galleries-create"]={run:function(t,l){var r={},i=[];return r.title=t.title,r.description=t.description,r.primary_photo_id=t.photoID,r.full_result=1,i=[l.callAPI("flickr.galleries.create",r),l.getModelRegistry("gallery-models"),l.getModel("person-models",l.getViewer().nsid),l.getModel("person-galleries-models",l.getViewer().nsid),l.getModelRegistry("photo-galleries-models"),l.getModelRegistry("photo-contexts-models")],t.photoID&&i.push(l.getModel("photo-models",t.photoID)),e.Promise.all(i).then((function(o){var l,r,i=o[0],s=o[1],a=o[2],p=o[3],g=o[4],n=o[5],d=i.gallery.id,h=d.split("-")[1];return o.length>6&&(l=o[6]),!!h&&(r=s.add({id:h,compoundId:d,title:i.gallery.title.content,description:i.gallery.description.content,photoPageList:l?[l]:[],photoContextList:l?[l]:[],owner:a,primary:i.gallery.primaryPhotoId,primaryPhotoSizes:e.APIHelper.response.parsePrimaryPhotoSizes(i.gallery),photoCount:i.gallery.primaryPhotoId&&l&&!l.getValue("isVideo")?1:0,videoCount:i.gallery.primaryPhotoId&&l&&l.getValue("isVideo")?1:0,viewCount:i.gallery.countViews,commentCount:i.gallery.countComments,coverPhotosData:i.gallery.coverPhotosData||[]}),p.getValue("galleriesList").prependToList(r),g.exists(t.photoID)&&!g.getValue(t.photoID,"galleries").getFromListByID(r.getValue("id"))&&(g.getValue(t.photoID,"galleries").prependToList(r),g.setValue(t.photoID,"total",g.getValue(t.photoID,"total")+1)),n.exists(t.photoID)&&!n.getValue(t.photoID,"contexts").getFromListByID(r.getValue("id"))&&(n.setValue(t.photoID,"totalGalleries",n.getValue(t.photoID,"totalGalleries")+1),n.getValue(t.photoID,"contexts").appendToList(r)),r)}),e.FetcherErrorLogger(o))}}}),"@VERSION@",{requires:["flickr-promise","api-helper"],optional:["gallery-models","photo-models","person-models","person-galleries-models","photo-galleries-models","photo-contexts-models"]});