2016-09-05 07:10:39 +02:00
|
|
|
<script type="text/javascript">
|
2016-09-02 16:53:16 +02:00
|
|
|
|
2016-09-05 07:10:39 +02:00
|
|
|
function ViewModel(data) {
|
|
|
|
var self = this;
|
2016-09-02 16:53:16 +02:00
|
|
|
|
2016-09-05 07:10:39 +02:00
|
|
|
self.invoice_fields = ko.observableArray();
|
|
|
|
self.client_fields = ko.observableArray();
|
2016-09-05 14:28:59 +02:00
|
|
|
self.account_fields1 = ko.observableArray();
|
|
|
|
self.account_fields2 = ko.observableArray();
|
2016-09-05 07:10:39 +02:00
|
|
|
window.field_map = [];
|
|
|
|
|
|
|
|
self.addField = function(section, field, label) {
|
2016-09-05 14:28:59 +02:00
|
|
|
if (self[section].indexOf(field) < 0) {
|
|
|
|
self[section].push(field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.resetFields = function() {
|
|
|
|
console.log('herey');
|
|
|
|
self.invoice_fields.removeAll();
|
|
|
|
self.client_fields.removeAll();
|
|
|
|
self.account_fields1.removeAll();
|
|
|
|
self.account_fields2.removeAll();
|
|
|
|
}
|
|
|
|
|
2016-09-05 16:44:01 +02:00
|
|
|
self.onChange = function() {
|
2016-09-05 14:28:59 +02:00
|
|
|
refreshPDF();
|
2016-09-05 16:44:01 +02:00
|
|
|
NINJA.formIsChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.onDragged = function() {
|
|
|
|
self.onChange();
|
2016-09-05 07:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
self.removeInvoiceFields = function(item) {
|
|
|
|
self.invoice_fields.remove(item);
|
2016-09-05 16:44:01 +02:00
|
|
|
self.onChange();
|
2016-09-05 07:10:39 +02:00
|
|
|
}
|
|
|
|
self.removeClientFields = function(item) {
|
|
|
|
self.client_fields.remove(item);
|
2016-09-05 16:44:01 +02:00
|
|
|
self.onChange();
|
2016-09-05 07:10:39 +02:00
|
|
|
}
|
2016-09-05 14:28:59 +02:00
|
|
|
self.removeAccountFields1 = function(item) {
|
|
|
|
self.account_fields1.remove(item);
|
2016-09-05 16:44:01 +02:00
|
|
|
self.onChange();
|
2016-09-05 07:10:39 +02:00
|
|
|
}
|
2016-09-05 14:28:59 +02:00
|
|
|
self.removeAccountFields2 = function(item) {
|
|
|
|
self.account_fields2.remove(item);
|
2016-09-05 16:44:01 +02:00
|
|
|
self.onChange();
|
2016-09-05 07:10:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addField(section) {
|
|
|
|
var $select = $('#' + section + '_select');
|
|
|
|
var field = $select.val();
|
|
|
|
var label = $select.find('option:selected').text();
|
|
|
|
window.model.addField(section, field, label);
|
|
|
|
$select.val(null).blur();
|
|
|
|
}
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
window.model = new ViewModel();
|
|
|
|
|
|
|
|
var selectedFields = {!! json_encode($account->getInvoiceFields()) !!};
|
2016-09-05 14:28:59 +02:00
|
|
|
var allFields = {!! json_encode($account->getAllInvoiceFields()) !!};
|
|
|
|
|
|
|
|
loadFields(selectedFields);
|
|
|
|
loadMap(allFields);
|
|
|
|
|
|
|
|
ko.applyBindings(model);
|
|
|
|
})
|
|
|
|
|
|
|
|
function resetFields() {
|
|
|
|
var defaultFields = {!! json_encode($account->getDefaultInvoiceFields()) !!};
|
|
|
|
window.model.resetFields();
|
|
|
|
loadFields(defaultFields);
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadMap(allFields) {
|
|
|
|
for (var section in allFields) {
|
|
|
|
if ( ! allFields.hasOwnProperty(section)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
var fields = allFields[section];
|
|
|
|
for (var field in fields) {
|
|
|
|
if ( ! fields.hasOwnProperty(field)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
var label = fields[field];
|
|
|
|
window.field_map[field] = label;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadFields(selectedFields)
|
|
|
|
{
|
2016-09-05 07:10:39 +02:00
|
|
|
for (var section in selectedFields) {
|
|
|
|
if ( ! selectedFields.hasOwnProperty(section)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
var fields = selectedFields[section];
|
|
|
|
for (var field in fields) {
|
|
|
|
if ( ! fields.hasOwnProperty(field)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
var label = fields[field];
|
|
|
|
model.addField(section, field, label);
|
|
|
|
}
|
|
|
|
}
|
2016-09-05 14:28:59 +02:00
|
|
|
}
|
2016-09-05 07:10:39 +02:00
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style type="text/css">
|
|
|
|
.field-list {
|
|
|
|
width: 100%;
|
|
|
|
margin-top: 12px;
|
|
|
|
}
|
|
|
|
.field-list tr {
|
|
|
|
width: 100%;
|
|
|
|
cursor: pointer;
|
|
|
|
border-bottom: solid 1px #CCC;
|
|
|
|
}
|
|
|
|
|
|
|
|
.field-list td {
|
|
|
|
width: 100%;
|
|
|
|
background-color: white;
|
|
|
|
padding-top: 10px;
|
|
|
|
padding-bottom: 10px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.field-list td i {
|
|
|
|
float: left;
|
|
|
|
width: 18px;
|
|
|
|
padding-top: 2px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.field-list td div {
|
|
|
|
float: left;
|
2016-09-05 14:28:59 +02:00
|
|
|
xwidth: 146px;
|
|
|
|
width: 100%;
|
2016-09-05 07:10:39 +02:00
|
|
|
overflow: hidden;
|
|
|
|
white-space: nowrap;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
}
|
|
|
|
|
|
|
|
.field-list tr:hover .fa {
|
|
|
|
visibility: visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
.field-list tr:hover div {
|
|
|
|
width: 120px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.field-list .fa {
|
|
|
|
visibility: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
.field-list .fa-close {
|
|
|
|
color: red;
|
|
|
|
}
|
|
|
|
|
|
|
|
.field-list .fa-bars {
|
|
|
|
position: absolute;
|
|
|
|
right: 20px;
|
|
|
|
color: #AAA;
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|