/*1298995513,169775559*/
if (window.CavalryLogger) {
CavalryLogger.start_js(["dfIHW"]);
}
function ProfileChooser() {
this.parent.construct(this);
this.checkedItems = {};
this.cache = {};
this.suggested = {};
this.activeCache = null;
this.index = 0;
}
ProfileChooser.extend('ProfileBrowser');
ProfileChooser.prototype = {
VALUE_DEFAULT: 'default',
VALUE_SELECTED: 'selected',
VALUE_DISABLED: 'disabled',
NUM_PER_PAGE: 50,
preloadCache: function (b, c) {
this.suggested = c;
this.cache = b;
for (var a in this.cache) this.sortSuggested(a);
},
subscribeListView: function () {
this.listView.subscribe('scrollTrigger', function () {
var b = this.index;
var a = b + this.NUM_PER_PAGE;
var c = this.cache[this.activeCache].slice(b, a);
if (c.length) {
this.index = a;
this.appendToView(c);
this.listView.resetScroll();
}
}.bind(this));
this.listView.subscribe('clickedCheckable', function (a, e) {
var c = CSS.hasClass(e.item, 'selectedCheckable');
var b = DOM.find(e.item, '.checkbox');
var f = this.listView.getRoot();
if (!c && CSS.hasClass(f, 'limitReached')) {
b.checked = false;
return;
}
var g = b.value;
this.typeahead.getData().data[g].selected = !c;
this.checkedItems[g] = !c ? 1 : 0;
this.typeahead.getCore().hiddenInput.value = JSON.stringify(this.checkedItems);
this.listView.toggleCheckableItem(e.item, c);
var d = this.getCheckedCount();
CSS.conditionClass(f, 'limitReached', d >= this.getSelectionLimit());
this.inform('updateCheckableCount', {
listview: f.id,
count: d
});
}.bind(this));
},
subscribeSelector: function () {
this.selector.subscribe('changeListEndpoint', function (a, b) {
b.anchor.removeAttribute('data-listendpoint');
this.resetTypeahead(b.showTypeahead);
this.queryListEndpoint(b.endpoint, b.value);
}.bind(this));
this.selector.subscribe('changeValue', function (a, b) {
this.resetTypeahead(b.showTypeahead);
if (b.value == this.VALUE_SELECTED) {
var c = [];
for (var d in this.checkedItems) this.checkedItems[d] && c.push(d);
this.cache[b.value] = c;
}
this.resetView(b.value);
}.bind(this));
},
subscribeTypeahead: function () {
var a = this.typeahead.getData();
a.subscribe('activity', function (b, c) {
this.listView.setLoadingState(c.activity || this.querying);
c.activity && this.listView.swapList(this.typeahead.getView().element);
}.bind(this));
a.subscribe('fillCache', function (b, e) {
this.cache[this.VALUE_DEFAULT] = e.alluids;
this.sortSuggested(this.VALUE_DEFAULT);
this.cache[this.VALUE_DISABLED] = e.disabled;
this.cache[this.VALUE_SELECTED] = e.selected;
var c = this.selector.getSelectedAnchor();
var f = this.selector.getSelectedValue();
if (this.cache[f]) {
this.resetView(f);
} else {
var d = c.getAttribute('data-listendpoint');
if (d) {
this.queryListEndpoint(d, f);
c.removeAttribute('data-listendpoint');
}
}
this.checkedItems = e.selected;
this.typeahead.getCore().hiddenInput.value = JSON.stringify(this.checkedItems);
this.activeCache = f;
}.bind(this));
this.typeahead.subscribe('render', function (b, c) {
if (!this.typeahead.getCore().getValue()) {
this.listView.resetScroll();
this.index = c.length;
}
}.bind(this));
this.typeahead.subscribe('reset', function () {
this.resetView(this.activeCache);
}.bind(this));
},
queryListEndpoint: function (a, b) {
this.querying = true;
this.listView.setLoadingState(true);
new AsyncRequest(a).setHandler(function (d) {
var c = d.getPayload();
this.cache[b] = c.ids;
this.suggested[b] = c.suggested;
this.sortSuggested(b);
this.resetView(b);
this.listView.setLoadingState(false);
this.querying = false;
}.bind(this)).send();
},
resetTypeahead: function (b) {
CSS.conditionShow(this.typeahead.getElement(), b);
var a = this.typeahead.getCore();
a.reset();
b && a.getElement().focus();
a.hiddenInput.value = JSON.stringify(this.checkedItems);
},
sortSuggested: function (b) {
var c = this.suggested[b];
if (!c) return;
var a = this.cache[b];
var e = Object.from(a);
var d = c.filter(function (f) {
if (f in e) {
a.splice(a.indexOf(f), 1);
return true;
}
return false;
});
this.cache[b] = d.concat(a);
},
resetView: function (a) {
this.activeCache = a;
var b = this.typeahead.getData();
var c = this.cache[a];
b.setSuggestedUids(this.suggested[a] || []);
b.respond('', c, true);
b.setInclusions(c);
},
appendToView: function (b) {
var a = this.typeahead.getData().buildData(b);
this.typeahead.getView().appendResults(a);
},
getCheckedCount: function () {
var a = 0;
for (var b in this.checkedItems) if (this.checkedItems[b]) a++;
return a;
}
};
function ProfileChooserSelector() {
this.parent.construct(this);
}
ProfileChooserSelector.extend('ProfileBrowserSelector');
ProfileChooserSelector.prototype = {
handle: function (c) {
var a = DOM.find(c.option, 'a');
var b = a.getAttribute('data-listendpoint');
var e = Selector.getOptionValue(c.option);
var d = a.getAttribute('data-typeahead');
if (b) {
this.inform('changeListEndpoint', {
anchor: a,
endpoint: b,
value: e,
showTypeahead: d
});
return;
}
this.inform('changeValue', {
value: e,
showTypeahead: d
});
}
};
function ProfileChooserDataSource(b, c, a) {
this.parent.construct(this, b);
this.selectedEntries = c;
this.disabledEntries = a;
this.suggestedUids = {};
this.inclusions = [];
this.exclusionsObj = Object.from(this.exclusions);
}
ProfileChooserDataSource.extend('DataSource');
ProfileChooserDataSource.prototype = {
bootstrap: function () {
if (this.bootstrapped) return;
this.fetch(this.bootstrapEndpoint, this.bootstrapData, '', '');
this.bootstrapped = true;
},
processEntries: function (a, b) {
var c = this.parent.processEntries(a, b);
c = this.removeExclusions(c);
c.each(function (e) {
var d = this.data[e];
d.selected = e in this.selectedEntries;
d.disabled = e in this.disabledEntries;
}, this);
this.setInclusions(c);
return c;
},
setInclusions: function (a) {
this.inclusions = a || [];
return this;
},
buildCacheResults: function (d, a) {
var c = this.parent.buildCacheResults(d, a);
var b = Object.from(this.inclusions);
return c.filter(function (e) {
return e in b;
});
},
buildUids: function (c, a) {
if (c) return this.parent.buildUids(c, a);
if (this.inclusions) return this.inclusions;
var b = this.exclusionsObj;
return values(this.data || {}).sort(function (d, e) {
return d.index - e.index;
}).map(function (d) {
return d.uid;
}).concat(a || []).filter(function (d) {
if (d in b) return false;
return (b[d] = true);
});
},
buildData: function (c) {
var a = this.parent.buildData(c);
var b = this.suggestedUids;
a.each(function (d) {
d.suggested = (d.uid in b);
});
return a;
},
removeExclusions: function (a) {
return a.filter(function (b) {
return !(b in this.exclusionsObj);
}.bind(this));
},
setSuggestedUids: function (a) {
this.suggestedUids = Object.from(a);
},
fillCache: function (a) {
a = this.removeExclusions(a);
this.parent.fillCache(a);
this.inform('fillCache', {
alluids: a,
selected: this.selectedEntries,
disabled: this.disabledEntries
});
}
};
function ProfileChooserTypeaheadCore(a, b) {
this.parent.construct(this, a, b);
}
ProfileChooserTypeaheadCore.extend('TypeaheadCore');
ProfileChooserTypeaheadCore.prototype = {
keepFocused: false,
initToggle: bagofholding,
initView: bagofholding,
select: bagofholding,
keyup: function () {
this.checkValue();
}
};
function ProfileChooserTypeaheadView(a, b) {
this.parent.construct(this, a, b);
}
ProfileChooserTypeaheadView.extend('TypeaheadView');
ProfileChooserTypeaheadView.prototype = {
render: function (j, e, f) {
var d = this.results[this.index],
c = this.autoSelect ? 0 : -1,
a = [];
if (j) {
var h;
var i = {
search: _tx("\u003cstrong>{value}\u003c\/strong>", {
value: htmlize(j)
})
};
if (!e || !e.length) {
h = _tx("No results for: {search}", i);
} else if (e.length == 1) {
h = _tx("Top result for: {search}", i);
} else {
i.count = e.length;
h = _tx("Top {count} results for: {search}", i);
}
a = ['<div class="fbProfileBrowserSummaryBox pvm phs mhs">', h, '</div>'];
}
a.push('<div class="fbProfileBrowserListContainer">', this.buildMarkup(e), '</div>');
this.results = e;
CSS.conditionClass(this.element, 'hideSummary', !j);
this.element.innerHTML = a.join('');
this.items = this.getItems();
if (d && f) for (var b = 0, g = e.length; b < g; ++b) if (d.uid == e[b].uid) {
c = b;
break;
}
this.highlight(c, false);
this.inform('render', e);
},
buildMarkup: function (c) {
var d = [];
var b = [];
var a = [];
c.each(function (e) {
if (e.suggested) {
d.push(e);
} else b.push(e);
});
if (d.length) {
a.push('<div class="clearfix">', this.parent.buildMarkup(d), '</div>');
if (b.length) a.push('<div class="suggestedDivider mts">', '<span class="fss fcg fwb phs dividerText">', _tx("ALL FRIENDS"), '</span>', '</div>');
}
a.push(this.parent.buildMarkup(b));
return a.join('');
},
renderer: function (a, b) {
if (!a) return [];
var c = a.suggested ? _tx("Suggested") : a.category;
var d = htmlize(a.text);
var e = d.length > 20 ? 'long' : '';
return ['<li class="multiColumnCheckable checkableListItem ', a.disabled ? ' disabledCheckable' : '', a.selected ? ' selectedCheckable' : '', '">', '<input type="checkbox" class="checkbox" name="checkableitems[]"', 'value="', htmlspecialchars(a.uid), '"', a.selected ? ' checked="1"' : '', a.disabled ? ' disabled="1"' : '', '/>', '<a class="anchor" href="#" tabindex="-1">', '<div class="UIImageBlock clearfix UIImageBlock_Entity">', '<img src="', a.photo, '" ', 'class="photo UIImageBlock_Image img UIImageBlock_ENT_Image"', '/>', '<div class="content UIImageBlock_Content">', '<div class="fcb fwb text ', e, '">', d, '</div>', '<div class="fcg text subtitle">', c, '</div>', '</div>', '</div>', '</a>', '</li>'];
},
highlight: function (a, b) {
if (a > this.items.length - 1) {
a = -1;
} else if (a < -1) a = this.items.length - 1;
if (a >= 0 && this.results[a] && !this.results[a].disabled) {
this.selected = this.items[a];
} else this.selected = null;
this.index = a;
if (b !== false) this.inform('highlight', {
index: a,
selected: this.results[a]
});
},
appendResults: function (b) {
var a = DOM.find(this.element, '.fbProfileBrowserListContainer');
DOM.appendContent(a, HTML(this.buildMarkup(b)));
}
};
if (window.Bootloader) {
Bootloader.done(["dfIHW"]);
}