YUI.add("photo-tags-models",(function(t){function e(t){e.superclass.constructor.call(this,t)}t.Models[this.name]=e,t.extend(e,t.FlickrModelRegistry,{name:this.name,remote:{read:function(e){return t.ModelFetchers["flickr-tags-getListPhoto"].run(e,this.appContext)},create:function(e){return t.ModelCreators["flickr-photos-addTags"].run(e,this.appContext)},delete:function(e){return t.ModelDeletors["flickr-photos-removeTag"].run(e,this.appContext)}},attributes:{tags:{isCollection:!0}}})}),"@VERSION@",{requires:["flickr-model-registry","flickr-tags-getListPhoto-fetcher","flickr-photos-addTags-creator","flickr-photos-removeTag-deletor"]});YUI.add("flickr-photos-addTags-creator",(function(t,o){"use strict";t.namespace("ModelCreators")["flickr-photos-addTags"]={run:function(s,e){var r=this;return t.Promise.all([e.callAPI("flickr.photos.addTags",this._processParams(s)),e.getModelRegistry("photo-tags-models"),e.getModelRegistry("tag-models")]).then((function(t){return r._processResponse(t,s)}),(function(t){throw s.fullResponse&&(t.photoIds=s.photoId),t})).then(null,t.FetcherErrorLogger(o))},_processParams:function(t){t.tags=t.tags||[];var o={};return o.photo_ids=t.photoId.join(","),o.tags=t.tags.join(","),t.fullResponse&&(o.full_response=1),o.extras="is_autotag",o},_processResponse:function(t,o){var s,e,r,a=t[0],n=t[1],i=t[2],d=[];if(s=a.errors,!o.fullResponse){for(a.tags.tag.forEach((function(t){i.exists(t.id)||i.add({id:t.id,tagRaw:t.raw,tagValue:t.content.replace(/\s/g,""),tagAuthorNSID:t.author,duplicateAutotagId:t.duplicateAutotag}),d.push(i.proxy(t.id))})),e=0;e<o.photoId.length;e++)r=o.photoId[e],n.exists(r)?d.forEach((function(t){void 0!==t&&n.getValue(r,"tags").push(t)})):n.add({id:r,tags:d});return d}if(s&&s.length>0)return s}}}),"@VERSION@",{requires:["flickr-promise"],optional:["photo-tags-models","tag-models"]});YUI.add("flickr-favorites-getContext-fetcher",(function(e,o){"use strict";e.namespace("ListFetchers")["flickr-favorites-getContext"]={run:function(t,s){var r=this;return e.Promise.all([s.callAPI("flickr.favorites.getContext",this._processParams(t),!0),s.getModelRegistry("favorite-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 a favorite"===e.message&&(e.notInContext=!0),e})).then(null,e.FetcherErrorLogger(o))},_processParams:function(o){var t={photo_id:o.photoId,num_prev:o.numNext,num_next:o.numPrev,extras:e.APIHelper.request.getRebootPhotoExtras()};return o.id?t.user_id=o.id:t.path_alias=o.pathAlias,t},_processResponse:function(o,t){var s,r,n,a,p,i,l,h,d=o[0],g=o[1],u=o[2],m=o[3],c=o[4],x=o[5],y=[],M=u.proxy(t.photoId);return r=d.prevphotos,n=d.nextphotos,s=e.APIHelper.response.parsePhotos({photos:r.photo,personModelRegistry:m,photoModelRegistry:u,photoEngagementModelRegistry:c,photoStatsModelRegistry:x}),y=e.APIHelper.response.parsePhotos({photos:n.photo,personModelRegistry:m,photoModelRegistry:u,photoEngagementModelRegistry:c,photoStatsModelRegistry:x}),p=!!(l=g.getValue(t.id,"photoContextList")).hasMinBoundary&&l.hasMinBoundary(),i=!!l.hasMaxBoundary&&l.hasMaxBoundary(),a=l.getList(),h=e.APIHelper.response.addOrReplaceListByContext({model:M,next:s,prev:y.reverse(),hasMax:i,hasMin:p,current:a,numNext:t.numNext,numPrev:t.numPrev}),g.setValue(t.id,"photoContextList",h),{next:s,previous:y.reverse()}}}}),"@VERSION@",{requires:["flickr-promise","api-helper"],optional:["favorite-models","photo-models","person-models","photo-engagement-models","photo-stats-models"]});YUI.add("flickr-favorites-getList-fetcher",(function(e,o){"use strict";e.namespace("ListFetchers")["flickr-favorites-getList"]={run:function(t,s){var r=this;return e.Promise.all([s.callAPI("flickr.favorites.getList",this._processParams(t)),s.getModelRegistry("photo-models"),s.getModelRegistry("person-models"),s.getModelRegistry("favorite-models"),s.getModelRegistry("photo-engagement-models"),s.getModelRegistry("photo-stats-models"),s.getModelRegistry("gallery-photo-association-models"),s.getModelRegistry("gallery-faves-models")]).then((function(e){return r._processResponse(e,t)}),e.FetcherErrorLogger(o))},_processParams:function(o){var t={extras:e.APIHelper.request.getRebootPhotoExtras(),per_page:o.perPage||20,page:o.page||1,get_user_info:1,jump_to:o.withPhotoId||""};if(o.id||o.userId)t.user_id=(o.id||o.userId).split("-")[0];else{if(!o.pathAlias)throw new Error("[flickr-favorites-getList-fetcher] `id` or `pathAlias` is required.");t.path_alias=o.pathAlias}return o.galleryId&&(t.gallery_id=o.galleryId),t},_processResponse:function(o,t){var s,r,a,p=o[0],l=o[1],i=o[2],d=o[3],g=o[4],h=o[5],n=o[6],y=o[7],c={id:p.user.nsid,pathAlias:p.user.pathAlias,totalItems:p.photos.total},u=t.id||t.userId,f=[];return u&&u!==c.id&&(c.id=u),r=e.APIHelper.response.parsePerson(p.user),c.owner=i.addOrUpdate(r),t.galleryId?(p.photos.photo.forEach((function(e){e.gallerynotaddable&&f.push(e)})),s=e.APIHelper.response.parsePhotos({photos:p.photos.photo,personModelRegistry:i,photoModelRegistry:l,photoEngagementModelRegistry:g,photoStatsModelRegistry:h}),a=e.APIHelper.response.parsePhotos({photos:f,personModelRegistry:i,photoModelRegistry:l,photoEngagementModelRegistry:g,photoStatsModelRegistry:h}),c.photoList={perPage:p.photos.perpage,page:p.photos.page,pageContent:s,totalItems:p.photos.total},c.id=r.id+"-"+t.galleryId,y.addOrUpdate(c).getValue("nonGalleryAddablePhotos").concat(a)):(s=e.APIHelper.response.parsePhotos({photos:p.photos.photo,personModelRegistry:i,photoModelRegistry:l,photoEngagementModelRegistry:g,photoStatsModelRegistry:h}),c.photoPageList={perPage:p.photos.perpage,page:p.photos.page,pageContent:s,totalItems:p.photos.total},d.addOrUpdate(c)),p.photos.photo&&p.photos.photo.forEach((function(e){e.ingallery&&n.addOrUpdate({id:t.galleryId+"-"+e.id,galleryId:t.galleryId,photoId:e.id})})),s}}}),"@VERSION@",{requires:["flickr-promise","api-helper"],optional:["photo-models","person-models","favorite-models","photo-engagement-models","photo-stats-models"]});YUI.add("favorite-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-favorites-getList"].run(t,this.appContext)}},attributes:{normalizedId:{readOnly:!0,defaultFn:function(e){return e.split("-")[0]}},displayType:{readOnly:!0,defaultFn:function(){return"favorites"}},title:{readOnly:!0,derivedBy:["owner","normalizedId"],defaultFn:function(e){var t,r=this.appContext.getViewer(),i=this.getValue(e,"normalizedId");return r&&r.nsid===i?"Your favorites":(t=this.getValue(e,"owner"))?t.getValue("displayname")+"'s favorites":"Favorites"}},pathAlias:{validator:function(t,r){return e.AttributeHelpers.validateString(t)},setter:function(t){return e.AttributeHelpers.coerceString(t)||void 0},defaultFn:function(e){return this.getValue(e,"normalizedId")}},owner:{isModel:!0},isOwner:e.PhotoModelHelper.attributes.isOwner,photoPageList:{isCollection:!0,pageFetch:{listFetcher:e.ListFetchers["flickr-favorites-getList"]}},photoContextList:{isListProxy:!0,contextFetch:{listFetcher:e.ListFetchers["flickr-favorites-getContext"],listItemIdField:"photoId"}},url:{readOnly:!0,derivedBy:["owner","normalizedId"],defaultFn:function(e){var t=this.getValue(e,"owner"),r=this.getValue(e,"normalizedId");return"/photos/"+(t?t.getValue("pathAlias"):r)+"/favorites/"}},totalItems:{defaultFn:function(){return null}},urlSuffix:{readOnly:!0,derivedBy:["owner"],defaultFn:function(e){return"faves-"+this.getValue(e,"owner").getValue("pathAlias")}}}})}),"@VERSION@",{requires:["flickr-model-registry","flickr-promise","flickr-favorites-getContext-fetcher","flickr-favorites-getList-fetcher","photo-model-helper"]});YUI.add("flickr-galleries-getInfo-fetcher",(function(e,r){"use strict";e.namespace("ModelFetchers")["flickr-galleries-getInfo"]={run:function(o,t){var n=this,s=this._processParams(o);return e.FlickrPromise({apiResponse:t.callAPI("flickr.galleries.getInfo",s),galleryInfoModelRegistry:t.getModelRegistry("gallery-info-models"),personModelRegistry:t.getModelRegistry("person-models")}).then((function(e){return n._processResponse(e,o,t)}),e.FetcherErrorLogger(r))},_processResponse:function(e,r,o){var t,n,s=e.apiResponse,i=e.galleryInfoModelRegistry,a=(e.personModelRegistry,e.personModel,s.gallery);if(a)return o.getModel("person-models",a.owner).then((function(e){return n=e,t={id:r.id,compoundId:a.id,owner:n,username:a.username,primaryPhotoId:a.primary_photo_id,dateCreate:parseInt(a.date_create,10),dateUpdate:parseInt(a.date_update,10),photoCount:a.count_photos,videoCount:a.count_videos,viewCount:parseInt(a.count_views,10),commentCount:parseInt(a.count_comments,10),title:a.title._content,description:a.description._content,currentState:a.current_state,primary_photo_server:a.primary_photo_server,primary_photo_farm:a.primary_photo_farm,primary_photo_secret:a.primary_photo_secret},i.addOrUpdate(t)}))},_processParams:function(e){return{gallery_id:e.id}}}}),"@VERSION@",{requires:["flickr-promise","api-helper","url-helper"],optional:["gallery-info-models","person-models"]});YUI.add("flickr-galleries-comments-addComment-creator",(function(e,t){"use strict";e.namespace("ModelCreators")["flickr-galleries-comments-addComment"]={run:function(n,r){var o=this;return e.Promise.all([r.callAPI("flickr.galleries.comments.addComment",this._processParams(n)),r.getModelRegistry("person-models"),r.getModelRegistry("gallery-comment-models"),r.getModel("gallery-info-models",n.galleryId)]).then((function(e){return o._processResponse(e,n,r)}),e.FetcherErrorLogger(t))},_processParams:function(e){return{gallery_id:e.galleryId,comment_text:e.commentText,user_id:e.galleryOwnerId,extras:"full_response, expand_bbml, use_text_for_links, bbml_need_all_photo_sizes"}},_processResponse:function(e,t,n){var r,o,m,a=e[0],l=(e[1],e[2]),s=e[3],c=a.comment;return c.secureComment&&(o="string"==typeof c.secureComment?c.secureComment:c.secureComment.content),o||(o=c.content||c.comment),c.rawComment&&(m="string"==typeof c.rawComment?c.rawComment:c.rawComment.content),m||(m=c.content||c.comment),n.getModel("person-models",t.authorId).then((function(e){return r=l.addOrUpdate({id:c.commentId,galleryId:c.galleryId,galleryOwnerId:c.galleryOwnerId,author:e,authorUsername:c.authorname,authorId:c.author,date:c.dateCreate,permalink:c.permalink,content:c.content,contentSecure:o,contentRaw:m}),s.getValue("comments").unshift(r),s.getValue("comments").totalItems++,s.setValue("commentCount",s.getValue("commentCount")+1),r}))}}}),"@VERSION@",{requires:["flickr-promise"],optional:[]});