YUI.add("group-info-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.ModelFetchers["flickr-groups-getInfo"].run(t,this.appContext)},join:function(t,r){return e.ModelCreators["flickr-groups-join"].run(t,r)},leave:function(t,r){return e.ModelDeletors["flickr-groups-leave"].run(t,r)},create:function(t,r){return e.ModelCreators["flickr-groups-create"].run(t,r)}},join:function(e){var t=this.getValue(e,"group");return t&&(t.setValue("isMember",!0),t.setValue("isInvited",!1)),this},leave:function(e){var t=this.getValue(e,"group");return t&&(t.setValue("isAdmin",!1),t.setValue("isModerator",!1),t.setValue("isMember",!1),this.setValue(e,"hasPendingRequestToJoin",!1)),this},declineInvite:function(e){var t=this,r={group_id:e};return this.appContext.callAPI("flickr.groups.invite.member.decline",r).then((function(r){return t.setValue(e,"isInvited",!1),r}))},attributes:{pathAlias:{validator:function(t,r){return e.AttributeHelpers.validateString(t)},setter:function(t){return e.AttributeHelpers.coerceString(t)},defaultValue:""},description:{validator:function(t,r){return e.AttributeHelpers.validateString(t)},setter:function(t){return e.AttributeHelpers.coerceString(t)},defaultValue:""},secureDescription:{validator:function(t,r){return e.AttributeHelpers.validateString(t)},setter:function(t){return e.AttributeHelpers.coerceString(t)},defaultValue:""},rules:{validator:function(t,r){return e.AttributeHelpers.validateString(t)},setter:function(t){return e.AttributeHelpers.coerceString(t)},defaultValue:""},roles:{},secureRules:{validator:function(t,r){return e.AttributeHelpers.validateString(t)},setter:function(t){return e.AttributeHelpers.coerceString(t)},defaultValue:""},hasPendingRequestToJoin:{validator:function(t){return e.AttributeHelpers.validateBoolean(t)},setter:function(t){return e.AttributeHelpers.coerceBoolean(t)},defaultValue:!1},photoLimitOptOut:{validator:function(t){return e.AttributeHelpers.validateBoolean(t)},setter:function(t){return e.AttributeHelpers.coerceBoolean(t)},defaultValue:!1},isInvited:{validator:function(t){return e.AttributeHelpers.validateBoolean(t)},setter:function(t){return e.AttributeHelpers.coerceBoolean(t)},defaultValue:!1},discussionsLocked:{validator:function(t){return e.AttributeHelpers.validateBoolean(t)},setter:function(t){return e.AttributeHelpers.coerceBoolean(t)},defaultValue:!1},privacy:{validator:function(t){return e.AttributeHelpers.validateInteger(t)},setter:function(t){return e.AttributeHelpers.coerceInteger(t)},defaultValue:1},restrictions:{},throttle:{},poolPreviewRowsVisibleCount:{validator:function(t){return e.AttributeHelpers.validateInteger(t)},setter:function(t){return e.AttributeHelpers.coerceInteger(t)},defaultFn:function(e){return 1}},coverPhotoAttribution:{},group:{isModel:!0}}})}),"@VERSION@",{requires:["flickr-model-registry","flickr-promise","flickr-groups-getInfo-fetcher","flickr-groups-join-creator","flickr-groups-leave-deletor","flickr-groups-create-creator","attribute-helpers","group-models"]});YUI.add("flickr-groups-getInfo-fetcher",(function(e,o){"use strict";e.namespace("ModelFetchers")["flickr-groups-getInfo"]={run:function(r,t){var s=this;return e.Promise.all([t.callAPI("flickr.groups.getInfo",this._processParams(r),!0),t.getModelRegistry("group-info-models"),t.getModelRegistry("group-models"),t.getModelRegistry("group-blast-models"),t.getModelRegistry("group-activity-models")]).then((function(e){return s._processResponse(e,r)}),e.FetcherErrorLogger(o))},_processParams:function(o){var r={extras:e.APIHelper.request.getRebootPhotoExtras()+","+e.APIHelper.request.getRebootGroupExtras()+", blast_user_info, date_last_viewed, has_pending_invite, coverphoto_attribution, is_locked",secure_image_embeds:1,lang:void 0};if(o.id)r.group_id=o.id;else{if(!o.pathAlias)throw new Error("[flickr-groups-getInfo-fetcher] `id` or `pathAlias` is required.");r.group_path_alias=o.pathAlias}return r},_processResponse:function(o,r){var t,s,i,a,p=o[0],u=o[1],l=o[2],g=o[3],d=o[4];return i=l.parseGroupModel(r.id,r.pathAlias,p.group),l.addOrUpdate(i),s={id:i.id,viewedPool:e.moment(p.group.viewedDates?p.group.viewedDates.pool:void 0),viewedDiscussions:e.moment(p.group.viewedDates?p.group.viewedDates.discussions:void 0),group:l.proxy(i.id)},d.addOrUpdate(s),a={id:(i=l.proxy(i.id)).id,blastMessage:p.group.blast?p.group.blast.content:"",blastMessageSecure:p.group.blast?p.group.secureBlast.content:"",blastUserId:p.group.blast?p.group.blast.userId:"",blastDateAdded:p.group.blast?e.moment(p.group.blast.dateBlastAdded,"X"):e.moment(),blastUserName:p.group.blast?p.group.blast.userName:"",blastPathAlias:p.group.blast?p.group.blast.userPathAlias:"",blastUserNSID:p.group.blast?p.group.blast.userNsid:"",blastRealName:p.group.blast?p.group.blast.realName:"",blastUserStatus:p.group.blast?p.group.blast.userStatus:""},g.addOrUpdate(a),t={id:p.group.id,pathAlias:p.group.pathAlias||r.pathAlias,description:p.group.description.content,secureDescription:p.group.secureDescription?p.group.secureDescription.content:"",rules:p.group.rules.content,roles:p.group.roles,secureRules:p.group.secureRules.content,restrictions:p.group.restrictions,throttle:p.group.throttle,poolPreviewRowsVisibleCount:p.group.pool_rows,group:i,discussionsLocked:"1"===p.group.isLocked,hasPendingRequestToJoin:p.group.has_pending_request_to_join,isInvited:p.group.is_invited,coverPhotoAttribution:p.group.coverphoto,photoLimitOptOut:p.group.photo_limit_opt_out},u.addOrUpdate(t),u.proxy(t.id)}}}),"@VERSION@",{requires:["flickr-promise","api-helper","moment"],optional:["group-info-models","group-models"]});YUI.add("group-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,parseGroupModel:function(t,r,n){var o,i={id:n.id||t||n.nsid,pathAlias:n.pathAlias||r||n.pathalias,title:n.title,invitationOnly:n.invitationOnly,memberCount:n.memberCount,poolCount:n.photos,poolPreviewRowsVisibleCount:n.pool_rows,topicCount:"string"===n.topicCount?n.topicCount:void 0,pendingCount:n.pool_pending_count,memberPendingCount:n.member_pending_count,iconurls:e.APIHelper.response.removeProtocolFromURL(n.iconurls),isMember:n.is_member||n.member||n.isMember,isModerator:n.is_moderator||n.moderator||n.isModerator,isAdmin:n.is_admin||n.admin||n.isAdmin,eighteenplus:n.eighteenplus,coverPhotoUrls:e.APIHelper.response.removeProtocolFromURL(n.coverphotoUrl),latestPhotoActivity:e.moment(n.date_activity_detail?n.date_activity_detail.pool:void 0,"X"),latestDiscussionActivity:e.moment(n.date_activity_detail?n.date_activity_detail.discussions:void 0,"X"),showPoolToNonMembers:n.show_pool,showDiscussionToNonMembers:n.show_discussion,needsInterstitial:n.needs_interstitial,muted:n.muted};return"string"==typeof n.datecreate?o=n.datecreate:n.datecreate&&"string"==typeof n.datecreate.content&&(o=n.datecreate.content),o?(o+=" +0700",i.dateCreated=e.moment(o,"YYYY-MM-DD HH:mm:ss Z")):i.dateCreated=new e.moment,!i.title&&n.name&&(i.title="string"==typeof n.name?n.name:n.name.content),!i.memberCount&&n.members&&(i.memberCount="string"!=typeof n.members?n.members.content:n.members),!i.poolCount&&n.poolCount&&(i.poolCount="string"!=typeof n.poolCount?n.poolCount.content:n.poolCount),i.topicCount||(n.topicCount?i.topicCount="string"!=typeof n.topicCount?n.topicCount.content:n.topicCount:i.topicCount=0),n.privacy&&(parseInt(n.privacy,10)?i.privacy=parseInt(n.privacy,10):n.privacy.content&&(i.privacy=n.privacy.content)),i},getLargestCoverPhotoSize:function(t,r){return e.PhotoModelHelper.getLargestSize(t,r)},attributes:{title:{validator:function(t,r){return e.AttributeHelpers.validateString(t)},setter:function(t){return e.AttributeHelpers.coerceString(t)},defaultValue:""},pathAlias:{validator:function(t,r){return e.AttributeHelpers.validateString(t)},setter:function(t){return e.AttributeHelpers.coerceString(t)||void 0},defaultFn:function(e){return e}},isModerator:{validator:function(t){return e.AttributeHelpers.validateBoolean(t)},setter:function(t){return e.AttributeHelpers.coerceBoolean(t)},defaultValue:!1},invitationOnly:{validator:function(t){return e.AttributeHelpers.validateBoolean(t)},setter:function(t){return e.AttributeHelpers.coerceBoolean(t)},defaultValue:!1},isMember:{validator:function(t){return e.AttributeHelpers.validateBoolean(t)},setter:function(t){return e.AttributeHelpers.coerceBoolean(t)},defaultValue:!1},isAdmin:{validator:function(t){return e.AttributeHelpers.validateBoolean(t)},setter:function(t){return e.AttributeHelpers.coerceBoolean(t)},defaultValue:!1},memberCount:{validator:function(t){return e.AttributeHelpers.validateInteger(t)},setter:function(t){return e.AttributeHelpers.coerceInteger(t)},defaultFn:function(e){return 0}},poolCount:{validator:function(t){return e.AttributeHelpers.validateInteger(t)},setter:function(t){return e.AttributeHelpers.coerceInteger(t)},defaultFn:function(e){return 0}},friendlyPoolCount:{readOnly:!0,derivedBy:["poolCount"],getter:function(t,r){return e.Number.format(this.getValue(r,"poolCount"),{thousandsSeparator:","})}},pendingCount:{validator:function(t){return e.AttributeHelpers.validateInteger(t)},setter:function(t){return e.AttributeHelpers.coerceInteger(t)},defaultFn:function(e){return 0}},memberPendingCount:{validator:function(t){return e.AttributeHelpers.validateInteger(t)},setter:function(t){return e.AttributeHelpers.coerceInteger(t)},defaultFn:function(e){return 0}},topicCount:{validator:function(t){return e.AttributeHelpers.validateInteger(t)},setter:function(t){return e.AttributeHelpers.coerceInteger(t)},defaultFn:function(e){return 0}},groupPoolAddURL:{readOnly:!0,derivedBy:["pathAlias"],defaultFn:function(e){return"/groups/"+this.getValue(e,"pathAlias")+"/pool/add/"}},dateCreated:{validator:function(t){return e.AttributeHelpers.validateDate(t)},setter:function(t){return e.AttributeHelpers.coerceDate(t)},defaultFn:function(t){return e.moment()},serialize:function(e){return e.format("X")},deserialize:function(t){return e.moment(t,"X")}},latestPhotoActivity:{validator:function(t){return e.AttributeHelpers.validateDate(t)},setter:function(t){return e.AttributeHelpers.coerceDate(t)},defaultFn:function(t){return e.moment()},serialize:function(e){return e.format("X")},deserialize:function(t){return e.moment(t,"X")}},latestDiscussionActivity:{validator:function(t){return e.AttributeHelpers.validateDate(t)},setter:function(t){return e.AttributeHelpers.coerceDate(t)},defaultFn:function(t){return e.moment()},serialize:function(e){return e.format("X")},deserialize:function(t){return e.moment(t,"X")}},showPoolToNonMembers:{validator:function(t){return e.AttributeHelpers.validateBoolean(t)},setter:function(t){return e.AttributeHelpers.coerceBoolean(t)},defaultValue:!1},showDiscussionToNonMembers:{validator:function(t){return e.AttributeHelpers.validateBoolean(t)},setter:function(t){return e.AttributeHelpers.coerceBoolean(t)},defaultValue:!1},eighteenplus:{validator:function(t){return e.AttributeHelpers.validateBoolean(t)},setter:function(t){return e.AttributeHelpers.coerceBoolean(t)},defaultValue:!1},needsInterstitial:{validator:function(t){return e.AttributeHelpers.validateBoolean(t)},setter:function(t){return e.AttributeHelpers.coerceBoolean(t)},defaultValue:!1},privacy:{validator:function(t){return e.AttributeHelpers.validateInteger(t)},setter:function(t){return e.AttributeHelpers.coerceInteger(t)},defaultFn:function(e){return 0}},iconurls:{},bestIconURL:{readOnly:!0,derivedBy:["iconurls"],defaultFn:function(t,r){var n=e.URLHelper.getGroupIconURL(this.getValue(t,"iconurls"),r);return n||void 0}},mediumIconURL:{readOnly:!0,derivedBy:["iconurls"],defaultFn:function(t){var r=e.URLHelper.getGroupIconURL(this.getValue(t,"iconurls"),"medium");return r||void 0}},url:{readOnly:!0,derivedBy:["group"],defaultFn:function(e){return"/groups/"+(this.getValue(e,"pathAlias")||e)+"/"}},urlMembersPage:{readOnly:!0,derivedBy:["group","url"],defaultFn:function(e){return this.getValue(e,"url")+"members"}},urlPoolPage:{readOnly:!0,derivedBy:["group","url"],defaultFn:function(e){return this.getValue(e,"url")+"pool"}},urlDiscussionPage:{readOnly:!0,derivedBy:["group","url"],defaultFn:function(e){return this.getValue(e,"url")+"discuss"}},urlPendingMembersPage:{readOnly:!0,derivedBy:["id"],defaultFn:function(e){return"/groups_pending.gne?id="+e}},urlPendingPhotosPage:{readOnly:!0,derivedBy:["pathAlias"],defaultFn:function(e){return"/groups/"+this.getValue(e,"pathAlias")+"/admin/pending"}},coverPhotoUrls:{},latestGroupActivity:{readOnly:!0,derivedBy:["latestPhotoActivity","latestDiscussionActivity","dateCreated"],defaultFn:function(t){var r=this.getValue(t,"latestDiscussionActivity"),n=this.getValue(t,"latestPhotoActivity"),o=this.getValue(t,"dateCreated");return r.isValid()&&(o=e.moment.min(o,r)),n.isValid()&&(o=e.moment.min(o,n)),o}},muted:{validator:function(t){return e.AttributeHelpers.validateBoolean(t)},setter:function(t){return e.AttributeHelpers.coerceBoolean(t)},defaultValue:!1}}})}),"@VERSION@",{requires:["flickr-model-registry","flickr-promise","api-helper","url-helper","moment","flickr-groups-getInfo-fetcher","attribute-helpers","photo-model-helper"]});YUI.add("flickr-groups-pools-getGroups-fetcher",(function(e,r){"use strict";e.namespace("ListFetchers")["flickr-groups-pools-getGroups"]={run:function(s,o){var p=this;return e.Promise.all([o.callAPI("flickr.groups.pools.getGroups",{extras:e.APIHelper.request.getRebootGroupExtras()+", icon_urls, needs_interstitial",page:s.page||0,per_page:s.perPage||400},!0),o.getModelRegistry("person-groups-models"),o.getModelRegistry("group-pool-models"),o.getModelRegistry("group-models")]).then((function(e){return p._processResponse(e,s)}),e.FetcherErrorLogger(r))},_processResponse:function(r,s){var o=r[0],p=r[1],u=r[2],t=r[3],i=o.groups,a=s.id,l={},g=[];if(i)return i.group&&e.Array.each(i.group,(function(e,r){var s,o,p;(p=t.parseGroupModel(e.id,e.pathAlias,e)).id&&(s=t.addOrUpdate(p),o=u.addOrUpdate({id:e.id,pathAlias:e.pathAlias,group:s}),g.push(o))})),(l={id:a,memberCount:o.userGroupMemberships?o.userGroupMemberships.member:null,moderatorCount:o.userGroupMemberships?o.userGroupMemberships.moderator:null,adminCount:o.userGroupMemberships?o.userGroupMemberships.admin:null,invitedCount:o.userGroupMemberships?o.userGroupMemberships.invited:null}).groups=e.APIHelper.response.addOrReplaceListByPage({current:p.exists(a)?p.proxy(a).getValue("groups").getList():[],perPage:s.perPage,pageNum:s.page,totalItems:o.groups.total,newPages:g}),p.exists(a)?p.setValue(a,"groups",l.groups):p.add(l),l.groups}}}),"@VERSION@",{requires:["flickr-promise","api-helper"],optional:["person-groups-models","group-models","group-pool-models","person-models"]});YUI.add("flickr-groups-fave-fetcher",(function(e,r){"use strict";e.namespace("ModelFetchers")["flickr-groups-fave"]={run:function(s,o){return e.Promise.all([o.callAPI("flickr.groups.fave",s),o.getModelRegistry("person-groups-models")]).then(this._processResponse,e.FetcherErrorLogger(r))},_processResponse:function(e){}}}),"@VERSION@",{requires:["flickr-promise","flickr-promise"],optional:["person-groups-models","api-helper"]});YUI.add("flickr-groups-unfave-fetcher",(function(e,r){"use strict";e.namespace("ModelFetchers")["flickr-groups-unfave"]={run:function(s,o){return e.Promise.all([o.callAPI("flickr.groups.unfave",s),o.getModelRegistry("person-groups-models")]).then(this._processResponse,e.FetcherErrorLogger(r))},_processResponse:function(e){}}}),"@VERSION@",{requires:["flickr-promise","flickr-promise"],optional:["person-groups-models","api-helper"]});YUI.add("flickr-people-getGroupsWithStatus-fetcher",(function(e,t){"use strict";e.namespace("ListFetchers")["flickr-people-getGroupsWithStatus"]={run:function(s,i){var r=this,o={extras:e.APIHelper.request.getRebootGroupExtras()+", icon_urls, date_activity, date_last_viewed",user_id:s.id,status:s.status};return s.id!==i.getViewer().nsid&&(o.public_only=1,o.status="2,3,4"),e.Promise.all([i.callAPI("flickr.people.getGroupsWithStatus",o,!0),i.getModelRegistry("person-groups-models"),i.getModelRegistry("group-models"),i.getModelRegistry("group-activity-models")]).then((function(e){return r._processResponse(e,s)}),e.FetcherErrorLogger(t))},_processResponse:function(t,s){var i,r=t[0],o=t[1],a=t[2],u=t[3],d=r.groups,l=s.id,p={},n=[];if(d)return e.Array.each(d,(function(t,r){var o,d,l,p=a.parseGroupModel(s.id,s.pathAlias,t);t.id&&(o=a.addOrUpdate(p),n.push(o),t.viewDates?(d="0"!==t.viewDates.pool?e.moment(t.viewDates.pool,"X"):u.getDefaultViewedDate(),(l="0"!==t.viewDates.discussions?e.moment(t.viewDates.discussions,"X"):u.getDefaultViewedDate()).isValid()||(l=u.getDefaultViewedDate()),d.isValid()||(d=u.getDefaultViewedDate())):(d=u.getDefaultViewedDate(),l=u.getDefaultViewedDate()),i={id:p.id,viewedPool:d,viewedDiscussions:l,group:o},u.addOrUpdate(i))})),(p={id:l,memberCount:r.members?r.members:null,moderatorCount:0,adminCount:0,invitedCount:0})[s.attribute]=n,o.exists(l)?o.setValue(l,s.attribute,p[s.attribute]):o.add(p),p[s.attribute]}}}),"@VERSION@",{requires:["flickr-promise","api-helper","moment"],optional:["person-groups-models","group-models"]});YUI.add("person-groups-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.ModelFetchers["flickr-people-getInfo"].run(t,this.appContext)},faveGroup:function(t,r){return e.ModelFetchers["flickr-groups-fave"].run(t,r)},unfaveGroup:function(t,r){return e.ModelFetchers["flickr-groups-unfave"].run(t,r)}},faveGroup:function(e){var t=this,r=e.group_id,o=e.user_id;return this.remote.faveGroup(e,this.appContext).then(null,(function(){t.appContext.getModel("group-models",r).then((function(e){t.getValue(o,"groupsFaved").removeFromList(r)}))})),this.appContext.getModel("group-models",r).then((function(e){t.getValue(o,"groupsFaved").appendToList(e)}))},unfaveGroup:function(e){var t=e.group_id,r=e.user_id,o=this;return this.remote.unfaveGroup(e,this.appContext).then(null,(function(){o.appContext.getModel("group-models",t).then((function(e){o.getValue(r,"groupsFaved").appendToList(e)}))})),this.appContext.getModel("group-models",t).then((function(e){o.getValue(r,"groupsFaved").removeFromList(t)}))},attributes:{id:{},memberCount:{validator:function(t){return e.AttributeHelpers.validateInteger(t)},setter:function(t){return e.AttributeHelpers.coerceInteger(t)}},moderatorCount:{validator:function(t){return e.AttributeHelpers.validateInteger(t)},setter:function(t){return e.AttributeHelpers.coerceInteger(t)}},adminCount:{validator:function(t){return e.AttributeHelpers.validateInteger(t)},setter:function(t){return e.AttributeHelpers.coerceInteger(t)}},invitedCount:{validator:function(t){return e.AttributeHelpers.validateInteger(t)},setter:function(t){return e.AttributeHelpers.coerceInteger(t)}},groups:{isListProxy:!0,pageFetch:{listFetcher:e.ListFetchers["flickr-groups-pools-getGroups"]}},groupsAdministered:{isListProxy:!0,pageFetch:{listFetcher:e.ListFetchers["flickr-people-getGroupsWithStatus"]}},groupsModerated:{isListProxy:!0,pageFetch:{listFetcher:e.ListFetchers["flickr-people-getGroupsWithStatus"]}},groupsBelongingTo:{isListProxy:!0,pageFetch:{listFetcher:e.ListFetchers["flickr-people-getGroupsWithStatus"]}},groupsFaved:{isListProxy:!0,pageFetch:{listFetcher:e.ListFetchers["flickr-people-getGroupsWithStatus"]}}}})}),"@VERSION@",{requires:["flickr-model-registry","flickr-promise","flickr-groups-pools-getGroups-fetcher","flickr-people-getInfo-fetcher","flickr-groups-fave-fetcher","flickr-groups-unfave-fetcher","flickr-people-getGroupsWithStatus-fetcher"]});