(function($, dermquest, window, undefined){ dermquest.register("Settings", new function(){ var me = {}; me.Dictionary = { no_facets: "-- Undetermined --", no_results: "No results matched the search criteria. Remove filters on the left to broaden your search.", and_operator: "and", or_operator: "or", none: "None" } me.Templates = { image_touch_interaction: 'Touch the image to zoom or tap here to view full size', image_click_interation: 'Hover over the image to zoom or click here to view full size', image_search_results: "Showing {{#min}}{{min}}-{{max}} of{{/min}} {{total_results}} results", single_image_search_result: "Showing {{total_results}} result", view_images: 'View Images', no_visible_facets: '

No further refinements

', confirm_facets: 'Confirm', error_feedback: '

{{error_message}}

', confirm_modal: '' } me.Resources = { image_feed_url: "/Services/imageData.ashx", facet_feed: "/Services/facetData.ashx", locker_add: "/helper/addToPersonalLocker.ashx", locker_add_modal: "/popups/personal-locker-general-use/", locker_first_add_modal: "/popups/personal-locker-first-use/", locker_remove: "/Services/DermQuestRestServices.svc/DeleteBookmark", remove_confim_modal: "/popups/personal-locker-delete/", member_rating_feed: "/Services/DermQuestRestServices.svc/RateImage", remove_image_submission_image: "/popups/submit-your-own-delete-image/", blog_feed: "/Helper/loadExpertOpinion.ashx" } me.Objects = { Model: Backbone.Model.extend(), DynamicState: function(id, include_operator) { var model = new Model, obj = { id: id, selection: [] }; if (include_operator) { obj.operator = 0; } model.set(obj) return model; }, State: function(id, include_operator) { var obj = { id: id, selection: [] }; if (include_operator) { obj.operator = 0; } return obj; }, BodySelection: function($target, config) { var me = _.extend({}, Backbone.Events), $me = $('
'); var data = config.data || config.model.get('data')[config.id], state = new dermquest.Settings.Objects.State(config.id); var $body_selector = $('
'), $no_facets_feedback = $(dermquest.Settings.Templates.no_visible_facets).hide(), $body_map; var LeftList, RightList; function init() { build(); $me.on("mouseenter", ".body-section", function (e) { var $target = $(e.currentTarget), facet_id = parseInt($target.attr("data-facet-id")); focus(facet_id); }); $me.on("mouseleave", ".body-section", function (e) { var $target = $(e.currentTarget), facet_id = parseInt($target.attr("data-facet-id")); blur(); }); $me.on("mouseenter", "label", function (e) { var $target = $(e.currentTarget), $branch_root = $target.parents('.branch-root'), facet_id = parseInt($branch_root.attr("data-facet-id")), $body_section = $body_map.find('[data-facet-id=' + facet_id + ']'); $body_section.addClass('highlight'); }); $me.on("mouseleave", "label", function (e) { var $target = $(e.currentTarget), $branch_root = $target.parents('.branch-root'), facet_id = parseInt($branch_root.attr("data-facet-id")), $body_section = $body_map.find('[data-facet-id=' + facet_id + ']'); $body_section.removeClass('highlight'); }); config.model.on("change:route", function(e, route) { if (route) { var my_route = route[config.id]; if (my_route && my_route.length > 0) { state.selection = my_route; update(route[config.id]); } else { reset(); } } else { reset(); } }); config.model.on('change:results', function(e, results){ if (results) { var my_results = results[config.id], visible_facets = state.selection; if (my_results) { visible_facets = _.union(visible_facets, my_results) } filter(visible_facets); } else { reset(); } }); $target.append($me); } function build() { $body_map = $('
'); var $left_wrapper = $('
'), $right_wrapper = $('
'); var roots = data.Roots, left_collections = [], right_collections = []; for (var i = 0, l = roots.length; i < l; i++) { var root = roots[i], $body_part = $(''); $body_map.append($body_part) if (i % 2 === 0) { left_collections.push(root); } else { right_collections.push(root); } } var left_config = { 'data': data, 'id': config.id, 'panelled': true }, right_config = _.extend({}, left_config); left_config.roots = left_collections; LeftList = new dermquest.Settings.Objects.SelectList($left_wrapper, left_config); right_config.roots = right_collections; RightList = new dermquest.Settings.Objects.SelectList($right_wrapper, right_config); LeftList.on("branch-update", function (facet_id, active) { getState(); updateBody(facet_id, active); }) RightList.on("branch-update", function (facet_id, active) { getState(); updateBody(facet_id, active); }); if (!config.hide_trigger) { var $trigger = $(dermquest.Settings.Templates.view_images); $right_wrapper.append($trigger) } $body_selector.append($left_wrapper, $body_map, $right_wrapper); $me.append($body_selector, $no_facets_feedback) } function focus(facet_id) { LeftList.focus(facet_id); RightList.focus(facet_id); } function blur() { LeftList.blur(); RightList.blur(); } function updateBody(facet_id, active) { var $body_part = $body_map.find('[data-facet-id="' + facet_id + '"]'); if (active) { $body_part.activate(); } else { $body_part.deactivate(); } } function filterBody() { var $sections = $body_map.find('.body-section'); $body_map.addClass('filtered'); for (var i = 0, l = $sections.length; i < l; i++) { var $section = $sections.eq(i), $input = $('#' + $section.attr('for')); if ($input.parent('li').hasClass('show')) { $section.addClass('show'); } } } function getState() { state.selection = _.union(LeftList.getSelection(), RightList.getSelection()); return state; } function filter(active_facets) { if (active_facets.length) { LeftList.filter(active_facets); RightList.filter(active_facets); filterBody(active_facets); $body_selector.show(); $no_facets_feedback.hide(); } else { $body_selector.hide(); $no_facets_feedback.show(); } } function update(selection) { LeftList.update(selection); RightList.update(selection); } function reset() { LeftList.reset(); RightList.reset(); $body_map.removeClass('filtered'); $body_map.find('.body-section').removeClass('show active'); } init(); me.init = init; me.reset = reset; me.getState = getState; return me; }, ActiveFacetList: function(model) { var me = _.extend({}, Backbone.Events), $me = $('.filter-list'); var model_width = 780; function init() { $me.on("click", ".filter-trigger", function (e) { e.preventDefault(); var $trigger = $(e.currentTarget), target = $trigger.attr("href"), $target = $(target); $target.activate(); dermquest.Common.Modal.open(target); }) model.on("change:route", function() { if (model.get('route')) { update(); } }) model.test = true; } function update() { reset(); var $list = $("
    "), data = model.get('data'), route = model.get('route'); _.each(data, function(value, key){ var collection = data[key], state_collection = route[key], width = model_width; var $item = $("
  • "); $item.attr("data-category-id", collection.Name); if (collection.Name === "localization") { width = 747; } $item.append('' + collection.Text + ''); if (state_collection && state_collection.length) { var $inner_list = $("
      "); for (var p = 0, pl = state_collection.length; p < pl; p++) { var facet_id = state_collection[p], facet = collection.Facets[facet_id], operator_text = dermquest.Settings.Dictionary.or_operator, operator = route[key + "MatchAll"]; if (facet) { if (p === pl - 1) { operator_text = '' } else { if (operator === 1) { operator_text = dermquest.Settings.Dictionary.and_operator } operator_text = ' ' + operator_text + ''; } var $facet_item = $('
    • ' + facet.Text.toTitle() + operator_text + 'X
    • '); $inner_list.append($facet_item); } } $item.append($inner_list); } $list.append($item) }); if ($list.html().length > 0) { $me.html($list); } } function reset() { $me.empty(); } me.update = update; init(); return me; }, SelectList: function($parent, config) { var me = _.extend({}, Backbone.Events), $me = $('
      '); var filtered = false; var data = config.data; if (!config.roots) { config.roots = data.Roots; } var state = new dermquest.Settings.Objects.State(config.id); function init() { // Two events fired for each input element... // Triggered only when the element is clicked $me.on("click", "input", function (e) { updateBranch(e.currentTarget); }); // Triggered whenever the input element is changed $me.on("change", "input", function (e) { updateLeaf(e.currentTarget); }); $me.on("mouseenter", "label", function (e) { $(e.currentTarget).siblings('ul').addClass('highlight'); }); $me.on("mouseleave", "label", function (e) { $(e.currentTarget).siblings('ul').removeClass('highlight'); }); build(); } function build() { function buildBranch(facets, root) { var branch_html = "
        "; for (var i = 0, l = facets.length; i < l; i++) { var id = facets[i], facet = data.Facets[id], input_id = "facet_" + id, item = '