fc77ee76d6
The primary license of the project is changing to: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later The Additional Permission is designed to permit publicly distributed Javascript code to be relicensed under LGPL-3.0-or-later, but not server-side Javascript code. As such, we've relicensed here static Javscript files under LGPL-3.0-or-later, and those that run as part of build and/or server side under AGPL-3.0-or-later. Note that in future, Javascript files may be updated to be stronger copyleft license with the Additional Permission, particularly if they adapted to run on server side and/or turned into templates. Of course, we'd seek public discussion with the contributor community about such changes. This commit is one of the many steps to relicense the entire codebase. Documentation granting permission for this relicensing (from all past contributors who hold copyrights) is on file with Software Freedom Conservancy, Inc.
124 lines
3.4 KiB
JavaScript
124 lines
3.4 KiB
JavaScript
// License: LGPL-3.0-or-later
|
|
var request = require('../../../common/client')
|
|
var action_recipient = require('./action_recipient')
|
|
var fields = require('./tags_and_fields_shared_methods')
|
|
var type = 'custom_field'
|
|
|
|
fields.index_masters(type)
|
|
|
|
appl.def('custom_fields.masters.show_modal', function(){
|
|
appl.open_modal('manageFieldMasterModal')
|
|
})
|
|
|
|
|
|
appl.def('custom_fields.masters.add', function(form_obj, node){
|
|
fields.add({ type: type, form_obj: form_obj, node: node })
|
|
})
|
|
|
|
|
|
appl.def('custom_fields.masters.delete', function(name, id, node) {
|
|
fields.delete({ name: name, id: id, type: type, node: node })
|
|
appl.ajax.index('supporter_details.custom_fields')
|
|
})
|
|
|
|
|
|
appl.def('custom_fields.bulk.show_modal', function(node) {
|
|
appl
|
|
.def('custom_fields.bulk.action_recipient', action_recipient())
|
|
.open_modal('editBulkCustomFieldsModal')
|
|
})
|
|
|
|
|
|
appl.def('custom_fields.bulk.toggle_remove', function(this_field, node) {
|
|
if (this_field.remove) this_field.remove = false;
|
|
else this_field.remove = true;
|
|
appl.def('custom_fields.masters.data', appl.custom_fields.masters.data)
|
|
})
|
|
|
|
|
|
appl.def('custom_fields.bulk.prepare_to_post', function(form_obj, node) {
|
|
var fields = []
|
|
|
|
for(var i = 1, len = form_obj.id.length; i < len; ++i) {
|
|
if(form_obj.remove[i] === 'true')
|
|
fields.push({custom_field_master_id: form_obj.id[i], value: ''})
|
|
else if(form_obj.val[i] === '')
|
|
{}
|
|
else
|
|
fields.push({custom_field_master_id: form_obj.id[i], value: form_obj.val[i]})
|
|
}
|
|
|
|
if(appl.supporters.selecting_all)
|
|
var post_data = {
|
|
custom_fields: fields,
|
|
selecting_all: true,
|
|
query: appl.supporters.query
|
|
}
|
|
else
|
|
var post_data = {
|
|
custom_fields: fields,
|
|
supporter_ids: appl.supporters.selected.map(function(s){return s.id})
|
|
}
|
|
|
|
post_custom_field_edits(post_data, function() {
|
|
appl
|
|
.notify('Successfully updated fields for ' + appl.custom_fields.bulk.action_recipient)
|
|
.uncheck_all_supporters()
|
|
})
|
|
appl.def('custom_fields.masters.data', appl.custom_fields.masters.data.map(function(s) {s.remove = false; return s}))
|
|
appl.prev_elem(node).reset()
|
|
})
|
|
|
|
|
|
|
|
appl.def('custom_fields.single.show_modal', function(name, id, node) {
|
|
var custom_field_list = []
|
|
|
|
appl.custom_fields.masters.data.forEach(function(custom_field_master) {
|
|
var new_custom_field = {
|
|
id: custom_field_master.id,
|
|
name: custom_field_master.name
|
|
}
|
|
appl.supporter_details.custom_fields.data.forEach(function(custom_field_join) {
|
|
if(custom_field_join.name === custom_field_master.name && custom_field_join.value)
|
|
new_custom_field.value = custom_field_join.value
|
|
})
|
|
custom_field_list.push(new_custom_field)
|
|
})
|
|
|
|
appl
|
|
.def('supporter_details.custom_field_list', custom_field_list)
|
|
.open_modal('editCustomFieldsModal')
|
|
})
|
|
|
|
|
|
|
|
appl.def('custom_fields.single.prepare_to_post', function(form_obj) {
|
|
var fields = []
|
|
for(var i = 1, len = form_obj.id.length; i < len; ++i) {
|
|
fields.push({custom_field_master_id: form_obj.id[i],value: form_obj.val[i]})
|
|
}
|
|
var post_data = {
|
|
custom_fields: fields,
|
|
supporter_ids: [appl.supporter_details.data.id]
|
|
}
|
|
|
|
post_custom_field_edits(post_data, function() {
|
|
appl
|
|
.notify('Successfully updated fields for ' + appl.supporter_details.data.name_email_or_id)
|
|
.ajax.index('supporter_details.custom_fields')
|
|
})
|
|
})
|
|
|
|
function post_custom_field_edits(post_data, callback){
|
|
appl.def('loading', true)
|
|
request
|
|
.post('custom_field_joins/modify', post_data)
|
|
.end(function(err, resp) {
|
|
appl
|
|
.close_modal()
|
|
.def('loading', false)
|
|
callback()
|
|
})
|
|
}
|
|
|