1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 08:02:40 +01:00
invoiceninja/resources/views/accounts/partials/invoice_fields.blade.php

226 lines
5.6 KiB
PHP
Raw Normal View History

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();
2017-10-27 10:46:08 +02:00
self.product_fields = ko.observableArray();
self.task_fields = 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);
}
}
2017-10-29 09:02:17 +01:00
self.resetInvoiceFields = function() {
2016-09-05 14:28:59 +02:00
self.invoice_fields.removeAll();
self.client_fields.removeAll();
self.account_fields1.removeAll();
self.account_fields2.removeAll();
2017-10-29 09:02:17 +01:00
}
self.resetProductFields = function() {
2017-10-27 10:46:08 +02:00
self.product_fields.removeAll();
self.task_fields.removeAll();
2016-09-05 14:28:59 +02:00
}
2016-09-05 16:44:01 +02:00
self.onChange = function() {
self.updateSelects();
2016-09-05 14:28:59 +02:00
refreshPDF();
2016-09-05 16:44:01 +02:00
NINJA.formIsChanged = true;
}
self.updateSelects = function() {
2017-10-27 10:46:08 +02:00
var usedFields = [].concat(
self.invoice_fields(),
self.client_fields(),
self.account_fields1(),
self.account_fields2());
var selects = [
'invoice_fields',
'client_fields',
'account_fields1',
'account_fields2',
2017-10-27 10:46:08 +02:00
'product_fields',
'task_fields',
];
for (var i=0; i<selects.length; i++) {
var select = selects[i];
$('#' + select + '_select > option').each(function() {
2017-10-27 10:46:08 +02:00
if (select == 'product_fields') {
usedFields = self.product_fields();
} else if (select == 'task_fields') {
usedFields = self.task_fields();
}
var isUsed = usedFields.indexOf(this.value) >= 0;
$(this).css('color', isUsed ? '#888' : 'black');
});
}
}
2016-09-05 16:44:01 +02:00
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
}
2017-10-27 10:46:08 +02:00
self.removeProductFields = function(item) {
self.product_fields.remove(item);
self.onChange();
}
self.removeTaskFields = function(item) {
self.task_fields.remove(item);
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);
window.model.onChange();
2016-09-05 07:10:39 +02:00
$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);
model.updateSelects();
2016-09-05 14:28:59 +02:00
ko.applyBindings(model);
})
2017-10-29 09:02:17 +01:00
function resetInvoiceFields() {
var defaultFields = {!! json_encode($account->getDefaultInvoiceFields()) !!};
window.model.resetInvoiceFields();
loadFields(defaultFields, 'invoice');
window.model.onChange();
}
function resetProductFields() {
2016-09-05 14:28:59 +02:00
var defaultFields = {!! json_encode($account->getDefaultInvoiceFields()) !!};
2017-10-29 09:02:17 +01:00
window.model.resetProductFields();
loadFields(defaultFields, 'product');
2016-12-05 20:50:13 +01:00
window.model.onChange();
2016-09-05 14:28:59 +02:00
}
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;
}
}
}
2017-10-29 09:02:17 +01:00
function loadFields(selectedFields, filter) {
2016-09-05 07:10:39 +02:00
for (var section in selectedFields) {
if ( ! selectedFields.hasOwnProperty(section)) {
continue;
}
2017-10-29 09:02:17 +01:00
if (filter == 'invoice' && (section == 'product_fields' || section == 'task_fields')) {
continue;
} else if (filter == 'product' && (section != 'product_fields' && section != 'task_fields')) {
continue;
}
2016-09-05 07:10:39 +02:00
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">
2016-09-05 07:10:39 +02:00
.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;
}
</style>