Skip to content
Snippets Groups Projects
Commit 2d72b8d5 authored by Eric Rasmussen's avatar Eric Rasmussen
Browse files

Updates and cleanup to edit profile js

parent 62402cc3
No related branches found
No related tags found
No related merge requests found
......@@ -264,7 +264,7 @@ To remove a widget drag it back to the <b>Widget gallery</b>.",
'profile:createicon:instructions' => "Click and drag a square below to match how you want your picture cropped. A preview of your cropped picture will appear in the box on the right. When you are happy with the preview, click 'Create your avatar'. This cropped image will be used throughout the site as your avatar. ",
'profile:editdetails' => "Edit details",
'profile:editicon' => "Edit profile icon (required for map)",
'profile:editicon' => "Edit profile icon",
'profile:aboutme' => "About me",
'profile:description' => "About me",
......
<?php
/**
* Elgg flex profile model
* Functions to save and display profile data
*
* @package Elgg
* @subpackage Form
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
* @author Kevin Jardine <kevin@radagast.biz>
* @copyright Radagast Solutions 2008
* @link http://radagast.biz/
*/
// Load form model
require_once(dirname(dirname(dirname(__FILE__))) . "/form/models/model.php");
// Load form profile model
require_once(dirname(dirname(dirname(__FILE__))) . "/form/models/profile.php");
// Eventually this will be very flexible and return different forms for
// different entities.
// Right now it just returns the first public profile form available.
function flexprofile_get_profile_form($user=null) {
return form_get_latest_public_profile_form(1);
}
// use the specified profile form to return the data (indexed by summary area) from the specified user
function flexprofile_get_data_for_summary_display($form, $user) {
$form_id = $form->getGUID();
$data = form_get_data_from_profile($form_id,$user);
$area_data = array();
$maps = form_get_maps($form_id);
if ($maps) {
foreach($maps as $map) {
$field = get_entity($map->field_id);
//print($field->internal_name.','.$field->field_type.','.$field->choice_type.','.$field->default_value.'<br />');
$internalname = $field->internal_name;
if (isset($data[$internalname]) && $data[$internalname]->value) {
$area = $field->area;
if ($area) {
if (!isset($area_data[$area])) {
$area_data[$area] = array();
}
$item = new StdClass();
$item->internalname = $internalname;
$item->title = form_field_t($form,$field,'title');
$item->description = form_field_t($form,$field,'description');
if ($field->field_type == 'choices') {
$item->fieldtype = $field->choice_type;
$choices = form_get_field_choices($field->getGUID());
$this_choice = '';
foreach($choices as $choice) {
if ($choice->value == $data[$internalname]->value) {
$this_choice = $choice;
break;
}
}
$item->value = form_choice_t($form,$field,$this_choice);
} else {
$item->fieldtype = $field->field_type;
$item->value = $data[$internalname]->value;
}
$area_data[$area][] = $item;
}
}
}
}
return $area_data;
}
// Return the form fields (indexed by tab), optionally prepopulated with data from the specified user.
function flexprofile_get_data_for_edit_form($form, $user=null) {
if ($user) {
$data = form_get_data_from_profile($form->getGUID(),$user);
} else {
$data = array();
}
$tab_data = array();
$form_tabs = form_display_by_tab($form,$data);
$tabs = $form_tabs['main'];
// add access control pulldowns
if ($tabs) {
foreach ($tabs as $tab => $tab_items) {
$tab_data[$tab] = '';
foreach ($tab_items as $item) {
//TODO - remove access controls for invisible fields
$internalname = $item->internalname;
// add access dropdown unless the item is invisible
if (!$item->invisible) {
$access_id = $item->default_access;
$access_bit = '<p class="form-field-access">';
$access_bit .= elgg_view('input/access', array('internalname' => 'flexprofile_access['.$internalname.']','value'=>$access_id));
$access_bit .= '</p>';
} else {
$access_bit = elgg_view('input/hidden', array('internalname' => 'flexprofile_access['.$internalname.']','value'=>ACCESS_PRIVATE));
}
$tab_data[$tab] .= $item->html.$access_bit;
}
}
}
// currently $form_tabs['extra'] is only used for hidden fields, so don't add
// access fields
$tabs = $form_tabs['extra'];
$extra = '';
foreach ($tabs as $item) {
$extra .= $item->html;
}
return array('main'=>$tab_data,'extra'=>$extra);
}
function flexprofile_set_data($entity,$data) {
global $CONFIG;
$entity_guid = $entity->getGUID();
foreach($data as $name => $item) {
remove_metadata($entity_guid, $name);
$value = $item->value;
if (is_array($value)) {
// currently tags are the only field_type returning multiple values
$i = 0;
foreach($value as $interval) {
$i++;
if ($i == 1) { $multiple = false; } else { $multiple = true; }
create_metadata($entity_guid, $name, $interval, 'text', $entity_guid, $item->access_id, $multiple);
}
} else {
create_metadata($entity_guid, $name, $value, '', $entity_guid, $item->access_id);
}
}
}
?>
\ No newline at end of file
<script type="text/javascript">
(function(){
// Edit Profile Stuff
function updateLL () {
function updateL () {
var city = $("input[name=form_data_profile_city]").val(), state = $("select[name=form_data_profile_state]").val(), country = $("select[name=form_data_profile_country]").val();
$.get("<?php echo $vars['url']; ?>mod/unl_theme/scripts/latlon.php",{city:city,state:state,country:country},function(response){
try {
......@@ -11,11 +10,11 @@
$("input[name=form_data_latitude]").val(data.latitude);
$("input[name=form_data_longitude]").val(data.longitude);
WDN.log("Long/lat: " + data.latitude + "/" + data.longitude);
} catch (e) {}
} catch(e) {}
});
};
function updateLLhome () {
function updateLLhome() {
var city = $("input[name=form_data_profile_homecity]").val(), state = $("select[name=form_data_profile_homestate]").val(), country = $("select[name=form_data_profile_homecountry]").val();
$.get("<?php echo $vars['url']; ?>mod/unl_theme/scripts/latlon.php",{city:city,state:state,country:country},function(response){
try {
......@@ -23,12 +22,11 @@
$("input[name=form_data_hometown_latitude]").val(data.latitude);
$("input[name=form_data_hometown_longitude]").val(data.longitude);
WDN.log("Long/lat: " + data.latitude + "/" + data.longitude);
} catch (e) {}
} catch(e) {}
});
};
$(document).ready(function(){
/* SET UP PROFILE EDIT FORM */
$("p.form-description").remove();
......@@ -43,8 +41,6 @@
// remove the text inputs. will be replacing with selectors
$("input[name=form_data_profile_dob_year]").remove();
// remove the country input
var country_parent = $("input[name=form_data_profile_country]").parent();
$("input[name=form_data_profile_country]").remove();
......@@ -62,14 +58,13 @@
$("input[name=form_data_profile_city]").parent().find("label").html('Your map location <span class="helper">Please enter the location you want to use for yourself on the map.</span>');
/* set up various year inputs */
/********** Set up various year inputs */
var x = 1900, html = '<option value="">--</option>';
var curYear = (new Date()).getFullYear();
/*** DOB Year */
var selYear = document.createElement("select");
selYear.name = "form_data_profile_dob_year";
while (x++ < curYear) {
html+= '<option';
if (x == dob_year) {
......@@ -79,8 +74,9 @@
}
$(selYear).html(html);
$("input[name=form_data_profile_dob_month]").parent().append(selYear);
/*** Attended from (Year) */
var selFrom = document.createElement("select");
selFrom.name = "form_data_profile_attended_from";
x = 1940;
......@@ -96,6 +92,7 @@
$(selFrom).html(html);
from_parent.append(selFrom);
/*** Attended to (Year) */
var selTo = document.createElement("select");
selTo.name = "form_data_profile_attended_to";
x = 1940;
......@@ -319,7 +316,6 @@
}
html += '>' + countries[i] + '</option>';
}
$(selCountry).html(html);
var selState = document.createElement("select");
......@@ -332,7 +328,6 @@
}
html += '>' + states[i] + '</option>';
}
$(selState).html(html);
var selhomeCountry = document.createElement("select");
......@@ -345,7 +340,6 @@
}
html += '>' + countries[i] + '</option>';
}
$(selhomeCountry).html(html);
var selhomeState = document.createElement("select");
......@@ -358,49 +352,33 @@
}
html += '>' + states[i] + '</option>';
}
$(selhomeState).html(html);
$("input[name=form_data_profile_dob_month]").parent().append(selYear);
country_parent.append(selCountry);
state_parent.append(selState);
homecountry_parent.append(selhomeCountry);
homestate_parent.append(selhomeState);
$("input[name=form_data_profile_dob_day]").insertBefore($("select[name=form_data_profile_dob_year]"));
/********** Lat/Long */
// don't display the latitude/longitude fields
$("input[name=form_data_latitude],input[name=form_data_longitude]").parent().hide();
$("input[name=form_data_hometown_latitude],input[name=form_data_hometown_longitude]").parent().hide();
// update the lat/long automatically whenever current location is changed
// update the lat/long automatically whenever current or hometown location is changed
$("input[name=form_data_profile_city],select[name=form_data_profile_state],select[name=form_data_profile_country]").change(function(){
updateLL();
});
$("input[name=form_data_hometown_latitude],input[name=form_data_hometown_longitude]").parent().hide();
// update the lat/long automatically whenever current location is changed
$("input[name=form_data_profile_homecity],select[name=form_data_profile_homestate],select[name=form_data_profile_homecountry]").change(function(){
updateLLhome();
});
$("#profileEditor label").each(function(){
if (this.innerHTML.match(/day/i) || this.innerHTML.match(/year/i) ){
$(this).parent().remove();
} else if (this.innerHTML.match(/month/i)) {
this.innerHTML = "Birthday";
}
});
/********* UNL Role */
var unlrole = $('form input[name=form_data_profile_role]').val();
if (unlrole == "alum") {
$('form input[name=form_data_profile_role]').val("alumnus");
}
$('form input[name=form_data_profile_role]').replaceWith('<select name="form_data_profile_role" class="input-pulldown">'+
'<option value="Prospective Student">Prospective Student</option>'+
'<option value="Current Student">Current Student</option>'+
......@@ -435,25 +413,35 @@
break;
}
$('form select[name=form_data_profile_role] option[value='+unlrole+']').attr('selected','selected');
var dob_month = $("input[name=form_data_profile_dob_month]").val(),
dob_day = $("input[name=form_data_profile_dob_day]").val();
/********* DOB Label */
$("label[for='form_data_profile_dob_month']").html('Birthday');
$("label[for='form_data_profile_dob_day']").remove();
$("label[for='form_data_profile_dob_year']").remove();
//Move Day to before year
$("input[name=form_data_profile_dob_day]").insertBefore($("select[name=form_data_profile_dob_year]"));
/********* DOB Month */
var dob_month = $("input[name=form_data_profile_dob_month]").val();
var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
var monthsHTML = '<option value="">--</option>';
for (var i = 0, l = months.length; i < l; i++){
for (var i = 0, l = months.length; i < l; i++) {
monthsHTML+= '<option value="' + months[i] + '">' + months[i] + '</option>';
}
$('form input[name=form_data_profile_dob_month]').replaceWith('<select name="form_data_profile_dob_month" class="input-pulldown">'+monthsHTML+'</select>');
$("select[name=form_data_profile_dob_month] option[value=" + dob_month + "]").attr("selected","selected");
/********* DOB Day */
var dob_day = $("input[name=form_data_profile_dob_day]").val();
var daysHTML = '<option value="">--</option>';
for (var i = 1, l = 32; i < l; i++){
for (var i = 1, l = 32; i < l; i++) {
daysHTML+= '<option value="' + i + '">' + i + '</option>';
}
$('form input[name=form_data_profile_dob_day]').replaceWith('<select name="form_data_profile_dob_day" class="input-pulldown">'+daysHTML+'</select>');
$('form input[name=form_data_profile_dob_day]').replaceWith('<select name="form_data_profile_dob_day" class="input-pulldown">'+daysHTML+'</select>');
$("select[name=form_data_profile_dob_day] option[value=" + dob_day + "]").attr("selected","selected");
/********* Alumni Checkbox */
var alumniOptIn = $("input[name=form_data_info_alumni_opt_in]").val();
$("input[name=form_data_info_alumni_opt_in]").replaceWith('<input type="checkbox" name="form_data_info_alumni_opt_in" value="yes" />');
if (alumniOptIn == "yes"){
......@@ -467,15 +455,14 @@
$("input[name=form_data_info_alumni_opt_in]").parent().hide();
}
};
alumniCheckbox();
$("select[name=form_data_profile_role]").change(alumniCheckbox);
//$("body.fixed #maincontent textarea[name=form_data_profile_unl_impact]").parent().css({clear:"both",display:"block","margin-left":"150px"}).siblings("label").css("width","330px");
/********** Display Form */
$("#formloading").remove();
$("#profileEditor").show();
});
})();
</script>
\ No newline at end of file
</script>
......@@ -11,40 +11,35 @@
* @link http://radagast.biz/
*/
/* copied from flexprofile and modified for UNL */
// Load flexprofile model
require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))) . "/flexprofile/models/model.php");
include(dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/unl_theme/scripts/JS/enhanceProfileForm.php');
require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/unl_theme/scripts/JS/enhanceProfileForm.php');
$user = $vars['entity'];
$form = flexprofile_get_profile_form($user);
if ($form) {
$tab_data = flexprofile_get_data_for_edit_form($form, $user);
if ($_GET['firstlogin'] == 'yes'){
if (get_input('firstlogin') == 'yes') {
?>
<div class="zenbox soothing">
<h3>Thanks for joining Planet Red!</h3>
<p>You're just a few quick steps from putting yourself on the map. Start by filling out your profile information.</p>
</div>
</div><br /><br />
<?php
}
//echo '<div id="formloading"><img src="/wdn/templates_3.0/css/header/images/colorbox/loading.gif" alt="Loading Form" /><noscript>Please enable JavaScript to use the profile editor.</noscript></div>';
echo '<form action="'.$vars['url'].'action/flexprofile/edit" method="post" enctype="multipart/form-data" class="zenform primary" id="profileEditor">';
echo '<div id="formloading"><img src="/wdn/templates_3.0/css/header/images/colorbox/loading.gif" alt="Loading Form" /><noscript>Please enable JavaScript to use the profile editor.</noscript></div>';
echo '<form action="'.$vars['url'].'action/flexprofile/edit" method="post" enctype="multipart/form-data" class="zenform primary" id="profileEditor" style="display:none;">';
echo elgg_view('input/securitytoken');
echo "<fieldset><ol>";
echo '<fieldset><ol>';
echo elgg_view('form/forms/display_form_content',array('tab_data'=>$tab_data,'description'=>'','preview'=>0,'form'=>$form,'form_data_id'=>0));
if ($_GET['firstlogin'] == 'yes'){
?>
<input type="hidden" name="firstlogin" value="yes" />
<?php
if (get_input('firstlogin') == 'yes') {
echo '<input type="hidden" name="firstlogin" value="yes" />';
}
echo "</ol></fieldset>";
echo '</ol></fieldset>';
?>
<p>
......
<?php
/**
* Elgg profile icon / profile links: passive links when looking at your own icon / profile
*
* @package ElggProfile
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
* @author Curverider Ltd <info@elgg.com>
* @copyright Curverider Ltd 2008-2010
* @link http://elgg.com/
*
* @uses $vars['entity'] The user entity. If none specified, the current user is assumed.
*/
?>
<?php
if ($vars['entity']->canEdit())
{
?>
<p class="user_menu_profile">
<a href="<?php echo $vars['url']?>pg/profile/<?php echo $vars['entity']->username; ?>/edit/"><?php echo elgg_echo("profile:edit"); ?></a>
</p>
<p class="user_menu_profile">
<a href="<?php echo $vars['url']?>pg/profile/<?php echo $vars['entity']->username; ?>/editicon/"><?php echo elgg_echo("profile:editicon"); ?></a>
</p>
<?php
}
?>
<p class="user_menu_friends">
<a href="<?php echo $vars['url']; ?>pg/friends/<?php echo $vars['entity']->username; ?>/"><?php echo elgg_echo("friends"); ?></a>
</p>
<p class="user_menu_friends_of">
<a href="<?php echo $vars['url']; ?>pg/friendsof/<?php echo $vars['entity']->username; ?>/"><?php echo elgg_echo("friends:of"); ?></a>
</p>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment