Commit | Line | Data |
---|---|---|
444f2d43 DT |
1 | /** |
2 | * FSF Member Dashboard | |
3 | * Copyright © 2014 Free Software Foundation, Inc. | |
4 | * | |
5 | * This file is a part of FSF Member Dashboard. | |
6 | * | |
7 | * FSF Member Dashboard is free software; you can copy, modify, and | |
8 | * distribute it under the terms of the GNU Affero General Public | |
9 | * License Version 3, 19 November 2007 and the CiviCRM Licensing | |
10 | * Exception. | |
11 | * | |
12 | * FSF Member Dashboard is distributed in the hope that it will be | |
13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty | |
14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Affero General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with FSF Member Dashboard. If not, see | |
19 | * <http://www.gnu.org/licenses/>. | |
20 | */ | |
21 | ||
5bf8e499 | 22 | (function($) { |
444f2d43 | 23 | function loadProfile(gid, success) { |
5bf8e499 | 24 | $.get('/civicrm/profile/edit', { |
444f2d43 DT |
25 | gid: gid, |
26 | json: 1 | |
27 | }, success); | |
28 | } | |
29 | ||
30 | function renderProfile(profile) { | |
31 | function renderFields() { | |
32 | return _.chain(profile) | |
33 | .values() | |
34 | .filter(function(field) { | |
35 | return _.isString(field.label) && _.isString(field.html); | |
36 | }) | |
37 | .map(function (field) { | |
ed7aee9f | 38 | return $('<div class="form-item"></div>') |
444f2d43 DT |
39 | .append(field.label) |
40 | .append(field.html); | |
41 | }) | |
42 | .value(); | |
43 | } | |
44 | ||
5bf8e499 DT |
45 | // Support older versions of jQuery that don't parse the JSON by |
46 | // default. | |
47 | profile = _.isString(profile) ? JSON.parse(profile): profile; | |
444f2d43 DT |
48 | var form = $('<form' + profile.attributes + '></form>'); |
49 | ||
50 | form.append(profile.requirednote) | |
51 | .append(profile.hidden) | |
52 | .append.apply(form, renderFields()); | |
53 | ||
473ce7cb | 54 | $('#info-loading').remove(); |
5bf8e499 | 55 | $('#info-form').append(form); |
444f2d43 DT |
56 | } |
57 | ||
58 | $(document).ready(function() { | |
a2dcdb05 | 59 | loadProfile(memberDashboard.profileId, renderProfile); |
444f2d43 | 60 | }); |
5bf8e499 | 61 | })(jQuery); |