diff --git a/familysearch-javascript-sdk.js b/familysearch-javascript-sdk.js index 24447a4..15327f4 100644 --- a/familysearch-javascript-sdk.js +++ b/familysearch-javascript-sdk.js @@ -3130,6 +3130,13 @@ define('discussions',[ * @return {String} Discussion URL */ + /** + * @ngdoc property + * @name discussions.types:constructor.DiscussionRef#attribution + * @propertyOf discussions.types:constructor.DiscussionRef + * @returns {Attribution} {@link attribution.types:constructor.Attribution Attribution} object + */ + /** * @ngdoc property * @name discussions.types:constructor.DiscussionRef#$personId @@ -3145,12 +3152,9 @@ define('discussions',[ * @return {String} URL of this discussion reference; _NOTE_ however, that individual discussion references cannot be read */ $getDiscussionRefUrl: function() { - // TODO change this once links is an associative array (last checked 4/2/14) - return helpers.removeAccessToken(maybe(helpers.find(this.links, {title: 'Discussion Reference'})).href); + return helpers.removeAccessToken(maybe(maybe(this.links)['discussion-reference']).href); }, - // TODO add attribution when that is available (last checked 4/2/14) - /** * @ngdoc function * @name discussions.types:constructor.DiscussionRef#$getDiscussionUrl @@ -3171,13 +3175,12 @@ define('discussions',[ * @return {Object} promise for the {@link discussions.functions:getDiscussion getDiscussion} response */ $getDiscussion: function() { - // TODO remove this.resourceId if resourceId ends up being discussion reference id return exports.getDiscussion(this.$getDiscussionUrl() || this.resourceId); }, /** * @ngdoc function - * @name discussions.types:constructor.DiscussionRef#$setDiscussionUrl + * @name discussions.types:constructor.DiscussionRef#$setDiscussion * @methodOf discussions.types:constructor.DiscussionRef * @function * @param {Discussion|string} discussion Discussion object or discussion url or discussion id @@ -3192,7 +3195,6 @@ define('discussions',[ this.resource = helpers.removeAccessToken(discussion); } else { - // TODO if resourceId is a discussion ref id instead of a discussion id, we'll need to set a $discussionId variable this.resourceId = discussion; } //noinspection JSValidateTypes @@ -3222,16 +3224,14 @@ define('discussions',[ return helpers.chainHttpPromises( plumbing.getUrl('person-discussion-references-template', null, {pid: self.$personId}), function(url) { - // TODO if resourceId is a discussion ref id instead of a discussion id, we need to use $discussionId if (!self.resource && self.resourceId) { // the discovery resource is guaranteed to be set due to the getUrl statement self.resource = helpers.getUrlFromDiscoveryResource(globals.discoveryResource, 'discussion-template', {did: self.resourceId}); } - // TODO save discussion references in new json serialization format when that works var payload = { persons: [{ id: self.$personId, - 'discussion-references' : [ self.resource ] + 'discussion-references' : [ { resource: self.resource } ] }] }; if (changeMessage) { @@ -3240,12 +3240,12 @@ define('discussions',[ var headers = {'Content-Type': 'application/x-fs-v1+json', 'X-FS-Feature-Tag': 'discussion-reference-json-fix'}; return plumbing.post(url, payload, headers, opts, function(data, promise) { if (!self.$getDiscussionRefUrl()) { - // TODO change this once links is an associative array - // TODO also set id when that field has been added - self.links = [{ - href: promise.getResponseHeader('Location'), - title: 'Discussion Reference' - }]; + self.links = { + 'discussion-reference': { + href: promise.getResponseHeader('Location'), + title: 'Discussion Reference' + } + }; } return self.$getDiscussionRefUrl(); }); @@ -3391,7 +3391,6 @@ define('discussions',[ function(url) { var payload = {discussions: [{ comments: [ self ] }] }; return plumbing.post(url, payload, {'Content-Type' : 'application/x-fs-v1+json'}, opts, function(data, promise) { - // TODO currently when creating discussion comments, X-ENTITY-ID and Location headers aren't returned (last checked 4/2/14) if (!self.id) { self.id = promise.getResponseHeader('X-ENTITY-ID'); } diff --git a/familysearch-javascript-sdk.min.js b/familysearch-javascript-sdk.min.js index 07cb1ae..f929111 100644 --- a/familysearch-javascript-sdk.min.js +++ b/familysearch-javascript-sdk.min.js @@ -5,6 +5,6 @@ * http://github.com/rootsdev/familysearch-javascript-sdk */ -!function(e,t){"object"==typeof module&&"object"==typeof module.exports?module.exports=t():"function"==typeof define&&define.amd?define(t):e.FamilySearch=t()}(this,function(){function e(e,t,r){n[e]={deps:3===arguments.length?t:[],fn:3===arguments.length?r:t}}function t(e){var i=n[e],o=[],s=i.fn;if("function"==typeof s){for(var c=0,u=i.deps.length;u>c;c++){var a=i.deps[c],l=r[a];void 0===l&&(l=t(a),r[a]=l),o.push(l)}s=i.fn.apply(this,o)}return s}var n={},r={};return e("globals",{appKey:null,environment:null,httpWrapper:null,deferredWrapper:null,setTimeout:null,clearTimeout:null,authCallbackUri:null,autoSignin:!1,autoExpire:!1,accessToken:null,saveAccessToken:!1,logging:!1,accessTokenCookie:"FS_ACCESS_TOKEN",authCodePollDelay:50,defaultThrottleRetryAfter:500,maxHttpRequestRetries:2,maxAccessTokenInactivityTime:354e4,maxAccessTokenCreationTime:8634e4,apiServer:{sandbox:"https://sandbox.familysearch.org",staging:"https://stage.familysearch.org",production:"https://familysearch.org"},oauthServer:{sandbox:"https://sandbox.familysearch.org/cis-web/oauth2/v3",staging:"https://identbeta.familysearch.org/cis-web/oauth2/v3",production:"https://ident.familysearch.org/cis-web/oauth2/v3"},authoritiesServer:{sandbox:"https://sandbox.familysearch.org",staging:"https://stage.familysearch.org",production:"https://api.familysearch.org"},discoveryUrl:"/.well-known/app-meta"}),e("helpers",["globals"],function(e){function t(e,t){for(var n in e)if(e.hasOwnProperty(n)&&t[n]!==e[n])return!1;return!0}function n(e,t){return c.isAbsoluteUrl(t)?t:e+("/"!==t.charAt(0)?"/":"")+t}function r(t,n,r){return r&&e.clearTimeout(r),e.setTimeout(function(){t()},n)}function i(e){a=r(c.eraseAccessToken,e,a)}function o(e){l=r(c.eraseAccessToken,e,l)}function s(){e.clearTimeout(a),a=null,e.clearTimeout(l),l=null}var c={};Object.create||(Object.create=function(){function e(){}return function(t){if(1!==arguments.length)throw new Error("Object.create implementation only accepts one parameter.");return e.prototype=t,new e}}()),"function"!=typeof Object.getPrototypeOf&&(Object.getPrototypeOf="object"==typeof"".__proto__?function(e){return e.__proto__}:function(e){return e.constructor.prototype}),c.isArray=function(e){return Array.isArray?Array.isArray(e):"[object Array]"==Object.prototype.toString.call(e)},c.isNumber=function(e){return"[object Number]"==Object.prototype.toString.call(e)},c.isNumeric=function(e){return!isNaN(parseFloat(e))&&isFinite(e)},c.isString=function(e){return"[object String]"==Object.prototype.toString.call(e)},c.isFunction=function(e){return"function"!=typeof/./?"function"==typeof e:"[object Function]"==Object.prototype.toString.call(e)},c.isObject=function(e){return e===Object(e)},c.isUndefined=function(e){return void 0===e};var u=c.forEach=function(e,t,n){if(null!=e)if(Array.prototype.forEach&&e.forEach===Array.prototype.forEach)e.forEach(t,n);else if(e.length===+e.length){for(var r=0,i=e.length;i>r;r++)if(t.call(n,e[r],r,e)==={})return}else for(var o in e)if(e.hasOwnProperty(o)&&t.call(n,e[o],o,e)==={})return};c.keys=Object.keys||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n);return t},c.filter=function(e,n,r){var i=[],o=c.isFunction(n);return u(e,function(e){(o?n.call(r,e):t(n,e))&&i.push(e)}),i},c.map=function(e,t,n){var r=[];return u(e,function(e,i,o){r.push(t.call(n,e,i,o))}),r},c.contains=function(e,t){if(null==e)return!1;if(e.indexOf&&e.indexOf===Array.prototype.indexOf)return-1!==e.indexOf(t);var n=!1;return u(e,function(e){e===t&&(n=!0)}),n},c.indexOf=function(e,t){if(Array.prototype.indexOf===e.indexOf)return e.indexOf(t);for(var n=0,r=e.length;r>n;n++)if(e[n]===t)return n;return-1},c.uniq=function(e){var t=[];return u(e,function(e){c.contains(t,e)||t.push(e)}),t},c.find=function(e,n,r){var i,o=c.isFunction(n);if(e)for(var s=0,u=e.length;u>s;s++){var a=e[s];if(o?n.call(r,a):t(n,a)){i=a;break}}return i},c.compose=function(){var e=arguments;return function(){for(var t=arguments,n=e.length-1;n>=0;n--)t=[e[n].apply(this,t)];return t[0]}},c.flatten=function(e){var t=[];return u(e,function(e){c.isArray(e)&&Array.prototype.push.apply(t,e)}),t},c.flatMap=c.compose(c.flatten,c.map),c.union=function(){return c.uniq(c.flatten(arguments))},c.findOrFirst=function(e,t){var n=c.find(e,t);return c.isUndefined(n)?e[0]:n},c.extend=function(e){return e=e||{},u(Array.prototype.slice.call(arguments,1),function(t){t&&u(t,function(t,n){e[n]=t})}),e},c.appFieldRejector=function(e){return!(c.isString(e)&&"_"===e.charAt(0))},c.deletePropertiesPartial=function(e,t){for(var n in e)!e.hasOwnProperty(n)||t&&!t(n)||delete e[n]},c.clonePartial=function(e,t){var n;if(null==e||"object"!=typeof e)return e;if(e instanceof Date)return n=new Date,n.setTime(e.getTime()),n;if(e instanceof Array){n=[];for(var r=0,i=e.length;i>r;r++)(!t||t(r))&&n.push(c.clonePartial(e[r],t));return n}if(e instanceof Object){n=Object.create(Object.getPrototypeOf(e));for(var o in e)!e.hasOwnProperty(o)||t&&!t(o)||(n[o]=c.clonePartial(e[o],t));return n}throw new Error("Unable to copy obj")},c.partialRight=function(e){var t=Array.prototype.slice.call(arguments,1);return function(){return e.apply(this,Array.prototype.slice.call(arguments).concat(t))}},c.partial=function(e){var t=Array.prototype.slice.call(arguments,1);return function(){return e.apply(this,t.concat(Array.prototype.slice.call(arguments)))}},c.maybe=function(e){return null!=e?e:{}},c.objectExtender=function(e,t){return function(n){return n&&(t?u(t(n),function(t){c.extend(t,c.isFunction(e)?e(n,t):e)}):c.extend(n,c.isFunction(e)?e(n,n):e)),n}},c.constructorSetter=function(e,t,n){var r;return n?(r=c.constructorSetter(e,t),function(e){if(c.isObject(e)){var t=n(e);c.isArray(t)?c.forEach(t,function(e){r(e)}):c.isObject(t)&&r(t)}return e}):t?(r=c.constructorSetter(e),function(e){return c.isObject(e)&&(c.isArray(e[t])?e[t]=c.map(e[t],function(e){return r(e)}):c.isObject(e[t])&&(e[t]=r(e[t]))),e}):function(t){var n=Object.create(e.prototype);return c.extend(n,t),n}},c.wrapFunctions=function(e,t,n){return u(n,function(n){e[n]=function(){return t[n].apply(t,arguments)}}),e},c.extendHttpPromise=function(e,t){return c.wrapFunctions(e,t,["getResponseHeader","getAllResponseHeaders","getStatusCode","getRequest"])},c.chainHttpPromises=function(){var e=arguments[0],t={};return u(Array.prototype.slice.call(arguments,1),function(n){e=e.then(function(){var e=n.apply(null,arguments);return e&&e.then&&c.extendHttpPromise(t,e),e})}),c.extendHttpPromise(e,t),e},c.removeEmptyProperties=function(e){return u(e,function(t,n){(null==t||""===t)&&delete e[n]}),e},c.getLastUrlSegment=function(e){return e&&(e=e.replace(/^.*\//,"").replace(/\?.*$/,"")),e},c.getResponseEntityId=function(e,t){return t.getResponseHeader("X-ENTITY-ID")},c.getResponseLocation=function(e,t){return c.removeAccessToken(t.getResponseHeader("Location"))},c.handleRedirect=function(t,n){var r=e.deferredWrapper(),i=function(){200===t.getStatusCode()||204===t.getStatusCode()?r.resolve(n(t)):r.reject(arguments)};return t.then(i,i),c.extendHttpPromise(r.promise,t)},c.isAbsoluteUrl=function(e){return/^https?:\/\//.test(e)},c.isOAuthServerUrl=function(t){return 0===t.indexOf(e.oauthServer[e.environment])},c.getAPIServerUrl=function(t){return n(e.apiServer[e.environment],t)},c.isAuthoritiesServerUrl=function(e){return-1!==e.indexOf("/authorities/v1/")},c.getAuthoritiesServerUrl=function(t){return n(e.authoritiesServer[e.environment],t)},c.encodeQueryString=function(e){var t=[];return u(e,function(e,n){n=encodeURIComponent(n);var r;r=c.isArray(e)?c.map(e,function(e){return n+"="+encodeURIComponent(e)}).join("&"):null!=e?n+"="+encodeURIComponent(e):n,t.push(r)}),t.join("&")},c.appendQueryParameters=function(e,t){var n=c.encodeQueryString(t);return 0===n.length?e:e+(e.indexOf("?")>=0?"&":"?")+n},c.decodeQueryString=function(e){var t={};if(e){var n=e.indexOf("?");if(-1!==n){var r=e.substring(n+1).split("&");u(r,function(e){var n=e.split("=",2);if(n&&n[0]){var r=decodeURIComponent(n[0]),i=null!=n[1]?decodeURIComponent(n[1]):n[1];null==t[r]||c.isArray(t[r])||(t[r]=[t[r]]),null!=t[r]?t[r].push(i):t[r]=i}})}}return t},c.removeQueryString=function(e){if(e){var t=e.indexOf("?");-1!==t&&(e=e.substring(0,t))}return e},c.appendAccessToken=function(t){if(t){var n=c.decodeQueryString(t);t=c.removeQueryString(t),n.access_token=e.accessToken,t=c.appendQueryParameters(t,n)}return t},c.removeAccessToken=function(e){if(e){var t=c.decodeQueryString(e);e=c.removeQueryString(e),delete t.access_token,e=c.appendQueryParameters(e,t)}return e},c.populateUriTemplate=function(e,t){for(var n=e.split(/[{}]/),r=!1,i=0,o=n.length;o>i;i++)if(i%2===1){var s=t[n[i]];n[i]=r?encodeURIComponent(s):encodeURI(s)}else-1!==n[i].indexOf("?")&&(r=!0);return n.join("")},c.getUrlFromDiscoveryResource=function(e,t,n){var r="",i=e.links[t];if(i.href)r=c.removeAccessToken(i.href);else if(i.template){var o=i.template.replace(/{\?[^}]*}/,"");r=c.populateUriTemplate(o,n||{})}return r},c.attributionNeeded=function(e){return!(e.attribution&&e.attribution.changeMessage&&!e.attribution.contributor)},c.log=function(){e.debug&&console.log.apply(null,arguments)},c.nextTick=function(t){e.setTimeout(function(){t()},0)},c.refPromise=function(t){return t&&c.isFunction(t.then)?t:{then:function(n){var r=e.deferredWrapper();return c.nextTick(function(){r.resolve(n(t))}),r.promise}}},c.promiseAll=function(t){var n=e.deferredWrapper(),r=0,i=c.isArray(t)?[]:{};return u(t,function(e,t){r++,c.refPromise(e).then(function(e){i.hasOwnProperty(t)||(i[t]=e,--r||n.resolve(i))},function(){i.hasOwnProperty(t)||n.reject.apply(n,arguments)})}),0===r&&n.resolve(i),n.promise},c.createCookie=function(e,t,n){var r="",i="https"===document.location.protocol&&"localhost"!==document.location.hostname;if(n){var o=new Date;o.setTime(o.getTime()+86400*n),r="; expires="+o.toUTCString()}document.cookie=e+"="+t+r+"; path=/"+(i?"; secure":"")},c.readCookie=function(e){for(var t=e+"=",n=document.cookie.split(";"),r=0;r=200&&299>=p&&!e.responseText?a.resolve(null):a.reject(e,t,n)}),t.wrapFunctions(l,u,["getResponseHeader","getAllResponseHeaders"]),l.getStatusCode=function(){return p},l.getRequest=function(){return c},l}},n.deferredWrapper=function(e){return function(){var t=e();return{promise:t.promise(),resolve:t.resolve,reject:t.reject}}},n}),e("plumbing",["globals","helpers"],function(e,t){function n(e){var t,r,i,o,s,c,u,a="";for(t in e)if(e.hasOwnProperty(t))if(r=e[t],r instanceof Array)for(u=0;u=500&&p>0||429===r){var i=$.getResponseHeader("Retry-After"),h=i?parseInt(i,10):e.defaultThrottleRetryAfter;e.setTimeout(function(){$=o.http(n,s,c,u,a,l,p-1),t.extendHttpPromise(f,$),$.then(function(e){d.resolve(e)},function(){d.reject.apply(d,arguments)})},h)}else d.reject.apply(d,arguments)})},function(){d.reject.apply(d,arguments)}),f},o}),e("init",["angularjs-wrappers","globals","helpers","jquery-wrappers","plumbing"],function(e,t,n,r,i){var o={};return o.init=function(o){if(o=o||{},!o.app_key)throw"app_key must be set";if(t.appKey=o.app_key,!o.environment)throw"environment must be set";if(t.environment=o.environment,!o.http_function)throw"http must be set; e.g., jQuery.ajax";var s=o.http_function;if(t.httpWrapper=s.defaults?e.httpWrapper(s):r.httpWrapper(s),!o.deferred_function)throw"deferred_function must be set; e.g., jQuery.Deferred";var c=o.deferred_function,u=c();u.resolve(),t.deferredWrapper=n.isFunction(u.promise)?r.deferredWrapper(c):e.deferredWrapper(c);var a=o.timeout_function;a?(t.setTimeout=function(e,t){return a(e,t)},t.clearTimeout=function(e){a.cancel(e)}):(t.setTimeout=function(e,t){return setTimeout(e,t)},t.clearTimeout=function(e){clearTimeout(e)}),t.authCallbackUri=o.auth_callback,t.autoSignin=o.auto_signin,t.autoExpire=o.auto_expire,o.save_access_token&&(t.saveAccessToken=!0,n.readAccessToken()),o.access_token&&(t.accessToken=o.access_token),t.debug=o.debug,t.discoveryPromise=i.get(t.discoveryUrl),t.discoveryPromise.then(function(e){t.discoveryResource=e})},o}),e("authentication",["globals","helpers","plumbing"],function(e,t,n){function r(e,n){e.then(function(e){var r=e.access_token;r?(t.setAccessToken(r),n.resolve(r)):n.reject(e.error)},function(){n.reject.apply(n,arguments)})}function i(e,n){var r=t.isUndefined(window.screenX)?window.screenLeft:window.screenX,i=t.isUndefined(window.screenY)?window.screenTop:window.screenY,o=t.isUndefined(window.outerWidth)?document.documentElement.clientWidth:window.outerWidth,s=t.isUndefined(window.outerHeight)?document.documentElement.clientHeight-22:window.outerHeight,c=n.width||780,u=n.height||500,a=parseInt(r+(o-c)/2,10),l=parseInt(i+(s-u)/2.5,10),p="width="+c+",height="+u+",left="+a+",top="+l;return window.open(t.appendQueryParameters(e,n),"",p)}function o(n){var r=e.deferredWrapper();if(n)var i=setInterval(function(){try{if(n.location.hostname===window.location.hostname){var e=t.decodeQueryString(n.location.href);clearInterval(i),n.close(),e.code?r.resolve(e.code):r.reject(e.error)}}catch(o){}},e.authCodePollDelay);else r.reject("Popup blocked");return r.promise}var s={};return s.getAuthCode=function(){return n.getUrl("http://oauth.net/core/2.0/endpoint/authorize").then(function(t){var n=i(t,{response_type:"code",client_id:e.appKey,redirect_uri:e.authCallbackUri});return o(n)})},e.getAccessToken=s.getAccessToken=function(i){var o=e.deferredWrapper();if(e.accessToken)t.nextTick(function(){o.resolve(e.accessToken)});else{var c;c=i?t.refPromise(i):s.getAuthCode(),c.then(function(t){n.getUrl("http://oauth.net/core/2.0/endpoint/token").then(function(i){var s=n.post(i,{grant_type:"authorization_code",code:t,client_id:e.appKey},{"Content-Type":"application/x-www-form-urlencoded"});r(s,o)})},function(){o.reject.apply(o,arguments)})}return o.promise},s.getAccessTokenForMobile=function(t,i){var o=e.deferredWrapper();return n.getUrl("http://oauth.net/core/2.0/endpoint/token").then(function(s){var c=n.post(s,{grant_type:"password",client_id:e.appKey,username:t,password:i},{"Content-Type":"application/x-www-form-urlencoded"});r(c,o)}),o.promise},s.hasAccessToken=function(){return!!e.accessToken},s.invalidateAccessToken=function(){return t.eraseAccessToken(),t.chainHttpPromises(n.getUrl("http://oauth.net/core/2.0/endpoint/token"),function(){return""})},s}),e("authorities",["helpers","plumbing"],function(e,t){var n=e.maybe,r={},i=r.Date=function(){},o=r.constructFormalDate=function(e,t){var n,r="",i="",o="",s="",c="+",u=0;"about"===e[u]?(t||(r="A"),u++):"before"===e[u]?(t||(r="A/"),u++):"after"===e[u]&&(t||(r="A",i="/"),u++),e[u].length<=2&&(o=(1===e[u].length?"0":"")+e[u],u++);var a=["january","february","march","april","may","june","july","august","september","october","november","december"].indexOf(e[u])+1;return a>0&&(s=(10>a?"0":"")+a.toString(),u++),n=e[u],u++,u=0&&(t=t.slice(0,n)),"from"===t[0]?(n=t.indexOf("to"),e=o(t.slice(1,n),!0)+"/"+o(t.slice(n+1),!0)):e=o(t,!1)}return e}};var s=r.Place=function(){};return r.Place.prototype={constructor:s,$getNormalizedPlace:function(){return n(this.normalized)[0]}},r.getDate=function(r,o){var s={date:r,dataFormat:"application/json"};return t.get(e.getAuthoritiesServerUrl("/authorities/v1/date"),s,{Accept:"application/json"},o,e.compose(e.objectExtender({getDate:function(){return n(n(this.dates).date)[0]}}),e.constructorSetter(i,"date",function(e){return e.dates})))},r.getPlaceSearch=function(r,i){var o={place:r,view:"simple",dataFormat:"application/json"};return t.get(e.getAuthoritiesServerUrl("/authorities/v1/place"),o,{Accept:"application/json"},i,e.compose(e.objectExtender({getPlaces:function(){return n(this.places).place}}),e.constructorSetter(s,"place",function(e){return e.places})))},r}),e("user",["globals","helpers","plumbing"],function(e,t,n){var r=t.maybe,i={},o=i.User=function(){};i.User.prototype={constructor:o};var s=i.Agent=function(){};return i.Agent.prototype={constructor:s,$getName:function(){return r(r(this.names)[0]).value},$getAccountName:function(){return r(r(this.accounts)[0]).accountName},$getEmail:function(){var e=r(r(this.emails)[0]).resource;return e?e.replace(/^mailto:/,""):e}},i.getCurrentUser=function(e,i){return t.chainHttpPromises(n.getUrl("current-user"),function(s){return n.get(s,e,{},i,t.compose(t.objectExtender({getUser:function(){return r(this.users)[0]}}),t.constructorSetter(o,"users")))})},i.getAgent=function(e,i,o){return t.chainHttpPromises(n.getUrl("agent-template",e,{uid:e}),function(e){return n.get(e,i,{},o,t.compose(t.objectExtender({getAgent:function(){return r(this.agents)[0]}}),t.constructorSetter(s,"agents")))})},i.getMultiAgent=function(e,n,r){var o={};return t.forEach(e,function(e){o[e]=i.getAgent(e,n,r)}),t.promiseAll(o)},i}),e("changeHistory",["helpers","plumbing","user"],function(e,t,n){var r=e.maybe,i={},o=i.Change=function(){};i.Change.prototype={constructor:o,$getAgentName:function(){return r(r(this.contributors)[0]).name},$getChangeReason:function(){return r(r(this.changeInfo)[0]).reason},$getAgentUrl:function(){return e.removeAccessToken(this.links.agent.href)},$getAgent:function(){return n.getAgent(this.$getAgentUrl())}};var s=e.compose(e.objectExtender({getChanges:function(){return this.entries||[]}}),e.constructorSetter(o,"entries"));return i.getPersonChanges=function(n,r,i){return e.chainHttpPromises(t.getUrl("person-changes-template",n,{pid:n}),function(e){return t.get(e,r,{Accept:"application/x-gedcomx-atom+json"},i,s)})},i.getChildAndParentsChanges=function(n,r,i){return e.chainHttpPromises(t.getUrl("child-and-parents-relationship-changes-template",n,{caprid:n}),function(e){return t.get(e,r,{Accept:"application/x-gedcomx-atom+json"},i,s)})},i.getCoupleChanges=function(n,r,i){return e.chainHttpPromises(t.getUrl("couple-relationship-changes-template",n,{crid:n}),function(e){return t.get(e,r,{Accept:"application/x-gedcomx-atom+json"},i,s)})},i}),e("attribution",["helpers","plumbing","user"],function(e,t,n){var r=e.maybe,i={},o=i.Attribution=function(e){e&&(this.changeMessage=e)};return i.Attribution.prototype={constructor:o,$getAgentId:function(){return r(this.contributor).resourceId},$getAgentUrl:function(){return e.removeAccessToken(r(this.contributor).resource)},$getAgent:function(){return n.getAgent(this.$getAgentUrl()||this.$getAgentId())}},i}),e("discussions",["attribution","globals","helpers","plumbing","user"],function(e,t,n,r,i){var o=n.maybe,s={},c=s.Discussion=function(e){e&&(this.title=e.title,this.details=e.details)};s.Discussion.prototype={constructor:c,$getCommentsUrl:function(){return n.removeAccessToken(o(o(this.links).comments).href)},$getComments:function(){return s.getDiscussionComments(this.$getCommentsUrl())},$getAgentId:function(){return o(this.contributor).resourceId},$getAgentUrl:function(){return n.removeAccessToken(o(this.contributor).resource)},$getAgent:function(){return i.getAgent(this.$getAgentUrl()||this.$getAgentId())},$save:function(e,t,i){var o=this,c=n.chainHttpPromises(o.id?r.getUrl("discussion-template",null,{did:o.id}):r.getUrl("discussions"),function(e){return r.post(e,{discussions:[o]},{"Content-Type":"application/x-fs-v1+json"},i,function(e,t){return o.id||t.getResponseHeader("X-ENTITY-ID")})}),u=c.then(function(e){return n.extendHttpPromise(u,c),t?s.getDiscussion(e,{},i).then(function(t){return n.deletePropertiesPartial(o,n.appFieldRejector),n.extend(o,t.getDiscussion()),e}):e});return u},$delete:function(e,t){return s.deleteDiscussion(this.id,e,t)}};var u=s.DiscussionRef=function(e){e&&(this.$personId=e.$personId,e.discussion&&this.$setDiscussion(e.discussion))};s.DiscussionRef.prototype={constructor:u,$getDiscussionRefUrl:function(){return n.removeAccessToken(o(n.find(this.links,{title:"Discussion Reference"})).href)},$getDiscussionUrl:function(){return n.removeAccessToken(this.resource)},$getDiscussion:function(){return s.getDiscussion(this.$getDiscussionUrl()||this.resourceId)},$setDiscussion:function(e){return e instanceof c?this.resourceId=e.id:n.isAbsoluteUrl(e)?this.resource=n.removeAccessToken(e):this.resourceId=e,this},$save:function(i,o){var s=this;return n.chainHttpPromises(r.getUrl("person-discussion-references-template",null,{pid:s.$personId}),function(c){!s.resource&&s.resourceId&&(s.resource=n.getUrlFromDiscoveryResource(t.discoveryResource,"discussion-template",{did:s.resourceId}));var u={persons:[{id:s.$personId,"discussion-references":[s.resource]}]};i&&(u.persons[0].attribution=new e.Attribution(i));var a={"Content-Type":"application/x-fs-v1+json","X-FS-Feature-Tag":"discussion-reference-json-fix"};return r.post(c,u,a,o,function(e,t){return s.$getDiscussionRefUrl()||(s.links=[{href:t.getResponseHeader("Location"),title:"Discussion Reference"}]),s.$getDiscussionRefUrl()})})},$delete:function(e,t){return s.deleteDiscussionRef(this.$getDiscussionRefUrl(),null,e,t)}};var a=s.Comment=function(e){e&&(this.text=e.text,this.$discussionId=e.$discussionId,this.$memoryId=e.$memoryId)};return s.Comment.prototype={constructor:a,$getCommentUrl:function(){return n.removeAccessToken(o(o(this.links).comment).href)},$getAgentId:function(){return o(this.contributor).resourceId},$getAgentUrl:function(){return n.removeAccessToken(o(this.contributor).resource)},$getAgent:function(){return i.getAgent(this.$getAgentUrl()||this.$getAgentId())},$save:function(e,t){var i=this,o=this.$memoryId?"memory-comments-template":"discussion-comments-template";return n.chainHttpPromises(r.getUrl(o,null,{did:i.$discussionId,mid:i.$memoryId}),function(e){var n={discussions:[{comments:[i]}]};return r.post(e,n,{"Content-Type":"application/x-fs-v1+json"},t,function(e,t){return i.id||(i.id=t.getResponseHeader("X-ENTITY-ID")),i.$getCommentUrl()||(i.links={comment:{href:t.getResponseHeader("Location")}}),i.id})})},$delete:function(e,t){return this.$discussionId?s.deleteDiscussionComment(this.$getCommentUrl()||this.$discussionId,this.id,e,t):s.deleteMemoryComment(this.$getCommentUrl()||this.$memoryId,this.id,e,t)}},s.getDiscussion=function(e,t,i){return n.chainHttpPromises(r.getUrl("discussion-template",e,{did:e}),function(e){return r.get(e,t,{Accept:"application/x-fs-v1+json"},i,n.compose(n.objectExtender({getDiscussion:function(){return o(o(this).discussions)[0]}}),n.constructorSetter(c,"discussions")))})},s.getMultiDiscussion=function(e,t,r){var i={};return n.forEach(e,function(e){var n,o;e instanceof u?(o=e.$getDiscussionUrl(),n=e.resourceId):(o=e,n=e),i[n]=s.getDiscussion(o,t,r)}),n.promiseAll(i)},s.getPersonDiscussionRefs=function(e,t,i){return n.chainHttpPromises(r.getUrl("person-discussion-references-template",e,{pid:e}),function(e){return r.get(e,t,{Accept:"application/x-fs-v1+json","X-FS-Feature-Tag":"discussion-reference-json-fix"},i,n.compose(n.objectExtender({getDiscussionRefs:function(){return o(o(o(this).persons)[0])["discussion-references"]||[]}}),n.constructorSetter(u,"discussion-references",function(e){return o(o(e).persons)[0]}),n.objectExtender(function(e){return{$personId:o(o(o(e).persons)[0]).id}},function(e){return o(o(o(e).persons)[0])["discussion-references"]})))})},s.commentsResponseMapper=n.compose(n.objectExtender({getComments:function(){return o(o(o(this).discussions)[0]).comments||[]}}),n.constructorSetter(a,"comments",function(e){return o(o(e).discussions)[0]})),s.getDiscussionComments=function(e,t,i){return n.chainHttpPromises(r.getUrl("discussion-comments-template",e,{did:e}),function(e){return r.get(e,t,{Accept:"application/x-fs-v1+json"},i,n.compose(s.commentsResponseMapper,n.objectExtender(function(e){return{$discussionId:o(o(o(e).discussions)[0]).id}},function(e){return o(o(o(e).discussions)[0]).comments})))})},s.deleteDiscussion=function(e,t,i){return n.chainHttpPromises(r.getUrl("discussion-template",e,{did:e}),function(t){return r.del(t,{"Content-Type":"application/x-fs-v1+json"},i,function(){return e})})},s.deleteDiscussionRef=function(e,t,i,o){return n.chainHttpPromises(r.getUrl("person-discussion-reference-template",e,{pid:e,drid:t}),function(t){var n={"Content-Type":"application/x-fs-v1+json"};return i&&(n["X-Reason"]=i),r.del(t,n,o,function(){return e})})},s.deleteDiscussionComment=function(e,t,i,o){return n.chainHttpPromises(r.getUrl("discussion-comment-template",e,{did:e,cmid:t}),function(t){return r.del(t,{"Content-Type":"application/x-fs-v1+json"},o,function(){return e})})},s.deleteMemoryComment=function(e,t,i,o){return n.chainHttpPromises(r.getUrl("memory-comment-template",e,{mid:e,cmid:t}),function(t){return r.del(t,{},o,function(){return e})})},s}),e("fact",["attribution","authorities","helpers"],function(e,t,n){var r=n.maybe,i={},o=i.Fact=function(e){e&&(e.type&&this.$setType(e.type),e.date&&this.$setDate(e.date),e.formalDate&&this.$setFormalDate(e.formalDate),e.place&&this.$setPlace(e.place),e.normalizedPlace&&this.$setNormalizedPlace(e.normalizedPlace),e.changeMessage&&this.$setChangeMessage(e.changeMessage))};return i.Fact.prototype={constructor:o,$getDate:function(){return r(this.date).original},$getNormalizedDate:function(){return r(r(r(this.date).normalized)[0]).value},$getFormalDate:function(){return r(this.date).formal},$getPlace:function(){return r(this.place).original},$getNormalizedPlace:function(){return r(r(r(this.place).normalized)[0]).value},$getNormalizedPlaceId:function(){var e=r(this.place).description;return e&&"#"===e.charAt(0)?e.substr(1):""},$setType:function(e){return this.$changed=!0,this.type=e,this},$setDate:function(e){return this.$changed=!0,this.date||(this.date={}),n.isString(e)?this.date.original=e:e instanceof t.Date?(this.date.original=e.original,this.$setFormalDate(e.$getFormalDate()),this.$setNormalizedDate(e.normalized)):n.isObject(e)&&(e.original&&(this.date.original=e.original),e.formal&&this.$setFormalDate(e.formal),e.normalized&&this.$setNormalizedDate(e.normalized)),this},$setFormalDate:function(e){return this.$changed=!0,this.date||(this.date={}),this.date.formal=e,this},$setNormalizedDate:function(e){return this.$changed=!0,this.date||(this.date={}),this.date.normalized=[{value:e}],this},$setPlace:function(e){return this.$changed=!0,this.place||(this.place={}),n.isString(e)?this.place.original=e:e instanceof t.Place?(this.place.original=e.original,this.$setNormalizedPlace(e.$getNormalizedPlace())):n.isObject(e)&&(e.original&&(this.place.original=e.original),e.normalized&&this.$setNormalizedPlace(e.normalized)),this},$setNormalizedPlace:function(e){return this.$changed=!0,this.place||(this.place={}),this.place.normalized=[{value:e}],this},$setChangeMessage:function(t){return this.attribution=new e.Attribution(t),this}},i}),e("name",["attribution","helpers"],function(e,t){function n(e,n){var r=n||0;for(t.isArray(e.nameForms)||(e.nameForms=[]);r>=e.nameForms.length;)e.nameForms.push({});return e.nameForms[r]}var r=t.maybe,i={},o=i.Name=function(e){e&&(t.isString(e)?this.$setFullText(e):(e.type&&this.$setType(e.type),e.givenName&&this.$setGivenName(e.givenName),e.surname&&this.$setSurname(e.surname),e.prefix&&this.$setPrefix(e.prefix),e.suffix&&this.$setSuffix(e.suffix),e.fullText&&this.$setFullText(e.fullText),this.$setPreferred(!!e.preferred),e.changeMessage&&this.$setChangeMessage(e.changeMessage)))};return i.Name.prototype={constructor:o,$getNameFormsCount:function(){return this.nameForms?this.nameForms.length:0 +!function(e,t){"object"==typeof module&&"object"==typeof module.exports?module.exports=t():"function"==typeof define&&define.amd?define(t):e.FamilySearch=t()}(this,function(){function e(e,t,r){n[e]={deps:3===arguments.length?t:[],fn:3===arguments.length?r:t}}function t(e){var i=n[e],o=[],s=i.fn;if("function"==typeof s){for(var c=0,u=i.deps.length;u>c;c++){var a=i.deps[c],l=r[a];void 0===l&&(l=t(a),r[a]=l),o.push(l)}s=i.fn.apply(this,o)}return s}var n={},r={};return e("globals",{appKey:null,environment:null,httpWrapper:null,deferredWrapper:null,setTimeout:null,clearTimeout:null,authCallbackUri:null,autoSignin:!1,autoExpire:!1,accessToken:null,saveAccessToken:!1,logging:!1,accessTokenCookie:"FS_ACCESS_TOKEN",authCodePollDelay:50,defaultThrottleRetryAfter:500,maxHttpRequestRetries:2,maxAccessTokenInactivityTime:354e4,maxAccessTokenCreationTime:8634e4,apiServer:{sandbox:"https://sandbox.familysearch.org",staging:"https://stage.familysearch.org",production:"https://familysearch.org"},oauthServer:{sandbox:"https://sandbox.familysearch.org/cis-web/oauth2/v3",staging:"https://identbeta.familysearch.org/cis-web/oauth2/v3",production:"https://ident.familysearch.org/cis-web/oauth2/v3"},authoritiesServer:{sandbox:"https://sandbox.familysearch.org",staging:"https://stage.familysearch.org",production:"https://api.familysearch.org"},discoveryUrl:"/.well-known/app-meta"}),e("helpers",["globals"],function(e){function t(e,t){for(var n in e)if(e.hasOwnProperty(n)&&t[n]!==e[n])return!1;return!0}function n(e,t){return c.isAbsoluteUrl(t)?t:e+("/"!==t.charAt(0)?"/":"")+t}function r(t,n,r){return r&&e.clearTimeout(r),e.setTimeout(function(){t()},n)}function i(e){a=r(c.eraseAccessToken,e,a)}function o(e){l=r(c.eraseAccessToken,e,l)}function s(){e.clearTimeout(a),a=null,e.clearTimeout(l),l=null}var c={};Object.create||(Object.create=function(){function e(){}return function(t){if(1!==arguments.length)throw new Error("Object.create implementation only accepts one parameter.");return e.prototype=t,new e}}()),"function"!=typeof Object.getPrototypeOf&&(Object.getPrototypeOf="object"==typeof"".__proto__?function(e){return e.__proto__}:function(e){return e.constructor.prototype}),c.isArray=function(e){return Array.isArray?Array.isArray(e):"[object Array]"==Object.prototype.toString.call(e)},c.isNumber=function(e){return"[object Number]"==Object.prototype.toString.call(e)},c.isNumeric=function(e){return!isNaN(parseFloat(e))&&isFinite(e)},c.isString=function(e){return"[object String]"==Object.prototype.toString.call(e)},c.isFunction=function(e){return"function"!=typeof/./?"function"==typeof e:"[object Function]"==Object.prototype.toString.call(e)},c.isObject=function(e){return e===Object(e)},c.isUndefined=function(e){return void 0===e};var u=c.forEach=function(e,t,n){if(null!=e)if(Array.prototype.forEach&&e.forEach===Array.prototype.forEach)e.forEach(t,n);else if(e.length===+e.length){for(var r=0,i=e.length;i>r;r++)if(t.call(n,e[r],r,e)==={})return}else for(var o in e)if(e.hasOwnProperty(o)&&t.call(n,e[o],o,e)==={})return};c.keys=Object.keys||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n);return t},c.filter=function(e,n,r){var i=[],o=c.isFunction(n);return u(e,function(e){(o?n.call(r,e):t(n,e))&&i.push(e)}),i},c.map=function(e,t,n){var r=[];return u(e,function(e,i,o){r.push(t.call(n,e,i,o))}),r},c.contains=function(e,t){if(null==e)return!1;if(e.indexOf&&e.indexOf===Array.prototype.indexOf)return-1!==e.indexOf(t);var n=!1;return u(e,function(e){e===t&&(n=!0)}),n},c.indexOf=function(e,t){if(Array.prototype.indexOf===e.indexOf)return e.indexOf(t);for(var n=0,r=e.length;r>n;n++)if(e[n]===t)return n;return-1},c.uniq=function(e){var t=[];return u(e,function(e){c.contains(t,e)||t.push(e)}),t},c.find=function(e,n,r){var i,o=c.isFunction(n);if(e)for(var s=0,u=e.length;u>s;s++){var a=e[s];if(o?n.call(r,a):t(n,a)){i=a;break}}return i},c.compose=function(){var e=arguments;return function(){for(var t=arguments,n=e.length-1;n>=0;n--)t=[e[n].apply(this,t)];return t[0]}},c.flatten=function(e){var t=[];return u(e,function(e){c.isArray(e)&&Array.prototype.push.apply(t,e)}),t},c.flatMap=c.compose(c.flatten,c.map),c.union=function(){return c.uniq(c.flatten(arguments))},c.findOrFirst=function(e,t){var n=c.find(e,t);return c.isUndefined(n)?e[0]:n},c.extend=function(e){return e=e||{},u(Array.prototype.slice.call(arguments,1),function(t){t&&u(t,function(t,n){e[n]=t})}),e},c.appFieldRejector=function(e){return!(c.isString(e)&&"_"===e.charAt(0))},c.deletePropertiesPartial=function(e,t){for(var n in e)!e.hasOwnProperty(n)||t&&!t(n)||delete e[n]},c.clonePartial=function(e,t){var n;if(null==e||"object"!=typeof e)return e;if(e instanceof Date)return n=new Date,n.setTime(e.getTime()),n;if(e instanceof Array){n=[];for(var r=0,i=e.length;i>r;r++)(!t||t(r))&&n.push(c.clonePartial(e[r],t));return n}if(e instanceof Object){n=Object.create(Object.getPrototypeOf(e));for(var o in e)!e.hasOwnProperty(o)||t&&!t(o)||(n[o]=c.clonePartial(e[o],t));return n}throw new Error("Unable to copy obj")},c.partialRight=function(e){var t=Array.prototype.slice.call(arguments,1);return function(){return e.apply(this,Array.prototype.slice.call(arguments).concat(t))}},c.partial=function(e){var t=Array.prototype.slice.call(arguments,1);return function(){return e.apply(this,t.concat(Array.prototype.slice.call(arguments)))}},c.maybe=function(e){return null!=e?e:{}},c.objectExtender=function(e,t){return function(n){return n&&(t?u(t(n),function(t){c.extend(t,c.isFunction(e)?e(n,t):e)}):c.extend(n,c.isFunction(e)?e(n,n):e)),n}},c.constructorSetter=function(e,t,n){var r;return n?(r=c.constructorSetter(e,t),function(e){if(c.isObject(e)){var t=n(e);c.isArray(t)?c.forEach(t,function(e){r(e)}):c.isObject(t)&&r(t)}return e}):t?(r=c.constructorSetter(e),function(e){return c.isObject(e)&&(c.isArray(e[t])?e[t]=c.map(e[t],function(e){return r(e)}):c.isObject(e[t])&&(e[t]=r(e[t]))),e}):function(t){var n=Object.create(e.prototype);return c.extend(n,t),n}},c.wrapFunctions=function(e,t,n){return u(n,function(n){e[n]=function(){return t[n].apply(t,arguments)}}),e},c.extendHttpPromise=function(e,t){return c.wrapFunctions(e,t,["getResponseHeader","getAllResponseHeaders","getStatusCode","getRequest"])},c.chainHttpPromises=function(){var e=arguments[0],t={};return u(Array.prototype.slice.call(arguments,1),function(n){e=e.then(function(){var e=n.apply(null,arguments);return e&&e.then&&c.extendHttpPromise(t,e),e})}),c.extendHttpPromise(e,t),e},c.removeEmptyProperties=function(e){return u(e,function(t,n){(null==t||""===t)&&delete e[n]}),e},c.getLastUrlSegment=function(e){return e&&(e=e.replace(/^.*\//,"").replace(/\?.*$/,"")),e},c.getResponseEntityId=function(e,t){return t.getResponseHeader("X-ENTITY-ID")},c.getResponseLocation=function(e,t){return c.removeAccessToken(t.getResponseHeader("Location"))},c.handleRedirect=function(t,n){var r=e.deferredWrapper(),i=function(){200===t.getStatusCode()||204===t.getStatusCode()?r.resolve(n(t)):r.reject(arguments)};return t.then(i,i),c.extendHttpPromise(r.promise,t)},c.isAbsoluteUrl=function(e){return/^https?:\/\//.test(e)},c.isOAuthServerUrl=function(t){return 0===t.indexOf(e.oauthServer[e.environment])},c.getAPIServerUrl=function(t){return n(e.apiServer[e.environment],t)},c.isAuthoritiesServerUrl=function(e){return-1!==e.indexOf("/authorities/v1/")},c.getAuthoritiesServerUrl=function(t){return n(e.authoritiesServer[e.environment],t)},c.encodeQueryString=function(e){var t=[];return u(e,function(e,n){n=encodeURIComponent(n);var r;r=c.isArray(e)?c.map(e,function(e){return n+"="+encodeURIComponent(e)}).join("&"):null!=e?n+"="+encodeURIComponent(e):n,t.push(r)}),t.join("&")},c.appendQueryParameters=function(e,t){var n=c.encodeQueryString(t);return 0===n.length?e:e+(e.indexOf("?")>=0?"&":"?")+n},c.decodeQueryString=function(e){var t={};if(e){var n=e.indexOf("?");if(-1!==n){var r=e.substring(n+1).split("&");u(r,function(e){var n=e.split("=",2);if(n&&n[0]){var r=decodeURIComponent(n[0]),i=null!=n[1]?decodeURIComponent(n[1]):n[1];null==t[r]||c.isArray(t[r])||(t[r]=[t[r]]),null!=t[r]?t[r].push(i):t[r]=i}})}}return t},c.removeQueryString=function(e){if(e){var t=e.indexOf("?");-1!==t&&(e=e.substring(0,t))}return e},c.appendAccessToken=function(t){if(t){var n=c.decodeQueryString(t);t=c.removeQueryString(t),n.access_token=e.accessToken,t=c.appendQueryParameters(t,n)}return t},c.removeAccessToken=function(e){if(e){var t=c.decodeQueryString(e);e=c.removeQueryString(e),delete t.access_token,e=c.appendQueryParameters(e,t)}return e},c.populateUriTemplate=function(e,t){for(var n=e.split(/[{}]/),r=!1,i=0,o=n.length;o>i;i++)if(i%2===1){var s=t[n[i]];n[i]=r?encodeURIComponent(s):encodeURI(s)}else-1!==n[i].indexOf("?")&&(r=!0);return n.join("")},c.getUrlFromDiscoveryResource=function(e,t,n){var r="",i=e.links[t];if(i.href)r=c.removeAccessToken(i.href);else if(i.template){var o=i.template.replace(/{\?[^}]*}/,"");r=c.populateUriTemplate(o,n||{})}return r},c.attributionNeeded=function(e){return!(e.attribution&&e.attribution.changeMessage&&!e.attribution.contributor)},c.log=function(){e.debug&&console.log.apply(null,arguments)},c.nextTick=function(t){e.setTimeout(function(){t()},0)},c.refPromise=function(t){return t&&c.isFunction(t.then)?t:{then:function(n){var r=e.deferredWrapper();return c.nextTick(function(){r.resolve(n(t))}),r.promise}}},c.promiseAll=function(t){var n=e.deferredWrapper(),r=0,i=c.isArray(t)?[]:{};return u(t,function(e,t){r++,c.refPromise(e).then(function(e){i.hasOwnProperty(t)||(i[t]=e,--r||n.resolve(i))},function(){i.hasOwnProperty(t)||n.reject.apply(n,arguments)})}),0===r&&n.resolve(i),n.promise},c.createCookie=function(e,t,n){var r="",i="https"===document.location.protocol&&"localhost"!==document.location.hostname;if(n){var o=new Date;o.setTime(o.getTime()+86400*n),r="; expires="+o.toUTCString()}document.cookie=e+"="+t+r+"; path=/"+(i?"; secure":"")},c.readCookie=function(e){for(var t=e+"=",n=document.cookie.split(";"),r=0;r=200&&299>=p&&!e.responseText?a.resolve(null):a.reject(e,t,n)}),t.wrapFunctions(l,u,["getResponseHeader","getAllResponseHeaders"]),l.getStatusCode=function(){return p},l.getRequest=function(){return c},l}},n.deferredWrapper=function(e){return function(){var t=e();return{promise:t.promise(),resolve:t.resolve,reject:t.reject}}},n}),e("plumbing",["globals","helpers"],function(e,t){function n(e){var t,r,i,o,s,c,u,a="";for(t in e)if(e.hasOwnProperty(t))if(r=e[t],r instanceof Array)for(u=0;u=500&&p>0||429===r){var i=$.getResponseHeader("Retry-After"),h=i?parseInt(i,10):e.defaultThrottleRetryAfter;e.setTimeout(function(){$=o.http(n,s,c,u,a,l,p-1),t.extendHttpPromise(f,$),$.then(function(e){d.resolve(e)},function(){d.reject.apply(d,arguments)})},h)}else d.reject.apply(d,arguments)})},function(){d.reject.apply(d,arguments)}),f},o}),e("init",["angularjs-wrappers","globals","helpers","jquery-wrappers","plumbing"],function(e,t,n,r,i){var o={};return o.init=function(o){if(o=o||{},!o.app_key)throw"app_key must be set";if(t.appKey=o.app_key,!o.environment)throw"environment must be set";if(t.environment=o.environment,!o.http_function)throw"http must be set; e.g., jQuery.ajax";var s=o.http_function;if(t.httpWrapper=s.defaults?e.httpWrapper(s):r.httpWrapper(s),!o.deferred_function)throw"deferred_function must be set; e.g., jQuery.Deferred";var c=o.deferred_function,u=c();u.resolve(),t.deferredWrapper=n.isFunction(u.promise)?r.deferredWrapper(c):e.deferredWrapper(c);var a=o.timeout_function;a?(t.setTimeout=function(e,t){return a(e,t)},t.clearTimeout=function(e){a.cancel(e)}):(t.setTimeout=function(e,t){return setTimeout(e,t)},t.clearTimeout=function(e){clearTimeout(e)}),t.authCallbackUri=o.auth_callback,t.autoSignin=o.auto_signin,t.autoExpire=o.auto_expire,o.save_access_token&&(t.saveAccessToken=!0,n.readAccessToken()),o.access_token&&(t.accessToken=o.access_token),t.debug=o.debug,t.discoveryPromise=i.get(t.discoveryUrl),t.discoveryPromise.then(function(e){t.discoveryResource=e})},o}),e("authentication",["globals","helpers","plumbing"],function(e,t,n){function r(e,n){e.then(function(e){var r=e.access_token;r?(t.setAccessToken(r),n.resolve(r)):n.reject(e.error)},function(){n.reject.apply(n,arguments)})}function i(e,n){var r=t.isUndefined(window.screenX)?window.screenLeft:window.screenX,i=t.isUndefined(window.screenY)?window.screenTop:window.screenY,o=t.isUndefined(window.outerWidth)?document.documentElement.clientWidth:window.outerWidth,s=t.isUndefined(window.outerHeight)?document.documentElement.clientHeight-22:window.outerHeight,c=n.width||780,u=n.height||500,a=parseInt(r+(o-c)/2,10),l=parseInt(i+(s-u)/2.5,10),p="width="+c+",height="+u+",left="+a+",top="+l;return window.open(t.appendQueryParameters(e,n),"",p)}function o(n){var r=e.deferredWrapper();if(n)var i=setInterval(function(){try{if(n.location.hostname===window.location.hostname){var e=t.decodeQueryString(n.location.href);clearInterval(i),n.close(),e.code?r.resolve(e.code):r.reject(e.error)}}catch(o){}},e.authCodePollDelay);else r.reject("Popup blocked");return r.promise}var s={};return s.getAuthCode=function(){return n.getUrl("http://oauth.net/core/2.0/endpoint/authorize").then(function(t){var n=i(t,{response_type:"code",client_id:e.appKey,redirect_uri:e.authCallbackUri});return o(n)})},e.getAccessToken=s.getAccessToken=function(i){var o=e.deferredWrapper();if(e.accessToken)t.nextTick(function(){o.resolve(e.accessToken)});else{var c;c=i?t.refPromise(i):s.getAuthCode(),c.then(function(t){n.getUrl("http://oauth.net/core/2.0/endpoint/token").then(function(i){var s=n.post(i,{grant_type:"authorization_code",code:t,client_id:e.appKey},{"Content-Type":"application/x-www-form-urlencoded"});r(s,o)})},function(){o.reject.apply(o,arguments)})}return o.promise},s.getAccessTokenForMobile=function(t,i){var o=e.deferredWrapper();return n.getUrl("http://oauth.net/core/2.0/endpoint/token").then(function(s){var c=n.post(s,{grant_type:"password",client_id:e.appKey,username:t,password:i},{"Content-Type":"application/x-www-form-urlencoded"});r(c,o)}),o.promise},s.hasAccessToken=function(){return!!e.accessToken},s.invalidateAccessToken=function(){return t.eraseAccessToken(),t.chainHttpPromises(n.getUrl("http://oauth.net/core/2.0/endpoint/token"),function(){return""})},s}),e("authorities",["helpers","plumbing"],function(e,t){var n=e.maybe,r={},i=r.Date=function(){},o=r.constructFormalDate=function(e,t){var n,r="",i="",o="",s="",c="+",u=0;"about"===e[u]?(t||(r="A"),u++):"before"===e[u]?(t||(r="A/"),u++):"after"===e[u]&&(t||(r="A",i="/"),u++),e[u].length<=2&&(o=(1===e[u].length?"0":"")+e[u],u++);var a=["january","february","march","april","may","june","july","august","september","october","november","december"].indexOf(e[u])+1;return a>0&&(s=(10>a?"0":"")+a.toString(),u++),n=e[u],u++,u=0&&(t=t.slice(0,n)),"from"===t[0]?(n=t.indexOf("to"),e=o(t.slice(1,n),!0)+"/"+o(t.slice(n+1),!0)):e=o(t,!1)}return e}};var s=r.Place=function(){};return r.Place.prototype={constructor:s,$getNormalizedPlace:function(){return n(this.normalized)[0]}},r.getDate=function(r,o){var s={date:r,dataFormat:"application/json"};return t.get(e.getAuthoritiesServerUrl("/authorities/v1/date"),s,{Accept:"application/json"},o,e.compose(e.objectExtender({getDate:function(){return n(n(this.dates).date)[0]}}),e.constructorSetter(i,"date",function(e){return e.dates})))},r.getPlaceSearch=function(r,i){var o={place:r,view:"simple",dataFormat:"application/json"};return t.get(e.getAuthoritiesServerUrl("/authorities/v1/place"),o,{Accept:"application/json"},i,e.compose(e.objectExtender({getPlaces:function(){return n(this.places).place}}),e.constructorSetter(s,"place",function(e){return e.places})))},r}),e("user",["globals","helpers","plumbing"],function(e,t,n){var r=t.maybe,i={},o=i.User=function(){};i.User.prototype={constructor:o};var s=i.Agent=function(){};return i.Agent.prototype={constructor:s,$getName:function(){return r(r(this.names)[0]).value},$getAccountName:function(){return r(r(this.accounts)[0]).accountName},$getEmail:function(){var e=r(r(this.emails)[0]).resource;return e?e.replace(/^mailto:/,""):e}},i.getCurrentUser=function(e,i){return t.chainHttpPromises(n.getUrl("current-user"),function(s){return n.get(s,e,{},i,t.compose(t.objectExtender({getUser:function(){return r(this.users)[0]}}),t.constructorSetter(o,"users")))})},i.getAgent=function(e,i,o){return t.chainHttpPromises(n.getUrl("agent-template",e,{uid:e}),function(e){return n.get(e,i,{},o,t.compose(t.objectExtender({getAgent:function(){return r(this.agents)[0]}}),t.constructorSetter(s,"agents")))})},i.getMultiAgent=function(e,n,r){var o={};return t.forEach(e,function(e){o[e]=i.getAgent(e,n,r)}),t.promiseAll(o)},i}),e("changeHistory",["helpers","plumbing","user"],function(e,t,n){var r=e.maybe,i={},o=i.Change=function(){};i.Change.prototype={constructor:o,$getAgentName:function(){return r(r(this.contributors)[0]).name},$getChangeReason:function(){return r(r(this.changeInfo)[0]).reason},$getAgentUrl:function(){return e.removeAccessToken(this.links.agent.href)},$getAgent:function(){return n.getAgent(this.$getAgentUrl())}};var s=e.compose(e.objectExtender({getChanges:function(){return this.entries||[]}}),e.constructorSetter(o,"entries"));return i.getPersonChanges=function(n,r,i){return e.chainHttpPromises(t.getUrl("person-changes-template",n,{pid:n}),function(e){return t.get(e,r,{Accept:"application/x-gedcomx-atom+json"},i,s)})},i.getChildAndParentsChanges=function(n,r,i){return e.chainHttpPromises(t.getUrl("child-and-parents-relationship-changes-template",n,{caprid:n}),function(e){return t.get(e,r,{Accept:"application/x-gedcomx-atom+json"},i,s)})},i.getCoupleChanges=function(n,r,i){return e.chainHttpPromises(t.getUrl("couple-relationship-changes-template",n,{crid:n}),function(e){return t.get(e,r,{Accept:"application/x-gedcomx-atom+json"},i,s)})},i}),e("attribution",["helpers","plumbing","user"],function(e,t,n){var r=e.maybe,i={},o=i.Attribution=function(e){e&&(this.changeMessage=e)};return i.Attribution.prototype={constructor:o,$getAgentId:function(){return r(this.contributor).resourceId},$getAgentUrl:function(){return e.removeAccessToken(r(this.contributor).resource)},$getAgent:function(){return n.getAgent(this.$getAgentUrl()||this.$getAgentId())}},i}),e("discussions",["attribution","globals","helpers","plumbing","user"],function(e,t,n,r,i){var o=n.maybe,s={},c=s.Discussion=function(e){e&&(this.title=e.title,this.details=e.details)};s.Discussion.prototype={constructor:c,$getCommentsUrl:function(){return n.removeAccessToken(o(o(this.links).comments).href)},$getComments:function(){return s.getDiscussionComments(this.$getCommentsUrl())},$getAgentId:function(){return o(this.contributor).resourceId},$getAgentUrl:function(){return n.removeAccessToken(o(this.contributor).resource)},$getAgent:function(){return i.getAgent(this.$getAgentUrl()||this.$getAgentId())},$save:function(e,t,i){var o=this,c=n.chainHttpPromises(o.id?r.getUrl("discussion-template",null,{did:o.id}):r.getUrl("discussions"),function(e){return r.post(e,{discussions:[o]},{"Content-Type":"application/x-fs-v1+json"},i,function(e,t){return o.id||t.getResponseHeader("X-ENTITY-ID")})}),u=c.then(function(e){return n.extendHttpPromise(u,c),t?s.getDiscussion(e,{},i).then(function(t){return n.deletePropertiesPartial(o,n.appFieldRejector),n.extend(o,t.getDiscussion()),e}):e});return u},$delete:function(e,t){return s.deleteDiscussion(this.id,e,t)}};var u=s.DiscussionRef=function(e){e&&(this.$personId=e.$personId,e.discussion&&this.$setDiscussion(e.discussion))};s.DiscussionRef.prototype={constructor:u,$getDiscussionRefUrl:function(){return n.removeAccessToken(o(o(this.links)["discussion-reference"]).href)},$getDiscussionUrl:function(){return n.removeAccessToken(this.resource)},$getDiscussion:function(){return s.getDiscussion(this.$getDiscussionUrl()||this.resourceId)},$setDiscussion:function(e){return e instanceof c?this.resourceId=e.id:n.isAbsoluteUrl(e)?this.resource=n.removeAccessToken(e):this.resourceId=e,this},$save:function(i,o){var s=this;return n.chainHttpPromises(r.getUrl("person-discussion-references-template",null,{pid:s.$personId}),function(c){!s.resource&&s.resourceId&&(s.resource=n.getUrlFromDiscoveryResource(t.discoveryResource,"discussion-template",{did:s.resourceId}));var u={persons:[{id:s.$personId,"discussion-references":[{resource:s.resource}]}]};i&&(u.persons[0].attribution=new e.Attribution(i));var a={"Content-Type":"application/x-fs-v1+json","X-FS-Feature-Tag":"discussion-reference-json-fix"};return r.post(c,u,a,o,function(e,t){return s.$getDiscussionRefUrl()||(s.links={"discussion-reference":{href:t.getResponseHeader("Location"),title:"Discussion Reference"}}),s.$getDiscussionRefUrl()})})},$delete:function(e,t){return s.deleteDiscussionRef(this.$getDiscussionRefUrl(),null,e,t)}};var a=s.Comment=function(e){e&&(this.text=e.text,this.$discussionId=e.$discussionId,this.$memoryId=e.$memoryId)};return s.Comment.prototype={constructor:a,$getCommentUrl:function(){return n.removeAccessToken(o(o(this.links).comment).href)},$getAgentId:function(){return o(this.contributor).resourceId},$getAgentUrl:function(){return n.removeAccessToken(o(this.contributor).resource)},$getAgent:function(){return i.getAgent(this.$getAgentUrl()||this.$getAgentId())},$save:function(e,t){var i=this,o=this.$memoryId?"memory-comments-template":"discussion-comments-template";return n.chainHttpPromises(r.getUrl(o,null,{did:i.$discussionId,mid:i.$memoryId}),function(e){var n={discussions:[{comments:[i]}]};return r.post(e,n,{"Content-Type":"application/x-fs-v1+json"},t,function(e,t){return i.id||(i.id=t.getResponseHeader("X-ENTITY-ID")),i.$getCommentUrl()||(i.links={comment:{href:t.getResponseHeader("Location")}}),i.id})})},$delete:function(e,t){return this.$discussionId?s.deleteDiscussionComment(this.$getCommentUrl()||this.$discussionId,this.id,e,t):s.deleteMemoryComment(this.$getCommentUrl()||this.$memoryId,this.id,e,t)}},s.getDiscussion=function(e,t,i){return n.chainHttpPromises(r.getUrl("discussion-template",e,{did:e}),function(e){return r.get(e,t,{Accept:"application/x-fs-v1+json"},i,n.compose(n.objectExtender({getDiscussion:function(){return o(o(this).discussions)[0]}}),n.constructorSetter(c,"discussions")))})},s.getMultiDiscussion=function(e,t,r){var i={};return n.forEach(e,function(e){var n,o;e instanceof u?(o=e.$getDiscussionUrl(),n=e.resourceId):(o=e,n=e),i[n]=s.getDiscussion(o,t,r)}),n.promiseAll(i)},s.getPersonDiscussionRefs=function(e,t,i){return n.chainHttpPromises(r.getUrl("person-discussion-references-template",e,{pid:e}),function(e){return r.get(e,t,{Accept:"application/x-fs-v1+json","X-FS-Feature-Tag":"discussion-reference-json-fix"},i,n.compose(n.objectExtender({getDiscussionRefs:function(){return o(o(o(this).persons)[0])["discussion-references"]||[]}}),n.constructorSetter(u,"discussion-references",function(e){return o(o(e).persons)[0]}),n.objectExtender(function(e){return{$personId:o(o(o(e).persons)[0]).id}},function(e){return o(o(o(e).persons)[0])["discussion-references"]})))})},s.commentsResponseMapper=n.compose(n.objectExtender({getComments:function(){return o(o(o(this).discussions)[0]).comments||[]}}),n.constructorSetter(a,"comments",function(e){return o(o(e).discussions)[0]})),s.getDiscussionComments=function(e,t,i){return n.chainHttpPromises(r.getUrl("discussion-comments-template",e,{did:e}),function(e){return r.get(e,t,{Accept:"application/x-fs-v1+json"},i,n.compose(s.commentsResponseMapper,n.objectExtender(function(e){return{$discussionId:o(o(o(e).discussions)[0]).id}},function(e){return o(o(o(e).discussions)[0]).comments})))})},s.deleteDiscussion=function(e,t,i){return n.chainHttpPromises(r.getUrl("discussion-template",e,{did:e}),function(t){return r.del(t,{"Content-Type":"application/x-fs-v1+json"},i,function(){return e})})},s.deleteDiscussionRef=function(e,t,i,o){return n.chainHttpPromises(r.getUrl("person-discussion-reference-template",e,{pid:e,drid:t}),function(t){var n={"Content-Type":"application/x-fs-v1+json"};return i&&(n["X-Reason"]=i),r.del(t,n,o,function(){return e})})},s.deleteDiscussionComment=function(e,t,i,o){return n.chainHttpPromises(r.getUrl("discussion-comment-template",e,{did:e,cmid:t}),function(t){return r.del(t,{"Content-Type":"application/x-fs-v1+json"},o,function(){return e})})},s.deleteMemoryComment=function(e,t,i,o){return n.chainHttpPromises(r.getUrl("memory-comment-template",e,{mid:e,cmid:t}),function(t){return r.del(t,{},o,function(){return e})})},s}),e("fact",["attribution","authorities","helpers"],function(e,t,n){var r=n.maybe,i={},o=i.Fact=function(e){e&&(e.type&&this.$setType(e.type),e.date&&this.$setDate(e.date),e.formalDate&&this.$setFormalDate(e.formalDate),e.place&&this.$setPlace(e.place),e.normalizedPlace&&this.$setNormalizedPlace(e.normalizedPlace),e.changeMessage&&this.$setChangeMessage(e.changeMessage))};return i.Fact.prototype={constructor:o,$getDate:function(){return r(this.date).original},$getNormalizedDate:function(){return r(r(r(this.date).normalized)[0]).value},$getFormalDate:function(){return r(this.date).formal},$getPlace:function(){return r(this.place).original},$getNormalizedPlace:function(){return r(r(r(this.place).normalized)[0]).value},$getNormalizedPlaceId:function(){var e=r(this.place).description;return e&&"#"===e.charAt(0)?e.substr(1):""},$setType:function(e){return this.$changed=!0,this.type=e,this},$setDate:function(e){return this.$changed=!0,this.date||(this.date={}),n.isString(e)?this.date.original=e:e instanceof t.Date?(this.date.original=e.original,this.$setFormalDate(e.$getFormalDate()),this.$setNormalizedDate(e.normalized)):n.isObject(e)&&(e.original&&(this.date.original=e.original),e.formal&&this.$setFormalDate(e.formal),e.normalized&&this.$setNormalizedDate(e.normalized)),this},$setFormalDate:function(e){return this.$changed=!0,this.date||(this.date={}),this.date.formal=e,this},$setNormalizedDate:function(e){return this.$changed=!0,this.date||(this.date={}),this.date.normalized=[{value:e}],this},$setPlace:function(e){return this.$changed=!0,this.place||(this.place={}),n.isString(e)?this.place.original=e:e instanceof t.Place?(this.place.original=e.original,this.$setNormalizedPlace(e.$getNormalizedPlace())):n.isObject(e)&&(e.original&&(this.place.original=e.original),e.normalized&&this.$setNormalizedPlace(e.normalized)),this},$setNormalizedPlace:function(e){return this.$changed=!0,this.place||(this.place={}),this.place.normalized=[{value:e}],this},$setChangeMessage:function(t){return this.attribution=new e.Attribution(t),this}},i}),e("name",["attribution","helpers"],function(e,t){function n(e,n){var r=n||0;for(t.isArray(e.nameForms)||(e.nameForms=[]);r>=e.nameForms.length;)e.nameForms.push({});return e.nameForms[r]}var r=t.maybe,i={},o=i.Name=function(e){e&&(t.isString(e)?this.$setFullText(e):(e.type&&this.$setType(e.type),e.givenName&&this.$setGivenName(e.givenName),e.surname&&this.$setSurname(e.surname),e.prefix&&this.$setPrefix(e.prefix),e.suffix&&this.$setSuffix(e.suffix),e.fullText&&this.$setFullText(e.fullText),this.$setPreferred(!!e.preferred),e.changeMessage&&this.$setChangeMessage(e.changeMessage)))};return i.Name.prototype={constructor:o,$getNameFormsCount:function(){return this.nameForms?this.nameForms.length:0 },$getFullText:function(e){return r(r(this.nameForms)[e||0]).fullText},$getNamePart:function(e,n){return r(t.find(r(r(this.nameForms)[n||0]).parts,{type:e})).value},$getGivenName:function(e){return this.$getNamePart("http://gedcomx.org/Given",e)},$getSurname:function(e){return this.$getNamePart("http://gedcomx.org/Surname",e)},$getPrefix:function(e){return this.$getNamePart("http://gedcomx.org/Prefix",e)},$getSuffix:function(e){return this.$getNamePart("http://gedcomx.org/Suffix",e)},$setType:function(e){return this.$changed=!0,this.type=e,this},$setPreferred:function(e){return this.$changed=!0,this.preferred=e,this},$setFullText:function(e,t){this.$changed=!0;var r=n(this,t);return r.fullText=e,this},$setNamePart:function(e,r,i){this.$changed=!0;var o=n(this,i);t.isArray(o.parts)||(o.parts=[]);var s=t.find(o.parts,{type:r});return s||(s={type:r},o.parts.push(s)),s.value=e,this},$setGivenName:function(e,t){return this.$setNamePart(e,"http://gedcomx.org/Given",t)},$setSurname:function(e,t){return this.$setNamePart(e,"http://gedcomx.org/Surname",t)},$setPrefix:function(e,t){return this.$setNamePart(e,"http://gedcomx.org/Prefix",t)},$setSuffix:function(e,t){return this.$setNamePart(e,"http://gedcomx.org/Suffix",t)},$setChangeMessage:function(t){return this.attribution=new e.Attribution(t),this}},i}),e("memories",["attribution","discussions","globals","helpers","name","plumbing"],function(e,t,n,r,i,o){var s=r.maybe,c={},u=c.Memory=function(e){e&&(e.title&&this.$setTitle(e.title),e.description&&this.$setDescription(e.description),e.filename&&this.$setArtifactFilename(e.filename),e.$data&&(this.$data=e.$data))};c.Memory.prototype={constructor:u,$getTitle:function(){return s(s(this.titles)[0]).value},$getDescription:function(){return s(s(this.description)[0]).value},$getIconUrl:function(){return r.appendAccessToken(s(s(this.links)["image-icon"]).href)},$getThumbnailUrl:function(){return r.appendAccessToken(s(s(this.links)["image-thumbnail"]).href)},$getImageUrl:function(){return r.appendAccessToken(s(s(this.links).image).href)},$getMemoryArtifactUrl:function(){return r.appendAccessToken(r.removeAccessToken(this.about))},$getMemoryUrl:function(){return r.removeAccessToken(s(s(this.links).description).href)},$getArtifactFilename:function(){return s(s(this.artifactMetadata)[0]).filename},$getArtifactType:function(){return s(s(this.artifactMetadata)[0]).artifactType},$getArtifactHeight:function(){return s(s(this.artifactMetadata)[0]).height},$getArtifactWidth:function(){return s(s(this.artifactMetadata)[0]).width},$getCommentsUrl:function(){return r.removeAccessToken(s(s(this.links).comments).href)},$getComments:function(){return c.getMemoryComments(this.$getCommentsUrl()||this.id)},$setTitle:function(e){return this.titles=[{value:e}],this},$setDescription:function(e){return this.description=[{value:e}],this},$setArtifactFilename:function(e){return r.isArray(this.artifactMetadata)&&this.artifactMetadata.length||(this.artifactMetadata=[{}]),this.artifactMetadata[0].filename=e,this},$save:function(e,t,n){var i=this,s=r.chainHttpPromises(i.id?o.getUrl("memory-template",null,{mid:i.id}):o.getUrl("memories"),function(e){if(i.id)return o.post(e,{sourceDescriptions:[i]},{},n,function(){return i.id});var t={};return i.$getTitle()&&(t.title=i.$getTitle()),i.$getDescription()&&(t.description=i.$getDescription()),i.$getArtifactFilename()&&(t.filename=i.$getArtifactFilename()),o.post(r.appendQueryParameters(e,t),i.$data,{"Content-Type":r.isString(i.$data)?"text/plain":"multipart/form-data"},n,r.getResponseEntityId)}),u=s.then(function(e){return r.extendHttpPromise(u,s),t?c.getMemory(e,{},n).then(function(t){return r.deletePropertiesPartial(i,r.appFieldRejector),r.extend(i,t.getMemory()),e}):e});return u},$delete:function(e,t){return c.deleteMemory(this.$getMemoryUrl()||this.id,e,t)}};var a=c.MemoryPersona=function(e){e&&(this.$memoryId=e.$memoryId,e.name&&this.$setName(e.name),e.memoryArtifactRef&&this.$setMemoryArtifactRef(e.memoryArtifactRef))};c.MemoryPersona.prototype={constructor:a,$getMemoryPersonaUrl:function(){return r.removeAccessToken(s(s(this.links).persona).href)},$getMemoryArtifactRef:function(){return s(this.media)[0]},$getName:function(){return s(this.names)[0]},$getDisplayName:function(){return s(this.display).name},$getMemoryUrl:function(){return r.removeAccessToken(s(this.$getMemoryArtifactRef()).description)},$getMemory:function(){return c.getMemory(this.$getMemoryUrl()||this.$memoryId)},$setName:function(e){return e instanceof i.Name||(e=new i.Name(e)),this.names=[e],this},$setMemoryArtifactRef:function(e){return this.media=[e],this},$save:function(e,t,i){var s=this,u=r.chainHttpPromises(o.getUrl(s.id?"memory-persona-template":"memory-personas-template",null,{mid:s.$memoryId,pid:s.id}),function(e){if(!s.$getMemoryArtifactRef()){var t=r.getUrlFromDiscoveryResource(n.discoveryResource,"memory-template",{mid:s.$memoryId});s.$setMemoryArtifactRef(new p({description:t}))}return o.post(e,{persons:[s]},{},i,function(e,t){return s.$getMemoryPersonaUrl()||r.removeAccessToken(t.getResponseHeader("Location"))})}),a=u.then(function(e){return r.extendHttpPromise(a,u),t?c.getMemoryPersona(e,null,{},i).then(function(t){return r.deletePropertiesPartial(s,r.appFieldRejector),r.extend(s,t.getMemoryPersona()),e}):e});return a},$delete:function(e,t){return c.deleteMemoryPersona(this.$getMemoryPersonaUrl()||this.$memoryId,this.id,e,t)}};var l=c.MemoryPersonaRef=function(e){e&&(this.$personId=e.$personId,e.memoryPersona&&this.$setMemoryPersona(e.memoryPersona))};c.MemoryPersonaRef.prototype={constructor:l,$getMemoryPersonaRefUrl:function(){return r.removeAccessToken(s(s(this.links)["evidence-reference"]).href)},$getMemoryPersonaUrl:function(){return r.removeAccessToken(this.resource)},$getMemoryPersona:function(){return c.getMemoryPersona(this.$getMemoryPersonaUrl())},$getMemoryUrl:function(){return this.resource?r.removeAccessToken(this.resource.replace(/(^.*\/memories\/[^\/]*)\/personas\/.*$/,"$1")):this.resource},$getMemory:function(){return c.getMemory(this.$getMemoryUrl())},$setMemoryPersona:function(e){return e instanceof a&&(e=e.$getMemoryPersonaUrl()),this.resource=r.removeAccessToken(e),this},$save:function(e,t){var n=this;return r.chainHttpPromises(o.getUrl("person-memory-persona-references-template",null,{pid:n.$personId}),function(e){return o.post(e,{persons:[{evidence:[n]}]},{},t,function(e,t){return n.id||(n.id=t.getResponseHeader("X-ENTITY-ID")),n.$getMemoryPersonaRefUrl()||(n.links={"evidence-reference":{href:t.getResponseHeader("Location")}}),n.$getMemoryPersonaRefUrl()})})},$delete:function(e,t){return c.deleteMemoryPersonaRef(this.$getMemoryPersonaRefUrl()||this.$personId,this.id,e,t)}};var p=c.MemoryArtifactRef=function(e){e&&(this.description=e.description,e.qualifierName&&this.$setQualifierName(e.qualifierName),e.qualifierValue&&this.$setQualifierValue(e.qualifierValue))};c.MemoryArtifactRef.prototype={constructor:p,$getQualifierName:function(){return s(s(this.qualifiers)[0]).name},$getQualifierValue:function(){return s(s(this.qualifiers)[0]).value},$setQualifierName:function(e){return r.isArray(this.qualifiers)&&this.qualifiers.length||(this.qualifiers=[{}]),this.qualifiers[0].name=e,this},$setQualifierValue:function(e){return r.isArray(this.qualifiers)&&this.qualifiers.length||(this.qualifiers=[{}]),this.qualifiers[0].value=e,this}},c.getPersonMemoriesQuery=function(t,n,i){return r.chainHttpPromises(o.getUrl("person-memories-query",t,{pid:t}),function(t){return o.get(t,n,{},i,r.compose(r.objectExtender({getMemories:function(){return this.sourceDescriptions||[]}}),r.constructorSetter(u,"sourceDescriptions"),r.constructorSetter(e.Attribution,"attribution",function(e){return e.sourceDescriptions})))})},c.getUserMemoriesQuery=function(t,n,i){return r.chainHttpPromises(o.getUrl("user-memories-query",t,{cisUserId:t}),function(t){return o.get(t,n,{},i,r.compose(r.objectExtender({getMemories:function(){return this.sourceDescriptions||[]}}),r.constructorSetter(u,"sourceDescriptions"),r.constructorSetter(e.Attribution,"attribution",function(e){return e.sourceDescriptions})))})},c.getMemory=function(t,n,i){return r.chainHttpPromises(o.getUrl("memory-template",t,{mid:t}),function(t){return o.get(t,n,{},i,r.compose(r.objectExtender({getMemory:function(){return s(this.sourceDescriptions)[0]}}),r.constructorSetter(u,"sourceDescriptions"),r.constructorSetter(e.Attribution,"attribution",function(e){return e.sourceDescriptions})))})},c.getMemoryComments=function(e,n,i){return r.chainHttpPromises(o.getUrl("memory-comments-template",e,{mid:e}),function(e){return o.get(e,n,{Accept:"application/x-fs-v1+json"},i,r.compose(t.commentsResponseMapper,r.objectExtender(function(e){return{$memoryId:s(s(s(e).sourceDescriptions)[0]).id}},function(e){return s(s(s(e).discussions)[0]).comments})))})};var d=r.compose(r.constructorSetter(a,"persons"),r.constructorSetter(i.Name,"names",function(e){return s(e).persons}),r.constructorSetter(p,"media",function(e){return s(e).persons}),r.objectExtender(function(e){return{$memoryId:s(s(e.sourceDescriptions)[0]).id}},function(e){return s(e).persons}));return c.getMemoryPersonas=function(e,t,n){return r.chainHttpPromises(o.getUrl("memory-personas-template",e,{mid:e}),function(e){return o.get(e,t,{},n,r.compose(r.objectExtender({getMemoryPersonas:function(){return this&&this.persons?this.persons:[]}}),d))})},c.getMemoryPersona=function(e,t,n,i){return r.chainHttpPromises(o.getUrl("memory-persona-template",e,{mid:e,pid:t}),function(e){return o.get(e,n,{},i,r.compose(r.objectExtender({getMemoryPersona:function(){return s(this.persons)[0]}}),d))})},c.getMemoryPersonaRefs=function(e,t,n){return r.chainHttpPromises(o.getUrl("person-memory-persona-references-template",e,{pid:e}),function(e){return o.get(e,t,{},n,r.compose(r.objectExtender({getMemoryPersonaRefs:function(){return s(s(this.persons)[0]).evidence||[]}}),r.constructorSetter(l,"evidence",function(e){return s(s(e).persons)[0]}),r.objectExtender(function(e){return{$personId:s(s(s(e).persons)[0]).id}},function(e){return s(s(s(e).persons)[0]).evidence})))})},c.getPersonPortraitUrl=function(e,t,n){return o.getUrl("person-portrait-template",e,{pid:e}).then(function(e){if(t&&t.followRedirect){t=r.extend({},t),delete t.followRedirect;var i=o.get(e,t,{},n);return r.handleRedirect(i,function(e){return 204===e.getStatusCode()?"":r.appendAccessToken(e.getResponseHeader("Content-Location"))})}return r.appendAccessToken(e)})},c.deleteMemory=function(e,t,n){return r.chainHttpPromises(o.getUrl("memory-template",e,{mid:e}),function(t){return o.del(t,{},n,function(){return e})})},c.deleteMemoryPersona=function(e,t,n,i){return r.chainHttpPromises(o.getUrl("memory-persona-template",e,{mid:e,pid:t}),function(t){return o.del(t,{},i,function(){return e})})},c.deleteMemoryPersonaRef=function(e,t,n,i){return r.chainHttpPromises(o.getUrl("person-memory-persona-reference-template",e,{pid:e,erid:t}),function(t){return o.del(t,{},i,function(){return e})})},c}),e("notes",["attribution","helpers","plumbing"],function(e,t,n){function r(e){if(e){if(e.persons)return e.persons;if(e.childAndParentsRelationships)return e.childAndParentsRelationships;if(e.relationships)return e.relationships}return{}}function i(i,o,c){return n.get(i,o,{Accept:"application/x-fs-v1+json"},c,t.compose(t.objectExtender({getNote:function(){return s(s(r(this)[0]).notes)[0]}}),t.constructorSetter(u,"notes",function(e){return r(e)[0]}),t.constructorSetter(e.Attribution,"attribution",function(e){return s(r(e)[0]).notes}),t.objectExtender(function(e){var t=e.persons?"$personId":e.childAndParentsRelationships?"$childAndParentsId":"$coupleId",n={};return n[t]=s(r(e)[0]).id,n},function(e){return s(r(e)[0]).notes})))}function o(e,n,r,i,o){var s={};return t.isArray(e)?t.forEach(e,function(e){var t,n;e instanceof a?(t=e.id,n=e.$getNoteUrl()):(t=e,n=e),s[t]=o(n,null,r,i)}):t.forEach(n,function(t){s[t]=o(e,t,r,i)}),s}var s=t.maybe,c={},u=c.Note=function(e){e&&(this.subject=e.subject,this.text=e.text,this.$personId=e.$personId,this.$childAndParentsId=e.$childAndParentsId,this.$coupleId=e.$coupleId)};c.Note.prototype={constructor:u,$getNoteUrl:function(){return t.removeAccessToken(s(s(this.links).note).href)},$save:function(r,i,o){var s,u,a=this,l={};a.$personId?(s=a.id?"person-note-template":"person-notes-template",u="persons"):a.$coupleId?(s=a.id?"couple-relationship-note-template":"couple-relationship-notes-template",u="relationships"):a.$childAndParentsId&&(s=a.id?"child-and-parents-relationship-note-template":"child-and-parents-relationship-notes-template",u="childAndParentsRelationships",l["Content-Type"]="application/x-fs-v1+json");var p=t.chainHttpPromises(n.getUrl(s,null,{pid:a.$personId,crid:a.$coupleId,caprid:a.$childAndParentsId,nid:a.id}),function(i){var s={};return s[u]=[{notes:[a]}],r&&(s[u][0].attribution=new e.Attribution(r)),n.post(i,s,l,o,function(e,n){return{id:a.id||n.getResponseHeader("X-ENTITY-ID"),location:a.$getNoteUrl()||t.removeAccessToken(n.getResponseHeader("Location"))}})}),d=p.then(function(e){return t.extendHttpPromise(d,p),i?c.getPersonNote(e.location,null,{},o).then(function(n){return t.deletePropertiesPartial(a,t.appFieldRejector),t.extend(a,n.getNote()),e.id}):e.id});return d},$delete:function(e,t){return this.$personId?c.deletePersonNote(this.$getNoteUrl()||this.$personId,this.id,e,t):this.$coupleId?c.deleteCoupleNote(this.$getNoteUrl()||this.$coupleId,this.id,e,t):c.deleteChildAndParentsNote(this.$getNoteUrl()||this.$childAndParentsId,this.id,e,t)}};var a=c.NoteRef=function(){};return c.NoteRef.prototype={constructor:a,$getNoteUrl:function(){return t.removeAccessToken(s(s(this.links).note).href)},$getNote:function(){return this.$personId?c.getPersonNote(this.$getNoteUrl()||this.$personId,this.id):this.$coupleId?c.getCoupleNote(this.$getNoteUrl()||this.$coupleId,this.id):c.getChildAndParentsNote(this.$getNoteUrl()||this.$childAndParentsId,this.id)},$delete:function(e,t){return this.$personId?c.deletePersonNote(this.$getNoteUrl()||this.$personId,this.id,e,t):this.$coupleId?c.deleteCoupleNote(this.$getNoteUrl()||this.$coupleId,this.id,e,t):c.deleteChildAndParentsNote(this.$getNoteUrl()||this.$childAndParentsId,this.id,e,t)}},c.getPersonNote=function(e,r,o,s){return e instanceof a&&(e=e.$getNoteUrl()),t.chainHttpPromises(n.getUrl("person-note-template",e,{pid:e,nid:r}),function(e){return i(e,o,s)})},c.getMultiPersonNote=function(e,n,r,i){var s=o(e,n,r,i,c.getPersonNote);return t.promiseAll(s)},c.getCoupleNote=function(e,r,o,s){return e instanceof a&&(e=e.$getNoteUrl()),t.chainHttpPromises(n.getUrl("couple-relationship-note-template",e,{crid:e,nid:r}),function(e){return i(e,o,s)})},c.getMultiCoupleNote=function(e,n,r,i){var s=o(e,n,r,i,c.getCoupleNote);return t.promiseAll(s)},c.getChildAndParentsNote=function(e,r,o,s){return e instanceof a&&(e=e.$getNoteUrl()),t.chainHttpPromises(n.getUrl("child-and-parents-relationship-note-template",e,{caprid:e,nid:r}),function(e){return i(e,o,s)})},c.getMultiChildAndParentsNote=function(e,n,r,i){var s=o(e,n,r,i,c.getChildAndParentsNote);return t.promiseAll(s)},c.getPersonNoteRefs=function(e,r,i){return t.chainHttpPromises(n.getUrl("person-notes-template",e,{pid:e}),function(e){return n.get(e,r,{},i,t.compose(t.objectExtender({getNoteRefs:function(){return s(s(s(this).persons)[0]).notes||[]}}),t.constructorSetter(a,"notes",function(e){return s(s(e).persons)[0]}),t.objectExtender(function(e){return{$personId:s(s(s(e).persons)[0]).id}},function(e){return s(s(s(e).persons)[0]).notes})))})},c.getCoupleNoteRefs=function(e,r,i){return t.chainHttpPromises(n.getUrl("couple-relationship-notes-template",e,{crid:e}),function(e){return n.get(e,r,{},i,t.compose(t.objectExtender({getNoteRefs:function(){return s(s(this.relationships)[0]).notes||[]}}),t.constructorSetter(a,"notes",function(e){return s(s(e).relationships)[0]}),t.objectExtender(function(e){return{$coupleId:s(s(s(e).relationships)[0]).id}},function(e){return s(s(s(e).relationships)[0]).notes})))})},c.getChildAndParentsNoteRefs=function(e,r,i){return t.chainHttpPromises(n.getUrl("child-and-parents-relationship-notes-template",e,{caprid:e}),function(e){return n.get(e,r,{Accept:"application/x-fs-v1+json"},i,t.compose(t.objectExtender({getNoteRefs:function(){return s(s(this.childAndParentsRelationships)[0]).notes||[]}}),t.constructorSetter(a,"notes",function(e){return s(s(e).childAndParentsRelationships)[0]}),t.objectExtender(function(e){return{$childAndParentsId:s(s(s(e).childAndParentsRelationships)[0]).id}},function(e){return s(s(s(e).childAndParentsRelationships)[0]).notes})))})},c.deletePersonNote=function(e,r,i,o){return t.chainHttpPromises(n.getUrl("person-note-template",e,{pid:e,nid:r}),function(t){var r={"Content-Type":"application/x-fs-v1+json"};return i&&(r["X-Reason"]=i),n.del(t,r,o,function(){return e})})},c.deleteCoupleNote=function(e,r,i,o){return t.chainHttpPromises(n.getUrl("couple-relationship-note-template",e,{crid:e,nid:r}),function(t){var r={};return i&&(r["X-Reason"]=i),n.del(t,r,o,function(){return e})})},c.deleteChildAndParentsNote=function(e,r,i,o){return t.chainHttpPromises(n.getUrl("child-and-parents-relationship-note-template",e,{caprid:e,nid:r}),function(t){var r={"Content-Type":"application/x-fs-v1+json"};return i&&(r["X-Reason"]=i),n.del(t,r,o,function(){return e})})},c}),e("sources",["attribution","globals","helpers","plumbing"],function(e,t,n,r){function i(r,i){return n.compose(n.objectExtender({getSourceRefs:function(){return o(o(this[r])[0]).sources||[]},getSourceDescriptions:function(){return this.sourceDescriptions||[]},getSourceDescription:function(e){return n.find(this.sourceDescriptions,{id:e})}}),n.constructorSetter(u,"sources",function(e){return o(o(e)[r])[0]}),n.constructorSetter(e.Attribution,"attribution",function(e){return o(o(o(e)[r])[0]).sources}),n.objectExtender(function(e,s){var c=s.description.substr(1),u={$sourceDescriptionId:c,$sourceDescriptionUrl:n.getUrlFromDiscoveryResource(t.discoveryResource,"source-description-template",{sdid:c})};return u[i]=o(o(o(e)[r])[0]).id,u},function(e){return o(o(o(e)[r])[0]).sources}),n.constructorSetter(c,"sourceDescriptions"),n.constructorSetter(e.Attribution,"attribution",function(e){return e.sourceDescriptions}))}var o=n.maybe,s={},c=s.SourceDescription=function(e){e&&(this.about=e.about,e.citation&&this.$setCitation(e.citation),e.title&&this.$setTitle(e.title),e.text&&this.$setText(e.text))};s.SourceDescription.prototype={constructor:c,$getCitation:function(){return o(o(this.citations)[0]).value},$getTitle:function(){return o(o(this.titles)[0]).value},$getText:function(){return o(o(this.notes)[0]).text},$getSourceRefsQuery:function(){return s.getSourceRefsQuery(this.id)},$setCitation:function(e){return this.citations=[{value:e}],this},$setTitle:function(e){return this.titles=[{value:e}],this},$setText:function(e){return this.notes=[{text:e}],this},$save:function(t,i,o){var c=this;t&&(c.attribution=new e.Attribution(t));var u=n.chainHttpPromises(c.id?r.getUrl("source-description-template",null,{sdid:c.id}):r.getUrl("source-descriptions"),function(e){return r.post(e,{sourceDescriptions:[c]},{},o,function(e,t){return c.id||t.getResponseHeader("X-ENTITY-ID")})}),a=u.then(function(e){return n.extendHttpPromise(a,u),i?s.getSourceDescription(e,{},o).then(function(t){return n.deletePropertiesPartial(c,n.appFieldRejector),n.extend(c,t.getSourceDescription()),e}):e});return a},$delete:function(e,t){return s.deleteSourceDescription(this.id,e,t)}};var u=s.SourceRef=function(e){e&&(this.$personId=e.$personId,this.$coupleId=e.$coupleId,this.$childAndParentsId=e.$childAndParentsId,e.sourceDescription&&this.$setSourceDescription(e.sourceDescription),e.tags&&this.$setTags(e.tags))};return s.SourceRef.prototype={constructor:u,$getSourceRefUrl:function(){return n.removeAccessToken(o(o(this.links)["source-reference"]).href)},$getSourceDescriptionUrl:function(){return n.removeAccessToken(this.$sourceDescriptionUrl)},$getSourceDescription:function(){return s.getSourceDescription(this.$getSourceDescriptionUrl())},$getTags:function(){return n.map(this.tags,function(e){return e.resource})},$setSourceDescription:function(e){return e instanceof c&&(e=e.id),n.isAbsoluteUrl(e)?(delete this.$sourceDescriptionId,this.$sourceDescriptionUrl=n.removeAccessToken(e),this.description=this.$sourceDescriptionUrl):(this.$sourceDescriptionId=e,delete this.$sourceDescriptionUrl),this},$setTags:function(e){return this.tags=n.map(e,function(e){return{resource:e}}),this},$addTag:function(e){return n.isArray(this.tags)||(this.tags=[]),this.tags.push({resource:e}),this},$removeTag:function(e){return e=n.find(this.tags,{resource:e}),e&&this.tags.splice(n.indexOf(this.tags,e),1),this},$save:function(i,o){var s=this;i&&(s.attribution=new e.Attribution(i));var c,u,a={};return s.$personId?(c="person-source-references-template",u="persons"):s.$coupleId?(c="couple-relationship-source-references-template",u="relationships"):s.$childAndParentsId&&(c="child-and-parents-relationship-source-references-template",c="child-and-parents-relationship-source-references-template",u="childAndParentsRelationships",a["Content-Type"]="application/x-fs-v1+json"),n.chainHttpPromises(r.getUrl(c,null,{pid:s.$personId,crid:s.$coupleId,caprid:s.$childAndParentsId,srid:s.id}),function(e){!s.$sourceDescriptionUrl&&s.$sourceDescriptionId&&(s.$sourceDescriptionUrl=n.getUrlFromDiscoveryResource(t.discoveryResource,"source-description-template",{sdid:s.$sourceDescriptionId})),s.$sourceDescriptionUrl&&(s.description=n.removeAccessToken(s.$sourceDescriptionUrl));var i={};return i[u]=[{sources:[s]}],r.post(e,i,a,o,function(e,t){return s.id||(s.id=t.getResponseHeader("X-ENTITY-ID")),s.$getSourceRefUrl()||(s.links={"source-reference":{href:n.removeAccessToken(t.getResponseHeader("Location"))}}),s.id})})},$delete:function(e,t){return this.$personId?s.deletePersonSourceRef(this.$getSourceRefUrl()||this.$personID,this.id,e,t):this.$coupleId?s.deleteCoupleSourceRef(this.$getSourceRefUrl()||this.$coupleId,this.id,e,t):s.deleteChildAndParentsSourceRef(this.$getSourceRefUrl()||this.$childAndParentsId,this.id,e,t)}},s.getSourceDescription=function(t,i,s){return t instanceof u&&(t=t.$getSourceDescriptionUrl()),n.chainHttpPromises(r.getUrl("source-description-template",t,{sdid:t}),function(t){return r.get(t,i,{},s,n.compose(n.objectExtender({getSourceDescription:function(){return o(this.sourceDescriptions)[0]}}),n.constructorSetter(c,"sourceDescriptions"),n.constructorSetter(e.Attribution,"attribution",function(e){return e.sourceDescriptions})))})},s.getMultiSourceDescription=function(e,t,r){var i={};return n.forEach(e,function(e){var n,o;e instanceof u?(n=e.$getSourceDescriptionUrl(),o=e.$getSourceDescriptionUrl()):(n=e,o=e),i[n]=s.getSourceDescription(o,t,r)}),n.promiseAll(i)},s.getSourceRefsQuery=function(t,i,s){return n.chainHttpPromises(r.getUrl("source-references-query"),function(c){return c=n.appendQueryParameters(c,{source:t}),r.get(c,i,{Accept:"application/x-fs-v1+json"},s,n.compose(n.objectExtender({getPersonSourceRefs:function(){return n.flatMap(o(this.persons),function(e){return e.sources})}}),n.objectExtender({getCoupleSourceRefs:function(){return n.flatMap(o(this.relationships),function(e){return e.sources})}}),n.objectExtender({getChildAndParentsSourceRefs:function(){return n.flatMap(o(this.childAndParentsRelationships),function(e){return e.sources})}}),n.constructorSetter(u,"sources",function(e){return n.union(o(e).persons,o(e).relationships,o(e).childAndParentsRelationships)}),n.constructorSetter(e.Attribution,"attribution",function(e){var t=n.union(o(e).persons,o(e).relationships,o(e).childAndParentsRelationships);return n.flatMap(t,function(e){return e.sources})}),n.objectExtender(function(e,r){var i=n.find(o(e).persons,function(e){return!!n.find(o(e).sources,{id:r.id})});return{$personId:i.id,$sourceDescriptionId:t,$sourceDescriptionUrl:r.description}},function(e){return n.flatMap(o(e).persons,function(e){return e.sources})}),n.objectExtender(function(e,r){var i=n.find(o(e).relationships,function(e){return!!n.find(o(e).sources,{id:r.id})});return{$coupleId:i.id,$sourceDescriptionId:t,$sourceDescriptionUrl:r.description}},function(e){return n.flatMap(o(e).relationships,function(e){return e.sources})}),n.objectExtender(function(e,r){var i=n.find(o(e).childAndParentsRelationships,function(e){return!!n.find(o(e).sources,{id:r.id})});return{$childAndParentsId:i.id,$sourceDescriptionId:t,$sourceDescriptionUrl:r.description}},function(e){return n.flatMap(o(e).childAndParentsRelationships,function(e){return e.sources})})))})},s.getPersonSourceRefs=function(e,t,o){return n.chainHttpPromises(r.getUrl("person-sources-query-template",e,{pid:e}),function(e){return r.get(e,t,{},o,i("persons","$personId"))})},s.getCoupleSourceRefs=function(e,t,o){return n.chainHttpPromises(r.getUrl("couple-relationship-sources-query-template",e,{crid:e}),function(e){return r.get(e,t,{},o,i("relationships","$coupleId"))})},s.getChildAndParentsSourceRefs=function(e,t,o){return n.chainHttpPromises(r.getUrl("child-and-parents-relationship-sources-template",e,{caprid:e}),function(e){return r.get(e,t,{Accept:"application/x-fs-v1+json"},o,i("childAndParentsRelationships","$childAndParentsId"))})},s.deleteSourceDescription=function(e,t,i){var o=s.getSourceRefsQuery(e,{},i).then(function(c){var u=n.union(n.map(c.getPersonSourceRefs(),function(e){return s.deletePersonSourceRef(e.$getSourceRefUrl(),null,t,i)}),n.map(c.getCoupleSourceRefs(),function(e){return s.deleteCoupleSourceRef(e.$getSourceRefUrl(),null,t,i)}),n.map(c.getChildAndParentsSourceRefs(),function(e){return s.deleteChildAndParentsSourceRef(e.$getSourceRefUrl(),null,t,i)}));return n.promiseAll(u).then(function(){var s=n.chainHttpPromises(r.getUrl("source-description-template",null,{sdid:e}),function(n){return r.del(n,t?{"X-Reason":t}:{},i,function(){return e})});return n.extendHttpPromise(o,s),s})});return o},s.deletePersonSourceRef=function(e,t,i,o){return n.chainHttpPromises(r.getUrl("person-source-reference-template",e,{pid:e,srid:t}),function(t){return r.del(t,i?{"X-Reason":i}:{},o,function(){return e})})},s.deleteCoupleSourceRef=function(e,t,i,o){return n.chainHttpPromises(r.getUrl("couple-relationship-source-reference-template",e,{crid:e,srid:t}),function(t){return r.del(t,i?{"X-Reason":i}:{},o,function(){return e})})},s.deleteChildAndParentsSourceRef=function(e,t,i,o){return n.chainHttpPromises(r.getUrl("child-and-parents-relationship-source-reference-template",e,{caprid:e,srid:t}),function(t){var n={"Content-Type":"application/x-fs-v1+json"};return i&&(n["X-Reason"]=i),r.del(t,n,o,function(){return e})})},s}),e("parentsAndChildren",["attribution","changeHistory","fact","globals","helpers","notes","plumbing","sources"],function(e,t,n,r,i,o,s,c){var u=i.maybe,a={},l=a.ChildAndParents=function(e){e&&(e.father&&this.$setFather(e.father),e.mother&&this.$setMother(e.mother),e.child&&this.$setChild(e.child),e.fatherFacts&&this.$setFatherFacts(e.fatherFacts),e.motherFacts&&this.$setMotherFacts(e.motherFacts))};a.setMember=function(e,t){this[e]||(this[e]={}),t instanceof r.Person?(this[e].resource=t.$getPersonUrl(),delete this[e].resourceId):i.isAbsoluteUrl(t)?(this[e].resource=t,delete this[e].resourceId):(this[e].resourceId=t,delete this[e].resource)},a.deleteMember=function(e,t){this.$deletedMembers||(this.$deletedMembers={}),this.$deletedMembers[e]=t,delete this[e]},a.setFacts=function(e,t,n){i.isArray(this[e])&&i.forEach(this[e],function(t){a.deleteFact.call(this,e,t,n)},this),this[e]=[],i.forEach(t,function(t){a.addFact.call(this,e,t)},this)},a.addFact=function(e,t){i.isArray(this[e])||(this[e]=[]),t instanceof n.Fact||(t=new n.Fact(t)),this[e].push(t)},a.deleteFact=function(e,t,r){t instanceof n.Fact||(t=i.find(this[e],{id:t}));var o=i.indexOf(this[e],t);if(o>=0){var s=i.removeAccessToken(u(u(u(t).links).conclusion).href);s&&(this.$deletedFacts||(this.$deletedFacts={}),this.$deletedFacts[s]=r),this[e].splice(o,1)}},a.ChildAndParents.prototype={constructor:l,$getChildAndParentsUrl:function(){return i.removeAccessToken(u(u(this.links).relationship).href)},$getFatherFacts:function(){return this.fatherFacts||[]},$getMotherFacts:function(){return this.motherFacts||[]},$getFatherId:function(){return u(this.father).resourceId},$getFatherUrl:function(){return i.removeAccessToken(u(this.father).resource)},$getFather:function(){return r.getPerson(this.$getFatherUrl()||this.$getFatherId())},$getMotherId:function(){return u(this.mother).resourceId},$getMotherUrl:function(){return i.removeAccessToken(u(this.mother).resource)},$getMother:function(){return r.getPerson(this.$getMotherUrl()||this.$getMotherId())},$getChildId:function(){return u(this.child).resourceId},$getChildUrl:function(){return i.removeAccessToken(u(this.child).resource)},$getChild:function(){return r.getPerson(this.$getChildUrl()||this.$getChildId())},$getNoteRefs:function(){return o.getChildAndParentsNoteRefs(i.removeAccessToken(this.links.notes.href))},$getSourceRefs:function(){return c.getChildAndParentsSourceRefs(this.id)},$getChanges:function(){return t.getChildAndParentsChanges(i.removeAccessToken(u(this.links["change-history"]).href))},$setFather:function(e){return a.setMember.call(this,"father",e),this.$fatherChanged=!0,this},$setMother:function(e){return a.setMember.call(this,"mother",e),this.$motherChanged=!0,this},$setChild:function(e){return a.setMember.call(this,"child",e),this},$deleteFather:function(e){return a.deleteMember.call(this,"father",e),this},$deleteMother:function(e){return a.deleteMember.call(this,"mother",e),this},$setFatherFacts:function(e,t){return a.setFacts.call(this,"fatherFacts",e,t),this},$addFatherFact:function(e){return a.addFact.call(this,"fatherFacts",e),this},$deleteFatherFact:function(e,t){return a.deleteFact.call(this,"fatherFacts",e,t),this},$setMotherFacts:function(e,t){return a.setFacts.call(this,"motherFacts",e,t),this},$addMotherFact:function(e){return a.addFact.call(this,"motherFacts",e),this},$deleteMotherFact:function(e,t){return a.deleteFact.call(this,"motherFacts",e,t),this},$save:function(t,n,o){var c=new l,u=!1,p=this.id;(!this.id||this.$fatherChanged)&&(c.father=this.father,u=!0),(!this.id||this.$motherChanged)&&(c.mother=this.mother,u=!0),this.id||(c.child=this.child,u=!0),t&&(c.attribution=new e.Attribution(t)),i.forEach(["fatherFacts","motherFacts"],function(e){i.forEach(this[e],function(t){p&&t.id&&!t.$changed||(a.addFact.call(c,e,t),u=!0)})},this);var d=[];u&&d.push(i.chainHttpPromises(p?s.getUrl("child-and-parents-relationship-template",null,{caprid:p}):s.getUrl("relationships"),function(e){return i.forEach(["father","mother","child"],function(e){c[e]&&!c[e].resource&&c[e].resourceId&&(c[e].resource=i.getUrlFromDiscoveryResource(r.discoveryResource,"person-template",{pid:c[e].resourceId}))}),s.post(e,{childAndParentsRelationships:[c]},{"Content-Type":"application/x-fs-v1+json"},o,i.getResponseEntityId)})),i.forEach(["father","mother"],function(e){if(this.id&&this.$deletedMembers&&this.$deletedMembers.hasOwnProperty(e)&&!this[e]){var n=this.$deletedMembers[e]||t;d.push(i.chainHttpPromises(s.getUrl("child-and-parents-relationship-parent-template",null,{caprid:p,role:e}),function(e){var t={"Content-Type":"application/x-fs-v1+json"};return n&&(t["X-Reason"]=n),s.del(e,t,o)}))}},this),p&&this.$deletedFacts&&i.forEach(this.$deletedFacts,function(e,n){e=e||t;var r={"Content-Type":"application/x-fs-v1+json"};e&&(r["X-Reason"]=e),d.push(s.del(n,r,o))});var f=this,h=i.promiseAll(d).then(function(e){var t=p?p:e[0];return i.extendHttpPromise(h,d[0]),n?a.getChildAndParents(t,{},o).then(function(e){return i.deletePropertiesPartial(f,i.appFieldRejector),i.extend(f,e.getRelationship()),t}):t});return h},$delete:function(e,t){return a.deleteChildAndParents(this.$getChildAndParentsUrl()||this.id,e,t)}},a.getChildAndParents=function(t,o,c){return i.chainHttpPromises(s.getUrl("child-and-parents-relationship-template",t,{caprid:t}),function(t){return s.get(t,o,{Accept:"application/x-fs-v1+json"},c,i.compose(i.constructorSetter(l,"childAndParentsRelationships"),i.objectExtender(p),i.constructorSetter(n.Fact,"motherFacts",function(e){return u(e).childAndParentsRelationships }),i.constructorSetter(n.Fact,"fatherFacts",function(e){return u(e).childAndParentsRelationships}),i.constructorSetter(e.Attribution,"attribution",function(e){return i.flatMap(e.childAndParentsRelationships,function(e){return i.union(e.motherFacts,e.fatherFacts)})}),r.personMapper()))})};var p={getRelationship:function(){return u(this.childAndParentsRelationships)[0]},getPerson:function(e){return i.find(this.persons,{id:e})}};return a.deleteChildAndParents=function(e,t,n){return i.chainHttpPromises(s.getUrl("child-and-parents-relationship-template",e,{caprid:e}),function(r){var i={"Content-Type":"application/x-fs-v1+json"};return t&&(i["X-Reason"]=t),s.del(r,i,n,function(){return e})})},a}),e("pedigree",["globals","helpers","plumbing"],function(e,t,n){function r(e){return{getPersons:function(){return this.persons},exists:function(n){return!!o(t.find(this.persons,i(e,n))).id},getPerson:function(n){return t.find(this.persons,i(e,n))}}}function i(e,t){return function(n){return n.display[e]==t}}var o=t.maybe,s={};return s.getAncestry=function(i,s,c){return t.chainHttpPromises(n.getUrl("ancestry-query"),function(u){return n.get(u,t.extend({person:i},s),{},c,t.compose(t.objectExtender(r("ascendancyNumber")),e.personMapper(),t.objectExtender({$getAscendancyNumber:function(){return this.display.ascendancyNumber}},function(e){return o(e).persons})))})},s.getDescendancy=function(i,s,c){return t.chainHttpPromises(n.getUrl("descendancy-query"),function(u){return n.get(u,t.extend({person:i},s),{},c,t.compose(t.objectExtender(r("descendancyNumber")),e.personMapper(),t.objectExtender({$getDescendancyNumber:function(){return this.display.descendancyNumber}},function(e){return o(e).persons})))})},s}),e("spouses",["attribution","changeHistory","fact","globals","helpers","parentsAndChildren","plumbing","notes","sources"],function(e,t,n,r,i,o,s,c,u){var a=i.maybe,l={},p=l.Couple=function(e){e&&(e.husband&&this.$setHusband(e.husband),e.wife&&this.$setWife(e.wife),e.facts&&this.$setFacts(e.facts))};l.Couple.prototype={constructor:p,$getCoupleUrl:function(){return i.removeAccessToken(a(a(this.links).relationship).href)},$getFacts:function(){return this.facts||[]},$getMarriageFact:function(){return i.find(this.facts,{type:"http://gedcomx.org/Marriage"})},$getHusbandId:function(){return a(this.person1).resourceId},$getHusbandUrl:function(){return i.removeAccessToken(a(this.person1).resource)},$getHusband:function(){return r.getPerson(this.$getHusbandUrl()||this.$getHusbandId())},$getWifeId:function(){return a(this.person2).resourceId},$getWifeUrl:function(){return i.removeAccessToken(a(this.person2).resource)},$getWife:function(){return r.getPerson(this.$getWifeUrl()||this.$getWifeId())},$getSpouseId:function(e){return a(this.person1).resourceId===e?a(this.person2).resourceId:a(this.person1).resourceId},$getSpouseUrl:function(e){return i.removeAccessToken(a(this.person1).resourceId===e?a(this.person2).resource:a(this.person1).resource)},$getSpouse:function(e){return r.getPerson(this.$getSpouseUrl(e)||this.$getSpouseId(e))},$getNoteRefs:function(){return c.getCoupleNoteRefs(i.removeAccessToken(this.links.notes.href))},$getSourceRefs:function(){return u.getCoupleSourceRefs(this.id)},$getChanges:function(){return t.getCoupleChanges(i.removeAccessToken(a(this.links["change-history"]).href))},$setHusband:function(e){return o.setMember.call(this,"person1",e),this.$husbandChanged=!0,this},$setWife:function(e){return o.setMember.call(this,"person2",e),this.$wifeChanged=!0,this},$setFacts:function(e,t){return o.setFacts.call(this,"facts",e,t),this},$addFact:function(e){return o.addFact.call(this,"facts",e),this},$deleteFact:function(e,t){return o.deleteFact.call(this,"facts",e,t),this},$save:function(t,n,c){var u=new p,a=!1,d=this.id;(!this.id||this.$husbandChanged||this.$wifeChanged)&&(u.person1=this.person1,u.person2=this.person2,a=!0),t&&(u.attribution=new e.Attribution(t)),i.forEach(this.facts,function(e){d&&e.id&&!e.$changed||(o.addFact.call(u,"facts",e),a=!0)});var f=[];a&&(d||(u.type="http://gedcomx.org/Couple"),f.push(i.chainHttpPromises(d?s.getUrl("couple-relationship-template",null,{crid:d}):s.getUrl("relationships"),function(e){return i.forEach(["person1","person2"],function(e){u[e]&&!u[e].resource&&u[e].resourceId&&(u[e].resource=i.getUrlFromDiscoveryResource(r.discoveryResource,"person-template",{pid:u[e].resourceId}))}),s.post(e,{relationships:[u]},{},c,i.getResponseEntityId)}))),d&&this.$deletedFacts&&i.forEach(this.$deletedFacts,function(e,n){e=e||t,f.push(s.del(n,e?{"X-Reason":e}:{},c))});var h=this,g=i.promiseAll(f).then(function(e){var t=d?d:e[0];return i.extendHttpPromise(g,f[0]),n?l.getCouple(t,{},c).then(function(e){return i.deletePropertiesPartial(h,i.appFieldRejector),i.extend(h,e.getRelationship()),t}):t});return g},$delete:function(e,t){return l.deleteCouple(this.$getCoupleUrl()||this.id,e,t)}},l.getCouple=function(t,o,c){return i.chainHttpPromises(s.getUrl("couple-relationship-template",t,{crid:t}),function(t){return s.get(t,o,{},c,i.compose(i.constructorSetter(p,"relationships"),i.objectExtender(d),i.constructorSetter(n.Fact,"facts",function(e){return a(e).relationships}),i.constructorSetter(e.Attribution,"attribution",function(e){return i.flatMap(e.relationships,function(e){return e.facts})}),r.personMapper()))})};var d={getRelationship:function(){return a(this.relationships)[0]},getPerson:function(e){return i.find(this.persons,{id:e})}};return l.deleteCouple=function(e,t,n){return i.chainHttpPromises(s.getUrl("couple-relationship-template",e,{crid:e}),function(r){return s.del(r,t?{"X-Reason":t}:{},n,function(){return e})})},l}),e("person",["attribution","changeHistory","discussions","fact","globals","helpers","memories","name","notes","parentsAndChildren","pedigree","plumbing","sources","spouses","user"],function(e,t,n,r,i,o,s,c,u,a,l,p,d,f,h){function g(e){return e?" "+e:""}var m=o.maybe,$={},P=i.Person=$.Person=function(e){e&&(e.gender&&this.$setGender(e.gender),e.names&&this.$setNames(e.names),e.facts&&this.$setFacts(e.facts))};$.Person.prototype={constructor:P,$getFacts:function(e){return(e?o.filter(this.facts,{type:e}):this.facts)||[]},$getFact:function(e){return o.find(this.facts,{type:e})},$getBirth:function(){return this.$getFact("http://gedcomx.org/Birth")},$getBirthDate:function(){var e=this.$getBirth();return e?e.$getDate():""},$getBirthPlace:function(){var e=this.$getBirth();return e?e.$getPlace():""},$getChristening:function(){return this.$getFact("http://gedcomx.org/Christening")},$getChristeningDate:function(){var e=this.$getChristening();return e?e.$getDate():""},$getChristeningPlace:function(){var e=this.$getChristening();return e?e.$getPlace():""},$getDeath:function(){return this.$getFact("http://gedcomx.org/Death")},$getDeathDate:function(){var e=this.$getDeath();return e?e.$getDate():""},$getDeathPlace:function(){var e=this.$getDeath();return e?e.$getPlace():""},$getBurial:function(){return this.$getFact("http://gedcomx.org/Burial")},$getBurialDate:function(){var e=this.$getBurial();return e?e.$getDate():""},$getBurialPlace:function(){var e=this.$getBurial();return e?e.$getPlace():""},$getDisplayBirthDate:function(){return m(this.display).birthDate},$getDisplayBirthPlace:function(){return m(this.display).birthPlace},$getDisplayDeathDate:function(){return m(this.display).deathDate},$getDisplayDeathPlace:function(){return m(this.display).deathPlace},$getDisplayGender:function(){return m(this.display).gender},$getDisplayLifeSpan:function(){return m(this.display).lifespan},$getDisplayName:function(){return m(this.display).name},$getNames:function(e){return(e?o.filter(this.names,{type:e}):this.names)||[]},$getPreferredName:function(){return o.findOrFirst(this.names,{preferred:!0})},$getGivenName:function(){var e=this.$getPreferredName();return e&&(e=e.$getGivenName()),e},$getSurname:function(){var e=this.$getPreferredName();return e&&(e=e.$getSurname()),e},$getPersistentIdentifier:function(){return m(m(this.identifiers)["http://gedcomx.org/Persistent"])[0]},$getPersonUrl:function(){return o.removeAccessToken(m(m(this.links).person).href)},$getChanges:function(e){return t.getPersonChanges(o.removeAccessToken(this.links["change-history"].href),e)},$getDiscussionRefs:function(){return n.getPersonDiscussionRefs(o.removeAccessToken(this.links["discussion-references"].href))},$getMemoryPersonaRefs:function(){return s.getMemoryPersonaRefs(o.removeAccessToken(this.links["evidence-references"].href))},$getNoteRefs:function(){return u.getPersonNoteRefs(o.removeAccessToken(this.links.notes.href))},$getSourceRefs:function(){return d.getPersonSourceRefs(this.id)},$getSpouses:function(){return $.getSpouses(this.id)},$getParents:function(){return $.getParents(this.id)},$getChildren:function(){return $.getChildren(this.id)},$getAncestry:function(e){return l.getAncestry(this.id,e)},$getDescendancy:function(e){return l.getDescendancy(this.id,e)},$getPersonPortraitUrl:function(e){return s.getPersonPortraitUrl(this.id,e)},$setNames:function(e,t){return o.isArray(this.names)&&o.forEach(this.names,function(e){this.$deleteName(e,t)},this),this.names=[],o.forEach(e,function(e){this.$addName(e)},this),this},$addName:function(e){return o.isArray(this.names)||(this.names=[]),e instanceof c.Name||(e=new c.Name(e)),this.names.push(e),this},$deleteName:function(e,t){e instanceof c.Name||(e=o.find(this.names,{id:e}));var n=o.indexOf(this.names,e);return n>=0&&(this.$deletedConclusions||(this.$deletedConclusions={}),this.$deletedConclusions[e.id]=t,this.names.splice(n,1)),this},$setFacts:function(e,t){return o.isArray(this.facts)&&o.forEach(this.facts,function(e){this.$deleteFact(e,t)},this),this.facts=[],o.forEach(e,function(e){this.$addFact(e)},this),this},$addFact:function(e){return o.isArray(this.facts)||(this.facts=[]),e instanceof r.Fact||(e=new r.Fact(e)),this.facts.push(e),this},$deleteFact:function(e,t){e instanceof r.Fact||(e=o.find(this.facts,{id:e}));var n=o.indexOf(this.facts,e);return n>=0&&(this.$deletedConclusions||(this.$deletedConclusions={}),this.$deletedConclusions[e.id]=t,this.facts.splice(n,1)),this},$setGender:function(t,n){return this.gender||(this.gender={}),this.gender.$changed=!0,this.gender.type=t,n&&(this.gender.attribution=new e.Attribution(n)),this},$save:function(t,n,r){var i=new P,s=!1;this.id&&(i.id=this.id),this.id||(this.gender||this.$setGender("http://gedcomx.org/Unknown"),o.isArray(this.names)&&0!==this.names.length||this.$addName({fullText:"Unknown",givenName:"Unknown"}),o.find(this.names,{preferred:!0})||this.names[0].$setPreferred(!0),1!==this.names.length||this.names[0].type||this.names[0].$setType("http://gedcomx.org/BirthName")),t&&(i.attribution=new e.Attribution(t)),!this.gender||this.gender.id&&!this.gender.$changed||(i.gender=this.gender,s=!0),o.forEach(this.names,function(e){(!e.id||e.$changed)&&(e.$getFullText()||e.$setFullText((g(e.$getPrefix())+g(e.$getGivenName())+g(e.$getSurname())+g(e.$getSuffix())).trim()),i.$addName(e),s=!0)}),o.forEach(this.facts,function(e){(!e.id||e.$changed)&&(i.$addFact(e),s=!0)});var c=[];s&&c.push(o.chainHttpPromises(i.id?p.getUrl("person-template",null,{pid:i.id}):p.getUrl("persons"),function(e){return p.post(e,{persons:[i]},{},r,o.getResponseEntityId)})),this.id&&this.$deletedConclusions&&o.forEach(this.$deletedConclusions,function(e,n){e=e||t,c.push(o.chainHttpPromises(p.getUrl("person-conclusion-template",null,{pid:i.id,cid:n}),function(t){return p.del(t,e?{"X-Reason":e}:{},r)}))});var u=this,a=o.promiseAll(c).then(function(e){var t=i.id?i.id:e[0];return o.extendHttpPromise(a,c[0]),n?$.getPerson(t,{},r).then(function(e){return o.deletePropertiesPartial(u,o.appFieldRejector),o.extend(u,e.getPerson()),t}):t});return a},$delete:function(e,t){return $.deletePerson(this.$getPersonUrl()||this.id,e,t)}},i.getPerson=$.getPerson=function(e,t,n){return o.chainHttpPromises(p.getUrl("person-template",e,{pid:e}),function(e){return p.get(e,t,{},n,o.compose(o.objectExtender({getPerson:function(){return this.persons[0]}}),$.personMapper()))})},i.personMapper=$.personMapper=function(t){var n=function(e){return o.flatMap(t?t(e):[e],function(e){return e.persons})};return o.compose(o.constructorSetter(P,"persons",t),o.constructorSetter(c.Name,"names",n),o.constructorSetter(r.Fact,"facts",n),o.constructorSetter(e.Attribution,"attribution",function(e){return o.flatMap(n(e),function(e){return o.union([e],e.names,e.facts,e.gender?[e.gender]:[])})}))},$.getMultiPerson=function(e,t,n){var r={};return o.forEach(e,function(e){r[e]=$.getPerson(e,t,n)}),o.promiseAll(r)},$.getPersonWithRelationships=function(t,n,i){return o.chainHttpPromises(p.getUrl("person-with-relationships-query"),function(s){return p.get(s,o.extend({person:t},n),{},i,o.compose(o.objectExtender({getPrimaryId:function(){return t}}),o.constructorSetter(r.Fact,"fatherFacts",function(e){return e.childAndParentsRelationships}),o.constructorSetter(r.Fact,"motherFacts",function(e){return e.childAndParentsRelationships}),o.constructorSetter(e.Attribution,"attribution",function(e){return o.flatMap(e.childAndParentsRelationships,function(e){return o.union(e.fatherFacts,e.motherFacts)})}),o.constructorSetter(r.Fact,"facts",function(e){return e.relationships}),o.constructorSetter(e.Attribution,"attribution",function(e){return o.flatMap(e.relationships,function(e){return e.facts})}),o.constructorSetter(a.ChildAndParents,"childAndParentsRelationships"),o.constructorSetter(f.Couple,"relationships"),o.objectExtender(y),$.personMapper()))})};var y={getPerson:function(e){return o.find(this.persons,{id:e})},getPrimaryPerson:function(){return this.getPerson(this.getPrimaryId())},getParentRelationships:function(){var e=this.getPrimaryId();return o.filter(this.childAndParentsRelationships,function(t){return m(t.child).resourceId===e})},getSpouseRelationships:function(){return o.filter(this.relationships,function(e){return"http://gedcomx.org/Couple"===e.type})},getSpouseRelationship:function(e){var t=this.getPrimaryId();return o.find(this.relationships,function(n){return"http://gedcomx.org/Couple"===n.type&&(t===n.$getHusbandId()?n.$getWifeId():n.$getHusbandId())===e})},getChildRelationships:function(){var e=this.getPrimaryId();return o.filter(this.childAndParentsRelationships,function(t){return m(t.father).resourceId===e||m(t.mother).resourceId===e})},getChildRelationshipsOf:function(e){var t=this.getPrimaryId();return o.filter(this.childAndParentsRelationships,function(n){return!(m(n.father).resourceId!==t&&m(n.mother).resourceId!==t||m(n.father).resourceId!=e&&m(n.mother).resourceId!=e)})},getFatherIds:function(){return o.uniq(o.map(o.filter(this.getParentRelationships(),function(e){return!!e.$getFatherId()}),function(e){return e.$getFatherId()},this))},getFathers:function(){return o.map(this.getFatherIds(),this.getPerson,this)},getMotherIds:function(){return o.uniq(o.map(o.filter(this.getParentRelationships(),function(e){return!!e.$getMotherId()}),function(e){return e.$getMotherId()},this))},getMothers:function(){return o.map(this.getMotherIds(),this.getPerson,this)},getSpouseIds:function(){return o.uniq(o.map(o.filter(this.getSpouseRelationships(),function(e){return e.$getHusbandId()&&e.$getWifeId()}),function(e){return this.getPrimaryId()===e.$getHusbandId()?e.$getWifeId():e.$getHusbandId()},this))},getSpouses:function(){return o.map(this.getSpouseIds(),this.getPerson,this)},getChildIds:function(){return o.uniq(o.map(this.getChildRelationships(),function(e){return e.$getChildId()},this))},getChildren:function(){return o.map(this.getChildIds(),this.getPerson,this)},getChildIdsOf:function(e){return o.uniq(o.map(this.getChildRelationshipsOf(e),function(e){return e.$getChildId()},this))},getChildrenOf:function(e){return o.map(this.getChildIdsOf(e),this.getPerson,this)}};$.getPersonChangeSummary=function(e,n,r){return o.chainHttpPromises(p.getUrl("person-change-summary-template",e,{pid:e}),function(e){return p.get(e,n,{Accept:"application/x-gedcomx-atom+json"},r,o.compose(o.objectExtender({getChanges:function(){return this.entries||[]}}),o.constructorSetter(t.Change,"entries")))})};var v=o.compose(o.constructorSetter(f.Couple,"relationships"),o.constructorSetter(a.ChildAndParents,"childAndParentsRelationships"),o.objectExtender({getCoupleRelationships:function(){return o.filter(m(this).relationships,{type:"http://gedcomx.org/Couple"})||[]},getChildAndParentsRelationships:function(){return m(this).childAndParentsRelationships||[]},getPerson:function(e){return o.find(this.persons,{id:e})}}),o.constructorSetter(r.Fact,"facts",function(e){return e.relationships}),o.constructorSetter(r.Fact,"fatherFacts",function(e){return e.childAndParentsRelationships}),o.constructorSetter(r.Fact,"motherFacts",function(e){return e.childAndParentsRelationships}),o.constructorSetter(e.Attribution,"attribution",function(e){return o.union(o.flatMap(e.relationships,function(e){return e.facts}),o.flatMap(e.childAndParentsRelationships,function(e){return o.union(e.fatherFacts,e.motherFacts)}))}),$.personMapper());return $.getSpouses=function(e,t,n){return o.chainHttpPromises(p.getUrl("spouses-template",e,{pid:e}),function(e){return p.get(e,t,{},n,v)})},$.getParents=function(e,t,n){return o.chainHttpPromises(p.getUrl("parents-template",e,{pid:e}),function(e){return p.get(e,t,{},n,v)})},$.getChildren=function(e,t,n){return o.chainHttpPromises(p.getUrl("children-template",e,{pid:e}),function(e){return p.get(e,t,{},n,v)})},$.deletePerson=function(e,t,n){return o.chainHttpPromises(p.getUrl("person-template",e,{pid:e}),function(r){return p.del(r,t?{"X-Reason":t}:{},n,function(){return e})})},$.getPreferredSpouse=function(e,t,n){return o.chainHttpPromises(h.getCurrentUser(),function(t){var n=t.getUser().treeUserId;return p.getUrl("preferred-spouse-relationship-template",null,{uid:n,pid:e})},function(e){var r=p.get(e+".json",t,{},n);return o.handleRedirect(r,function(e){return 200===e.getStatusCode()?o.getLastUrlSegment(e.getResponseHeader("Content-Location")):null})})},$.setPreferredSpouse=function(e,t,n){var r;return o.chainHttpPromises(p.getUrl("couple-relationship-template",t,{crid:t}),function(e){return r=e,h.getCurrentUser()},function(t){var n=t.getUser().treeUserId;return p.getUrl("preferred-spouse-relationship-template",null,{uid:n,pid:e})},function(t){return p.put(t,null,{Location:r},n,function(){return e})})},$.deletePreferredSpouse=function(e,t){return o.chainHttpPromises(h.getCurrentUser(),function(t){var n=t.getUser().treeUserId;return p.getUrl("preferred-spouse-relationship-template",null,{uid:n,pid:e})},function(n){return p.del(n,{},t,function(){return e})})},$.getPreferredParents=function(e,t,n){return o.chainHttpPromises(h.getCurrentUser(),function(t){var n=t.getUser().treeUserId;return p.getUrl("preferred-parent-relationship-template",null,{uid:n,pid:e})},function(e){var r=p.get(e+".json",t,{Accept:"application/x-fs-v1+json"},n);return o.handleRedirect(r,function(e){return 200===e.getStatusCode()?o.getLastUrlSegment(e.getResponseHeader("Content-Location")):null})})},$.setPreferredParents=function(e,t,n){var r;return o.chainHttpPromises(p.getUrl("child-and-parents-relationship-template",t,{caprid:t}),function(e){return r=e,h.getCurrentUser()},function(t){var n=t.getUser().treeUserId;return p.getUrl("preferred-parent-relationship-template",null,{uid:n,pid:e})},function(t){return p.put(t,null,{Location:r},n,function(){return e})})},$.deletePreferredParents=function(e,t){return o.chainHttpPromises(h.getCurrentUser(),function(t){var n=t.getUser().treeUserId;return p.getUrl("preferred-parent-relationship-template",null,{uid:n,pid:e})},function(n){return p.del(n,{},t,function(){return e})})},$}),e("searchAndMatch",["globals","helpers","plumbing"],function(e,t,n){function r(e){return e=e.replace(/[:"]/g,"").trim(),e.indexOf(" ")>=0?'"'+e+'"':e}function i(e){return t.map(t.filter(t.keys(e),function(e){return!a[e]}),function(t){return t+":"+r(e[t])}).join(" ")}function o(){return t.compose(t.objectExtender(l),t.constructorSetter(u,"entries"),e.personMapper(function(e){return t.map(s(e).entries,function(e){return s(e.content).gedcomx})}))}var s=t.maybe,c={},u=c.SearchResult=function(){};c.SearchResult.prototype={constructor:u,$getPerson:function(e){return t.find(s(s(this.content).gedcomx).persons,{id:e})},$getPrimaryPerson:function(){return this.$getPerson(this.id)},$getFullPrimaryPerson:function(){return e.getPerson(this.id)},$getFatherIds:function(){var e=this.id,n=this;return t.uniq(t.map(t.filter(s(s(this.content).gedcomx).relationships,function(t){return"http://gedcomx.org/ParentChild"===t.type&&t.person2.resourceId===e&&t.person1&&"http://gedcomx.org/Male"===s(n.$getPerson(t.person1.resourceId).gender).type}),function(e){return e.person1.resourceId}))},$getFathers:function(){return t.map(this.$getFatherIds(),this.$getPerson,this)},$getMotherIds:function(){var e=this.id,n=this;return t.uniq(t.map(t.filter(s(s(this.content).gedcomx).relationships,function(t){return"http://gedcomx.org/ParentChild"===t.type&&t.person2.resourceId===e&&t.person1&&"http://gedcomx.org/Male"!==s(n.$getPerson(t.person1.resourceId).gender).type}),function(e){return e.person1.resourceId}))},$getMothers:function(){return t.map(this.$getMotherIds(),this.$getPerson,this)},$getSpouseIds:function(){var e=this.id;return t.uniq(t.map(t.filter(s(s(this.content).gedcomx).relationships,function(t){return"http://gedcomx.org/Couple"===t.type&&(t.person1.resourceId===e||t.person2.resourceId===e)}),function(t){return t.person1.resourceId===e?t.person2.resourceId:t.person1.resourceId}))},$getSpouses:function(){return t.map(this.$getSpouseIds(),this.$getPerson,this)},$getChildIds:function(){var e=this.id;return t.uniq(t.map(t.filter(s(s(this.content).gedcomx).relationships,function(t){return"http://gedcomx.org/ParentChild"===t.type&&t.person1.resourceId===e&&t.person2}),function(e){return e.person2.resourceId}))},$getChildren:function(){return t.map(this.$getChildIds(),this.$getPerson,this)}};var a={start:!0,count:!0,context:!0},l={getSearchResults:function(){return this.entries||[]},getResultsCount:function(){return this.results},getIndex:function(){return this.index}};return c.getPersonSearch=function(e,r){return t.chainHttpPromises(n.getUrl("person-search"),function(s){return n.get(s,t.removeEmptyProperties({q:i(e),start:e.start,count:e.count,context:e.context}),{Accept:"application/x-gedcomx-atom+json"},r,t.compose(o(),function(e,t){return e.getContext=function(){return t.getResponseHeader("X-FS-Page-Context")},e}))})},c.getPersonMatches=function(e,r,i){return t.chainHttpPromises(n.getUrl("person-matches-template",e,{pid:e}),function(e){return n.get(e,r,{Accept:"application/x-gedcomx-atom+json"},i,o())})},c.getPersonMatchesQuery=function(e,r){return t.chainHttpPromises(n.getUrl("person-matches-query"),function(s){return n.get(s,t.removeEmptyProperties({q:i(e),start:e.start,count:e.count}),{Accept:"application/x-gedcomx-atom+json"},r,o())})},c}),e("sourceBox",["attribution","helpers","plumbing","sources","user"],function(e,t,n,r,i){var o=t.maybe,s={},c=s.Collection=function(e){e&&(this.title=e.title)};return s.Collection.prototype={constructor:c,$getSourceDescriptions:function(e){return s.getCollectionSourceDescriptions(t.removeAccessToken(this.links["source-descriptions"].href),e)},$save:function(e,r){var i=this,o=t.chainHttpPromises(i.id?n.getUrl("user-collection-template",null,{udcid:i.id}):n.getUrl("user-collections"),function(e){return n.post(e,{collections:[i]},{},r,function(e,t){return i.id||t.getResponseHeader("X-ENTITY-ID")})}),c=o.then(function(n){return t.extendHttpPromise(c,o),e?s.getCollection(n,{},r).then(function(e){return t.deletePropertiesPartial(i,t.appFieldRejector),t.extend(i,e.getCollection()),n}):n});return c},$delete:function(e){return s.deleteCollection(this.id,e)}},s.getCollectionsForUser=function(r,i,o){return t.chainHttpPromises(n.getUrl("user-collections-for-user-template",r,{uid:r}),function(r){return n.get(r,{},{Accept:"application/x-fs-v1+json"},o,t.compose(t.objectExtender({getCollections:function(){return this.collections||[]}}),t.constructorSetter(c,"collections"),t.constructorSetter(e.Attribution,"attribution",function(e){return e.collections})))})},s.getCollection=function(r,i,s){return t.chainHttpPromises(n.getUrl("user-collection-template",r,{udcid:r}),function(r){return n.get(r,i,{Accept:"application/x-fs-v1+json"},s,t.compose(t.objectExtender({getCollection:function(){return o(this.collections)[0]}}),t.constructorSetter(c,"collections"),t.constructorSetter(e.Attribution,"attribution",function(e){return e.collections})))})},s.getCollectionSourceDescriptions=function(i,o,s){return t.chainHttpPromises(n.getUrl("user-collection-source-descriptions-template",i,{udcid:i}),function(i){return n.get(i,o,{Accept:"application/x-fs-v1+json"},s,t.compose(t.objectExtender({getSourceDescriptions:function(){return this.sourceDescriptions||[]}}),t.constructorSetter(r.SourceDescription,"sourceDescriptions"),t.constructorSetter(e.Attribution,"attribution",function(e){return e.sourceDescriptions})))})},s.getCollectionSourceDescriptionsForUser=function(i,o,s){return t.chainHttpPromises(n.getUrl("user-collections-source-descriptions-for-user-template",i,{uid:i}),function(i){return n.get(i,o,{Accept:"application/x-fs-v1+json"},s,t.compose(t.objectExtender({getSourceDescriptions:function(){return this.sourceDescriptions||[]}}),t.constructorSetter(r.SourceDescription,"sourceDescriptions"),t.constructorSetter(e.Attribution,"attribution",function(e){return e.sourceDescriptions})))})},s.moveSourceDescriptionsToCollection=function(e,i,o){return t.chainHttpPromises(n.getUrl("user-collection-source-descriptions-template",e,{udcid:e}),function(s){var c=t.map(i,function(e){return{id:e instanceof r.SourceDescription?e.id:e}});return n.post(s,{sourceDescriptions:c},{},o,function(){return e})})},s.removeSourceDescriptionsFromCollections=function(e,o){return t.chainHttpPromises(i.getCurrentUser(),function(e){var t=e.getUser().treeUserId;return n.getUrl("user-collections-source-descriptions-for-user-template",null,{uid:t})},function(i){var s=t.map(e,function(e){return e instanceof r.SourceDescription?e.id:e});return n.del(t.appendQueryParameters(i,{id:s}),{},o,function(){return e})})},s.deleteCollection=function(e,r){return t.chainHttpPromises(n.getUrl("user-collection-template",e,{udcid:e}),function(t){return n.del(t,{},r,function(){return e})})},s}),e("utilities",["globals","helpers"],function(e,t){var n={};return n.getRedirectUrl=function(e){return t.appendAccessToken(t.appendQueryParameters(t.getAPIServerUrl("/platform/redirect"),e))},n}),e("FamilySearch",["init","authentication","authorities","changeHistory","discussions","fact","helpers","memories","name","notes","parentsAndChildren","pedigree","person","plumbing","searchAndMatch","sourceBox","sources","spouses","user","utilities"],function(e,t,n,r,i,o,s,c,u,a,l,p,d,f,h,g,m,$,P,y){var v=function(e){this.params=e,this.getAccessToken=s.partial(t.getAccessToken,this.params),this.getCurrentUser=s.partial(P.getCurrentUser,this.params),this.Fact=function(e){return new o.Fact(this.params,e)},this.createFact=function(e){return new o.Fact(this.params,e)}};return{Foo:v,init:e.init,getAuthCode:t.getAuthCode,getAccessToken:t.getAccessToken,getAccessTokenForMobile:t.getAccessTokenForMobile,hasAccessToken:t.hasAccessToken,invalidateAccessToken:t.invalidateAccessToken,Date:n.Date,Place:n.Place,getDate:n.getDate,getPlaceSearch:n.getPlaceSearch,Change:r.Change,getPersonChanges:r.getPersonChanges,getChildAndParentsChanges:r.getChildAndParentsChanges,getCoupleChanges:r.getCoupleChanges,Discussion:i.Discussion,DiscussionRef:i.DiscussionRef,Comment:i.Comment,getPersonDiscussionRefs:i.getPersonDiscussionRefs,getDiscussion:i.getDiscussion,getMultiDiscussion:i.getMultiDiscussion,getDiscussionComments:i.getDiscussionComments,deleteDiscussion:i.deleteDiscussion,deleteDiscussionRef:i.deleteDiscussionRef,deleteDiscussionComment:i.deleteDiscussionComment,deleteMemoryComment:i.deleteMemoryComment,Fact:o.Fact,Memory:c.Memory,MemoryPersona:c.MemoryPersona,MemoryPersonaRef:c.MemoryPersonaRef,MemoryArtifactRef:c.MemoryArtifactRef,getMemoryPersonaRefs:c.getMemoryPersonaRefs,getMemory:c.getMemory,getMemoryComments:c.getMemoryComments,getMemoryPersonas:c.getMemoryPersonas,getMemoryPersona:c.getMemoryPersona,getPersonPortraitUrl:c.getPersonPortraitUrl,getPersonMemoriesQuery:c.getPersonMemoriesQuery,getUserMemoriesQuery:c.getUserMemoriesQuery,deleteMemory:c.deleteMemory,deleteMemoryPersona:c.deleteMemoryPersona,deleteMemoryPersonaRef:c.deleteMemoryPersonaRef,Name:u.Name,Note:a.Note,NoteRef:a.NoteRef,getPersonNoteRefs:a.getPersonNoteRefs,getPersonNote:a.getPersonNote,getMultiPersonNote:a.getMultiPersonNote,getCoupleNoteRefs:a.getCoupleNoteRefs,getCoupleNote:a.getCoupleNote,getMultiCoupleNote:a.getMultiCoupleNote,getChildAndParentsNoteRefs:a.getChildAndParentsNoteRefs,getChildAndParentsNote:a.getChildAndParentsNote,getMultiChildAndParentsNote:a.getMultiChildAndParentsNote,deletePersonNote:a.deletePersonNote,deleteCoupleNote:a.deleteCoupleNote,deleteChildAndParentsNote:a.deleteChildAndParentsNote,ChildAndParents:l.ChildAndParents,deleteChildAndParents:l.deleteChildAndParents,getChildAndParents:l.getChildAndParents,getAncestry:p.getAncestry,getDescendancy:p.getDescendancy,Person:d.Person,deletePerson:d.deletePerson,getPerson:d.getPerson,getMultiPerson:d.getMultiPerson,getPersonWithRelationships:d.getPersonWithRelationships,getPersonChangeSummary:d.getPersonChangeSummary,getSpouses:d.getSpouses,getParents:d.getParents,getChildren:d.getChildren,getPreferredSpouse:d.getPreferredSpouse,setPreferredSpouse:d.setPreferredSpouse,deletePreferredSpouse:d.deletePreferredSpouse,getPreferredParents:d.getPreferredParents,setPreferredParents:d.setPreferredParents,deletePreferredParents:d.deletePreferredParents,get:f.get,post:f.post,put:f.put,del:f.del,http:f.http,getTotalProcessingTime:f.getTotalProcessingTime,setTotalProcessingTime:f.setTotalProcessingTime,SearchResult:h.SearchResult,getPersonSearch:h.getPersonSearch,getPersonMatches:h.getPersonMatches,getPersonMatchesQuery:h.getPersonMatchesQuery,Collection:g.Collection,getCollectionsForUser:g.getCollectionsForUser,getCollection:g.getCollection,getCollectionSourceDescriptions:g.getCollectionSourceDescriptions,getCollectionSourceDescriptionsForUser:g.getCollectionSourceDescriptionsForUser,moveSourceDescriptionsToCollection:g.moveSourceDescriptionsToCollection,removeSourceDescriptionsFromCollections:g.removeSourceDescriptionsFromCollections,deleteCollection:g.deleteCollection,SourceDescription:m.SourceDescription,SourceRef:m.SourceRef,getPersonSourceRefs:m.getPersonSourceRefs,getSourceDescription:m.getSourceDescription,getMultiSourceDescription:m.getMultiSourceDescription,getCoupleSourceRefs:m.getCoupleSourceRefs,getChildAndParentsSourceRefs:m.getChildAndParentsSourceRefs,getSourceRefsQuery:m.getSourceRefsQuery,deleteSourceDescription:m.deleteSourceDescription,deletePersonSourceRef:m.deletePersonSourceRef,deleteCoupleSourceRef:m.deleteCoupleSourceRef,deleteChildAndParentsSourceRef:m.deleteChildAndParentsSourceRef,Couple:$.Couple,deleteCouple:$.deleteCouple,getCouple:$.getCouple,Agent:P.Agent,User:P.User,getCurrentUser:P.getCurrentUser,getAgent:P.getAgent,getMultiAgent:P.getMultiAgent,getRedirectUrl:y.getRedirectUrl}}),t("FamilySearch")}); \ No newline at end of file diff --git a/js/docs-setup.js b/js/docs-setup.js index d833126..7621ab3 100644 --- a/js/docs-setup.js +++ b/js/docs-setup.js @@ -280,7 +280,7 @@ NG_DOCS={ "type": "function", "moduleName": "discussions", "shortDescription": "Reference to a discussion on a person.", - "keywords": "$delete $getdiscussion $getdiscussionrefurl $getdiscussionurl $personid $save $setdiscussionurl _discussion_ _note_ _refresh_ access api attached attributes change changemessage create created creating data delete deleted deletediscussionref details discussion discussionref discussions editable example function functions getdiscussion http individual init message net note object optional options opts parameter pass person promise property read reference references resource resourceid response set token types updated url" + "keywords": "$delete $getdiscussion $getdiscussionrefurl $getdiscussionurl $personid $save $setdiscussion _discussion_ _note_ _refresh_ access api attached attributes attribution change changemessage create created creating data delete deleted deletediscussionref details discussion discussionref discussions editable example function functions getdiscussion http individual init message net note object optional options opts parameter pass person promise property read reference references resource resourceid response set token types updated url" }, { "section": "api", diff --git a/partials/api/discussions.types.constructor.DiscussionRef.html b/partials/api/discussions.types.constructor.DiscussionRef.html index fce6418..675db8b 100644 --- a/partials/api/discussions.types.constructor.DiscussionRef.html +++ b/partials/api/discussions.types.constructor.DiscussionRef.html @@ -45,9 +45,9 @@

Parameters

$setDiscussionUrl(discussion) -
Parameters
ParamTypeDetails
discussionDiscussionstring

Discussion object or discussion url or discussion id

-
Returns
DiscussionRef

this discussion ref

+
  • $setDiscussion(discussion)

    +
    Parameters
    ParamTypeDetails
    discussionDiscussionstring

    Discussion object or discussion url or discussion id

    +
    Returns
    DiscussionRef

    this discussion ref

  • @@ -57,6 +57,10 @@

    Parameters

    Returns
    String

    Id of the person to whom this discussion is attached

    +
  • attribution

    +
    Returns
    Attribution

    Attribution object

    +
    +
  • resource

    Returns
    String

    Discussion URL