YUI.add("flickr-galleries-setPrimaryPhoto-updater",function(r,e){"use strict";r.namespace("ModelUpdaters")["flickr-galleries-setPrimaryPhoto"]={run:function(l,i){var t={};return t.gallery_id=l.galleryId,t.primary_photo_id=l.photoId,i.callAPI("flickr.galleries.setPrimaryPhoto",t).then(null,r.FetcherErrorLogger(e))}}},"@VERSION@",{requires:["flickr-promise"]});YUI.add("flickr-galleries-editPhotos-updater",function(r,e){"use strict";r.namespace("ModelUpdaters")["flickr-galleries-editPhotos"]={run:function(o,t){var i={gallery_id:o.galleryId,primary_photo_id:o.primaryPhotoId};return o.photoIds&&o.photoIds.length>0&&(i.photo_ids=o.photoIds.join(",")),t.callAPI("flickr.galleries.editPhotos",i).then(null,r.FetcherErrorLogger(e))}}},"@VERSION@",{requires:[]});YUI.add("flickr-galleries-reorderPhotos-updater",function(e,r){"use strict";e.namespace("ModelUpdaters")["flickr-galleries-reorderPhotos"]={run:function(r,t){var l={gallery_id:r.galleryId,photo_ids:JSON.stringify(r.photoIds),user_id:r.userId,current_state:r.currentState};return e.Promise.all([t.callAPI("flickr.galleries.reorderPhotos",l),t.getModel("gallery-info-models",r.galleryId),t.getModelRegistry("gallery-models")]).then(function(e){var t=e[0],l=e[1],o=e[2];if(l.setValue("currentState",t.currentState),o.exists(r.galleryId)){var a=o.getValue(r.galleryId,"photoContextList");a.getList().forEach(function(e){a.removeFromList(e.id)})}})}}},"@VERSION@",{requires:[],optional:["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=o[0],d=o[1],g=o[2],h=o[3],u=o[4],m=o[5],c=[],y=[],x=g.proxy(t.photoId),M=[];return s=i.nextphotos,r=i.prevphotos,y=e.APIHelper.response.parsePhotos({photos:s.photo,personModelRegistry:h,photoModelRegistry:g,photoEngagementModelRegistry:u,photoStatsModelRegistry:m}),c=e.APIHelper.response.parsePhotos({photos:r.photo,personModelRegistry:h,photoModelRegistry:g,photoEngagementModelRegistry:u,photoStatsModelRegistry:m}),a=d.getValue(t.id,"photoContextList"),l=!!a.hasMinBoundary&&a.hasMinBoundary(),p=!!a.hasMaxBoundary&&a.hasMaxBoundary(),n=a.getList(),M=e.APIHelper.response.addOrReplaceListByContext({model:x,next:y,prev:c.reverse(),current:n,hasMin:l,hasMax:p,numNext:t.numNext,numPrev:t.numPrev}),d.setValue(t.id,"photoContextList",M),{next:y,previous:c.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,s=[];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){s.push(l.getModel("photo-models",o))}):s.push(l.getModel("photo-models",t.photoID)),o.Promise.all([l.callAPI("flickr.galleries.addPhoto",i),l.getModel("gallery-models",r),o.Promise.all(s),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,s,a=e[0],d=e[1],h=e[2],g=e[3],n=e[4],p=e[5],u=e[6],c=!1;if("ok"===a.stat)return i=a.gallery,s=a.failures,h.forEach(function(e){c=!1,s&&(c=s.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))),p.exists(r)&&!p.hasPhoto(r,e.getValue("id"))&&p.getValue(r,"photoList").prependToList(e),g.exists(e.id)&&!g.getValue(e.id,"galleries").getFromListByID(d.getValue("id"))&&(g.getValue(e.id,"galleries").prependToList(d),g.setValue(e.id,"total",g.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)),u.addOrUpdate({id:r+"-"+e.id,galleryId:r,photoId:e.id}))}),d&&d.setValues({photoCount:i.countPhotos,videoCount:i.countVideos,primary:i.primaryPhotoId}),p.exists(r)&&(p.setValues(r,{photoCount:i.countPhotos,videoCount:i.countVideos,currentState:i.currentState,primaryPhotoId:i.primaryPhotoId}),p.getValue(r,"photoList").totalItems=i.countPhotos+i.countVideos||0),{galleryModel:d,apiResponse:a}},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"]});