Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrg2001 committed May 8, 2019
1 parent a7a8f2f commit 5f7e598
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 55 deletions.
138 changes: 115 additions & 23 deletions dist/w2ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3731,7 +3731,7 @@ w2utils.event = {
info : null // info bubble, can be bool/object
},

msgDelete : 'Are you sure you want to delete selected records?',
msgDelete : 'Are you sure you want to delete NN records?',
msgNotJSON : 'Returned data is not in valid JSON format.',
msgAJAXerror : 'AJAX error. See console for more details.',
msgRefresh : 'Refreshing...',
Expand Down Expand Up @@ -5706,8 +5706,6 @@ w2utils.event = {
if (!w2utils.isInt(this.last.xhr_offset)) this.last.xhr_offset = 0;
// add list params
var params = {
cmd : cmd,
selected : this.getSelection(),
limit : this.limit,
offset : parseInt(this.offset) + parseInt(this.last.xhr_offset),
searchLogic : this.last.logic,
Expand Down Expand Up @@ -6491,9 +6489,11 @@ w2utils.event = {
if (recs.length === 0) return;
if (this.msgDelete != '' && !force) {
this.message({
width : 350,
width : 380,
height : 170,
body : '<div class="w2ui-centered">' + w2utils.lang(obj.msgDelete) + '</div>',
body : '<div class="w2ui-centered">' +
w2utils.lang(obj.msgDelete).replace('NN', recs.length).replace('records', (recs.length == 1 ? 'record' : 'records')) +
'</div>',
buttons : (w2utils.settings.macButtonOrder
? '<button type="button" class="w2ui-btn btn-default" onclick="w2ui[\''+ this.name +'\'].message()">' + w2utils.lang('Cancel') + '</button>' +
'<button type="button" class="w2ui-btn" onclick="w2ui[\''+ this.name +'\'].delete(true)">' + w2utils.lang('Delete') + '</button>'
Expand Down Expand Up @@ -19212,6 +19212,11 @@ var w2prompt = function (label, title, callBack) {
})
}
}
if (fld.type == 'map') {
var tmp = { nestedFields: true, record: data };
var val = this.getValue.call(tmp, fld.field);
if (val._order) delete val._order
}
}.bind(this))
return data;
},
Expand Down Expand Up @@ -19681,6 +19686,7 @@ var w2prompt = function (label, title, callBack) {
input = '<input id="'+ field.field +'" name="'+ field.field +'" type="checkbox" '+ field.html.attr + tabindex_str + ' class="w2ui-input w2ui-toggle"/><div><div></div></div>';
break;
case 'map':
case 'array':
field.html.key = field.html.key || {};
field.html.value = field.html.value || {};
input = '<input id="'+ field.field +'" name="'+ field.field +'" type="hidden" '+ field.html.attr + tabindex_str + '>'+
Expand Down Expand Up @@ -20140,8 +20146,18 @@ var w2prompt = function (label, title, callBack) {
$(field.el).val(value);
break;
case 'map':
case 'array':
// init map
if (field.type == 'map' && (value == null || !$.isPlainObject(value))) {
this.setValue(field.field, {})
value = this.getValue(field.field)
}
if (field.type == 'array' && (value == null || !Array.isArray(value))) {
this.setValue(field.field, [])
value = this.getValue(field.field)
}
// need closure
(function (field) {
(function (obj, field) {
field.el.mapAdd = function (field, div, cnt) {
var html = '<div class="w2ui-map-field" style="margin-bottom: 5px">'+
'<input id="'+ field.field +'_key_'+ cnt +'" data-cnt="'+ cnt +'" type="text" '+ field.html.key.attr +' class="w2ui-input w2ui-map key"/>'+
Expand All @@ -20154,40 +20170,116 @@ var w2prompt = function (label, title, callBack) {
field.el.mapRefresh = function (map, div) {
// generate options
var cnt = 1;
Object.keys(map).forEach(function (item) {
var names;
if (field.type == 'map') {
if (!$.isPlainObject(map)) map = {}
if (map._order == null) map._order = Object.keys(map)
names = map._order
}
if (field.type == 'array') {
if (!Array.isArray(map)) map = []
names = map.map(function (item) { return item.key })
}
names.forEach(function (item) {
var $k = div.find('#' + field.name + '_key_' + cnt)
var $v = div.find('#' + field.name + '_value_' + cnt)
if ($k.length == 0 || $v.length == 0) {
field.el.mapAdd(field, div, cnt)
$k = div.find('#' + field.name + '_key_' + cnt)
$v = div.find('#' + field.name + '_value_' + cnt)
}
var val = map[item];
if (field.type == 'array') {
var tmp = map.filter(function(it) { return it.key == item ? true : false})
if (tmp.length > 0) val = tmp[0].value
}
$k.val(item)
$v.val(map[item])
$k.parent().attr('data-key', item)
$v.val(val)
$k.parents('.w2ui-map-field').attr('data-key', item)
cnt++
})
field.el.mapAdd(field, div, cnt);
var curr = div.find('#' + field.name + '_key_' + cnt).parent()
var next = div.find('#' + field.name + '_key_' + (cnt + 1)).parent()
if (curr.length == 0) {
field.el.mapAdd(field, div, cnt);
}
if (curr.length == 1 && next.length == 1) {
curr.removeAttr('data-key')
curr.find('.key').val(next.find('.key').val());
curr.find('.value').val(next.find('.value').val());
next.remove()
}
// attach events
$(field.el).next().find('input.w2ui-map')
.off('.mapChange')
.on('input.mapChange', function (event) {
var $cont = $(event.target).parents('.w2ui-field')
var $input = $cont.find('input')
var old_key = $(event.target).parents('.w2ui-map-field').attr('data-key')
var key = $(event.target).parents('.w2ui-map-field').find('.key').val()
var value = $(event.target).parents('.w2ui-map-field').find('.value').val()
delete map[old_key];
map[key] = value;
console.log('change', map);
})
.on('blur.mapChange', function () {
console.log('blue')
.on('change.mapChange', function () {
var $div = $(event.target).parents('.w2ui-map-field')
var old = $div.attr('data-key')
var key = $div.find('.key').val()
var value = $div.find('.value').val()
// event before
var value_new = {}
var value_previous = {}
var aMap = null
var aIndex = null
value_new[key] = value
if (field.type == 'array') {
map.forEach(function (it, ind) {
if (it.key == old) aIndex = ind
})
aMap = map[aIndex]
}
if (old != null && field.type == 'map') {
value_previous[old] = map[old]
}
if (old != null && field.type == 'array') {
value_previous[old] = aMap.value
}
var edata = obj.trigger({ phase: 'before', target: field.field, type: 'change', originalEvent: event, value_new: value_new, value_previous: value_previous })
if (edata.isCancelled === true) {
return;
}
if (field.type == 'map') {
delete map[old];
var ind = map._order.indexOf(old)
if (key != '') {
if (map[key] != null) {
var newKey, more = 0
do { more++; newKey = key + more } while (map[newKey] != null)
key = newKey
$div.find('.key').val(newKey)
}
map[key] = value;
$div.attr('data-key', key)
if (ind != -1) {
map._order[ind] = key
} else {
map._order.push(key)
}
} else {
map._order.splice(ind, 1)
$div.find('.value').val('')
}
} else if (field.type == 'array') {
if (key != '') {
if (aMap == null) {
map.push({ key: key, value: value })
} else {
aMap.key = key
aMap.value = value
}
} else {
map.splice(aInd, 1)
}
}
obj.setValue(field.field, map)
field.el.mapRefresh(map, div)
// event after
obj.trigger($.extend(edata, { phase: 'after' }));
})
}
field.el.mapRefresh(value, $(field.el).parent().find('.w2ui-map-container'))
})(field)
})(this, field)
break;
case 'radio':
$(field.$el).prop('checked', false).each(function (index, el) {
Expand Down
10 changes: 5 additions & 5 deletions dist/w2ui.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 5f7e598

Please sign in to comment.