$this->out->text($this->ext->getTags());
break;
case 'phone':
- $this->showPhone($field);
+ $this->showPhone($name, $field);
break;
default:
$this->out->text("TYPE: $type");
}
}
- protected function showPhone($field)
+ protected function showPhone($name, $field)
{
$this->out->elementStart('div', array('class' => 'phone-display'));
$this->out->text($field['value']);
protected function showEditablePhone($name, $field)
{
- $index = $field['index'];
+ $index = isset($field['index']) ? $field['index'] : 0;
$id = "extprofile-$name-$index";
$rel = $id . '-rel';
$this->out->elementStart(
'class' => 'phone-edit'
)
);
- $this->out->input($id, null, $field['value']);
+ $this->out->input(
+ $id,
+ null,
+ isset($field['value']) ? $field['value'] : null
+ );
$this->out->dropdown(
$id . '-rel',
'Type',
),
null,
false,
- $field['rel']
+ isset($field['rel']) ? $field['rel'] : null
);
- if ($field['multi']) {
- $this->out->element(
- 'a',
- array(
- 'class' => 'add_row',
- 'href' => 'javascript://'),
- '+'
- );
- $this->out->element(
- 'a',
- array(
- 'class' => 'remove_row',
- 'href' => 'javascript://',
- 'style' => 'display: none; '
- ),
- '-'
- );
- }
+
+ $this->out->element(
+ 'a',
+ array(
+ 'class' => 'add_row',
+ 'href' => 'javascript://',
+ 'style' => 'display: none; '
+ ),
+ '+'
+ );
+
+ $this->out->element(
+ 'a',
+ array(
+ 'class' => 'remove_row',
+ 'href' => 'javascript://',
+ 'style' => 'display: none; '
+ ),
+ '-'
+ );
+
$this->out->elementEnd('div');
}
-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(class) {
+ console.log("QQQ Enter reorder");
-var reorder = function(table) {
- var trs = $(table).find('tr').has('td');
+ var divs = $.find('div[class=' + class + ']');
+ console.log('divs length = ' + divs.length);
- $(trs).find('a').hide();
+ $(divs).find('a').hide();
- $(trs).each(function(i, tr) {
+ $(divs).each(function(i, div) {
console.log("ROW " + i);
- $(tr).find('a.remove_row').show();
- replaceIndex(rowIndex(tr), i);
+ $(div).find('a.remove_row').show();
+ replaceIndex(rowIndex(div), i);
});
- $(trs).last().find('a.add_row').show();
+ $(divs).last().find('a.add_row').show();
- if (trs.length == 1) {
- $(trs).find('a.remove_row').hide();
+ if (divs.length == 1) {
+ $(divs).find('a.remove_row').hide();
}
};
-var rowIndex = function(elem) {
- var idStr = $(elem).find('div').attr('id');
- var id = idStr.match(/\d+/);
+var rowIndex = function(div) {
+ var idstr = $(div).attr('id');
+ var id = idstr.match(/\d+/);
console.log("id = " + id);
+ return id;
+};
+
+var rowCount = function(class) {
+ var divs = $.find('div[class=' + class + ']');
+ return divs.length;
};
var replaceIndex = function(elem, oldIndex, newIndex) {
var regexp = /extprofile-.*-\d.*/;
var value = attrib.value;
var match = value.match(regexp);
- if (match != null) {
+ if (match !== null) {
attrib.value = value.replace("-" + oldIndex, "-" + newIndex);
console.log('match: oldIndex = ' + oldIndex + ' newIndex = ' + newIndex + ' name = ' + attrib.name + ' value = ' + attrib.value);
}
}
var addRow = function() {
- var divId = $(this).closest('div').attr('id');
- var index = divId.match(/\d+/);
- console.log("Current row = " + index);
+ var div = $(this).closest('div');
+ var id = $(div).attr('id');
+ var class = $(div).attr('class');
+ var index = id.match(/\d+/);
+ console.log("Current row = " + index + ', class = ' + class);
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'));
+ reorder(class);
};
+var removeRow = function() {
+ var div = $(this).closest('div');
+ var id = $(div).attr('id');
+ var class = $(div).attr('class');
+
+ cnt = rowCount(class);
+ console.debug("removeRow - cnt = " + cnt);
+ if (cnt > 1) {
+ var target = $(this).closest('tr');
+ target.remove();
+ reorder(class);
+ }
+};
+
+var init = function() {
+ reorder('phone-edit');
+}
+
$(document).ready(
function() {
+ init();
$('.add_row').live('click', addRow);
$('.remove_row').live('click', removeRow);
}
foreach ($simpleFieldNames as $name) {
$value = $this->trimmed('extprofile-' . $name);
- $this->saveField($user, $name, $value);
+ if (!empty($value)) {
+ $this->saveField($user, $name, $value);
+ }
}
$this->savePhoneNumbers($user);
function savePhoneNumbers($user) {
$phones = $this->findPhoneNumbers();
-
- foreach ($phones as $phone) {
- $this->saveField(
- $user,
- 'phone',
- $phone['value'],
- $phone['rel'],
- $phone['index']
- );
+ $this->removeAll($user, 'phone');
+ $i = 0;
+ foreach($phones as $phone) {
+ if (!empty($phone['value'])) {
+ ++$i;
+ $this->saveField(
+ $user,
+ 'phone',
+ $phone['value'],
+ $phone['rel'],
+ $i
+ );
+ }
}
}
$detail->free();
}
+ function removeAll($user, $name)
+ {
+ $profile = $user->getProfile();
+ $detail = new Profile_detail();
+ $detail->profile_id = $profile->id;
+ $detail->field_name = $name;
+ $detail->delete();
+ $detail->free();
+ }
+
/**
* Save fields that should be stored in the main profile object
*