|
| 1 | +/* |
| 2 | + the mainjs file for the app, |
| 3 | + It actually bridges the gap between sytuff |
| 4 | + @author ksdme |
| 5 | +*/ |
| 6 | +var ProfileTemplates; |
| 7 | + |
| 8 | +var ProfilesContainerMap = { |
| 9 | + core: { |
| 10 | + sel: "#core-team-container", |
| 11 | + beforeInsert: function() { |
| 12 | + $("#core-team-label").show() |
| 13 | + } |
| 14 | + }, |
| 15 | + |
| 16 | + community: { |
| 17 | + sel: "#members-container", |
| 18 | + beforeInsert: function() { |
| 19 | + $("#members-label").show() |
| 20 | + } |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +function buildTemplates() { |
| 25 | + ProfileTemplates = Pseudo.fromGroup("#profile-card") |
| 26 | +} |
| 27 | + |
| 28 | +function buildCard(member) { |
| 29 | + /* to avoid reflecting hacks */ |
| 30 | + member = jQuery.extend(true, {}, member); |
| 31 | + |
| 32 | + var socialUrlHTML = ""; |
| 33 | + for (var nmType in member.profile_social) { |
| 34 | + |
| 35 | + /* |
| 36 | + you need build a params |
| 37 | + dictionary from a dynamic var |
| 38 | + */ |
| 39 | + var params = {} |
| 40 | + params[nmType] = member.profile_social[nmType] |
| 41 | + |
| 42 | + socialUrlHTML += ProfileTemplates[nmType].render(params) |
| 43 | + } |
| 44 | + |
| 45 | + /* avoid possible side effects */ |
| 46 | + delete member.profile_social |
| 47 | + |
| 48 | + /* |
| 49 | + render out the base profile along with |
| 50 | + the the social links HTML |
| 51 | + */ |
| 52 | + return ProfileTemplates.base_profile.render( |
| 53 | + jQuery.extend({ |
| 54 | + profile_social_links: socialUrlHTML |
| 55 | + }, member) |
| 56 | + ) |
| 57 | +} |
| 58 | + |
| 59 | +/* render an entire community */ |
| 60 | +function buildCommunity(community) { |
| 61 | + for (var listType in community) { |
| 62 | + var subCommunityMembers = community[listType].members |
| 63 | + var subCommunityHTML = "" |
| 64 | + |
| 65 | + for (var member in subCommunityMembers) { |
| 66 | + subCommunityHTML += buildCard(subCommunityMembers[member]) |
| 67 | + } |
| 68 | + |
| 69 | + if (subCommunityHTML === "") |
| 70 | + continue |
| 71 | + |
| 72 | + /* init containers to accept */ |
| 73 | + var htmlContainerRoute = ProfilesContainerMap[listType] |
| 74 | + htmlContainerRoute.beforeInsert() |
| 75 | + |
| 76 | + var htmlContainer = $(htmlContainerRoute.sel) |
| 77 | + htmlContainer.html(htmlContainer.html()+subCommunityHTML) |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +$(function() { |
| 82 | + buildTemplates(); |
| 83 | + |
| 84 | + Fetch.all(function(community) { |
| 85 | + buildCommunity(community) |
| 86 | + }) |
| 87 | +}) |
0 commit comments