forked from GNUsocial/gnu-social
Extended profile - more work on getting complex fields to save
This commit is contained in:
parent
08018a1f7b
commit
deb40602d2
@ -106,6 +106,7 @@ class ExtendedProfile
|
|||||||
if (empty($phones)) {
|
if (empty($phones)) {
|
||||||
$pArrays[] = array(
|
$pArrays[] = array(
|
||||||
'label' => _m('Phone'),
|
'label' => _m('Phone'),
|
||||||
|
'index' => 0,
|
||||||
'type' => 'phone',
|
'type' => 'phone',
|
||||||
'vcard' => 'tel',
|
'vcard' => 'tel',
|
||||||
'multi' => true
|
'multi' => true
|
||||||
@ -115,7 +116,7 @@ class ExtendedProfile
|
|||||||
$pa = array(
|
$pa = array(
|
||||||
'label' => _m('Phone'),
|
'label' => _m('Phone'),
|
||||||
'type' => 'phone',
|
'type' => 'phone',
|
||||||
'index' => $phones[$i]->value_index,
|
'index' => intva($phones[$i]->value_index),
|
||||||
'rel' => $phones[$i]->rel,
|
'rel' => $phones[$i]->rel,
|
||||||
'value' => $phones[$i]->field_value,
|
'value' => $phones[$i]->field_value,
|
||||||
'vcard' => 'tel'
|
'vcard' => 'tel'
|
||||||
|
@ -184,8 +184,12 @@ class ExtendedProfileWidget extends Form
|
|||||||
$index = $field['index'];
|
$index = $field['index'];
|
||||||
$id = "extprofile-$name-$index";
|
$id = "extprofile-$name-$index";
|
||||||
$rel = $id . '-rel';
|
$rel = $id . '-rel';
|
||||||
|
$this->out->elementStart(
|
||||||
$this->out->elementStart('div', array('class' => 'phone-edit'));
|
'div', array(
|
||||||
|
'id' => $id . '-edit',
|
||||||
|
'class' => 'phone-edit'
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->out->input($id, null, $field['value']);
|
$this->out->input($id, null, $field['value']);
|
||||||
$this->out->dropdown(
|
$this->out->dropdown(
|
||||||
$id . '-rel',
|
$id . '-rel',
|
||||||
@ -205,10 +209,19 @@ class ExtendedProfileWidget extends Form
|
|||||||
$this->out->element(
|
$this->out->element(
|
||||||
'a',
|
'a',
|
||||||
array(
|
array(
|
||||||
'name' => $name,
|
'class' => 'add_row',
|
||||||
'href' => 'javascript://'),
|
'href' => 'javascript://'),
|
||||||
'+'
|
'+'
|
||||||
);
|
);
|
||||||
|
$this->out->element(
|
||||||
|
'a',
|
||||||
|
array(
|
||||||
|
'class' => 'remove_row',
|
||||||
|
'href' => 'javascript://',
|
||||||
|
'style' => 'display: none; '
|
||||||
|
),
|
||||||
|
'-'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
$this->out->elementEnd('div');
|
$this->out->elementEnd('div');
|
||||||
}
|
}
|
||||||
|
83
plugins/ExtendedProfile/js/profiledetail.js
Normal file
83
plugins/ExtendedProfile/js/profiledetail.js
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
var removeRow = function() {
|
||||||
|
var cnt = rowCount(this);
|
||||||
|
var table = $(this).closest('table');
|
||||||
|
console.log("row count = " + cnt);
|
||||||
|
if (cnt > 1) {
|
||||||
|
var target = $(this).closest('tr');
|
||||||
|
target.remove();
|
||||||
|
reorder(table);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var rowCount = function(row) {
|
||||||
|
var top = $(row).closest('table');
|
||||||
|
var trs = $(top).find('tr');
|
||||||
|
return trs.length - 1; // exclude th section header row
|
||||||
|
};
|
||||||
|
|
||||||
|
var reorder = function(table) {
|
||||||
|
var trs = $(table).find('tr').has('td');
|
||||||
|
|
||||||
|
$(trs).find('a').hide();
|
||||||
|
|
||||||
|
$(trs).each(function(i, tr) {
|
||||||
|
console.log("ROW " + i);
|
||||||
|
$(tr).find('a.remove_row').show();
|
||||||
|
replaceIndex(rowIndex(tr), i);
|
||||||
|
});
|
||||||
|
|
||||||
|
$(trs).last().find('a.add_row').show();
|
||||||
|
|
||||||
|
if (trs.length == 1) {
|
||||||
|
$(trs).find('a.remove_row').hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
var rowIndex = function(elem) {
|
||||||
|
var idStr = $(elem).find('div').attr('id');
|
||||||
|
var id = idStr.match(/\d+/);
|
||||||
|
console.log("id = " + id);
|
||||||
|
};
|
||||||
|
|
||||||
|
var replaceIndex = function(elem, oldIndex, newIndex) {
|
||||||
|
$(elem).find('*').each(function() {
|
||||||
|
$.each(this.attributes, function(i, attrib) {
|
||||||
|
var regexp = /extprofile-.*-\d.*/;
|
||||||
|
var value = attrib.value;
|
||||||
|
var match = value.match(regexp);
|
||||||
|
if (match != null) {
|
||||||
|
attrib.value = value.replace("-" + oldIndex, "-" + newIndex);
|
||||||
|
console.log('match: oldIndex = ' + oldIndex + ' newIndex = ' + newIndex + ' name = ' + attrib.name + ' value = ' + attrib.value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var resetRow = function(elem) {
|
||||||
|
$(elem).find('input').attr('value', '');
|
||||||
|
$(elem).find("select option[value='office']").attr("selected", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
var addRow = function() {
|
||||||
|
var divId = $(this).closest('div').attr('id');
|
||||||
|
var index = divId.match(/\d+/);
|
||||||
|
console.log("Current row = " + index);
|
||||||
|
var tr = $(this).closest('tr');
|
||||||
|
var newtr = $(tr).clone();
|
||||||
|
var newIndex = parseInt(index) + 1;
|
||||||
|
replaceIndex(newtr, index, newIndex);
|
||||||
|
resetRow(newtr);
|
||||||
|
$(tr).after(newtr);
|
||||||
|
console.log("number of rows: " + rowCount(tr));
|
||||||
|
reorder($(this).closest('table'));
|
||||||
|
};
|
||||||
|
|
||||||
|
$(document).ready(
|
||||||
|
|
||||||
|
function() {
|
||||||
|
$('.add_row').live('click', addRow);
|
||||||
|
$('.remove_row').live('click', removeRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
);
|
@ -43,7 +43,13 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
|
|||||||
|
|
||||||
function showStylesheets() {
|
function showStylesheets() {
|
||||||
parent::showStylesheets();
|
parent::showStylesheets();
|
||||||
$this->cssLink('plugins/ExtendedProfile/profiledetail.css');
|
$this->cssLink('plugins/ExtendedProfile/css/profiledetail.css');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function showScripts() {
|
||||||
|
parent::showScripts();
|
||||||
|
$this->script('plugins/ExtendedProfile/js/profiledetail.js');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +139,7 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
|
|||||||
$phoneTuples = array();
|
$phoneTuples = array();
|
||||||
|
|
||||||
foreach($phones as $phone) {
|
foreach($phones as $phone) {
|
||||||
$firstkey = array_shift(array_keys($phone));
|
$firstkey = current(array_keys($phone));
|
||||||
$index = substr($firstkey, strrpos($firstkey, '-') + 1);
|
$index = substr($firstkey, strrpos($firstkey, '-') + 1);
|
||||||
list($number, $rel) = array_values($phone);
|
list($number, $rel) = array_values($phone);
|
||||||
|
|
||||||
@ -142,11 +148,9 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
|
|||||||
'index' => $index,
|
'index' => $index,
|
||||||
'rel' => $rel
|
'rel' => $rel
|
||||||
);
|
);
|
||||||
|
|
||||||
return $phoneTuples;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $phones;
|
return $phoneTuples;
|
||||||
}
|
}
|
||||||
|
|
||||||
function arraySplit($array, $pieces)
|
function arraySplit($array, $pieces)
|
||||||
@ -157,7 +161,7 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
|
|||||||
|
|
||||||
$newCount = ceil(count($array) / $pieces);
|
$newCount = ceil(count($array) / $pieces);
|
||||||
$a = array_slice($array, 0, $newCount);
|
$a = array_slice($array, 0, $newCount);
|
||||||
$b = array_split(array_slice($array, $newCount), $pieces - 1);
|
$b = $this->arraySplit(array_slice($array, $newCount), $pieces - 1);
|
||||||
|
|
||||||
return array_merge(array($a), $b);
|
return array_merge(array($a), $b);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user