parent
73441bfea0
commit
5167f4fca8
@ -1,107 +0,0 @@ |
||||
// -- copyright
|
||||
// OpenProject is a project management system.
|
||||
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License version 3.
|
||||
//
|
||||
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||||
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
// Copyright (C) 2010-2013 the ChiliProject Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// See doc/COPYRIGHT.rdoc for more details.
|
||||
// ++
|
||||
|
||||
export class CostUnitSubformController { |
||||
|
||||
public objId:string; |
||||
public objName:string; |
||||
|
||||
constructor(public $element:ng.IAugmentedJQuery) { |
||||
this.objId = this.$element.attr('obj-id')!; |
||||
this.objName = this.$element.attr('obj-name')!; |
||||
|
||||
// Add new row handler
|
||||
$element.find('#' + this.objId).click(() => { |
||||
this.makeEditable('#' + this.objId, this.objName); |
||||
}); |
||||
} |
||||
|
||||
private getCurrencyValue(str:string) { |
||||
var result = str.match(/^\s*(([0-9]+[.,])+[0-9]+) (.+)\s*/); |
||||
return result ? new Array(result[1], result[3]) : new Array(str, ""); |
||||
} |
||||
|
||||
public makeEditable(id:string, name:string) { |
||||
var obj = jQuery(id); |
||||
this.edit_and_focus(obj, name); |
||||
} |
||||
|
||||
private edit_and_focus(obj:any, name:string) { |
||||
this.edit(obj, name); |
||||
|
||||
jQuery('#' + obj[0].id + '_edit').focus(); |
||||
jQuery('#' + obj[0].id + '_edit').select(); |
||||
} |
||||
|
||||
private edit(obj:any, name:string, obj_value?:any) { |
||||
obj.hide(); |
||||
|
||||
var obj_value = typeof (obj_value) != 'undefined' ? obj_value : obj[0].innerHTML; |
||||
var parsed = this.getCurrencyValue(obj_value); |
||||
var value = parsed[0]; |
||||
var currency = parsed[1]; |
||||
|
||||
var form_start = '<section class="form--section" id="' + obj[0].id + |
||||
'_section"><div class="form--field"><div class="form--field-container">'; |
||||
var button = '<div id="' + obj[0].id + |
||||
'_cancel" class="form--field-affix -transparent icon icon-close"></div>'; |
||||
var span = '<div id="' + obj[0].id + '_editor" class="form--text-field-container">'; |
||||
span += '<input id="' + obj[0].id + '_edit" class="form--text-field" name="' + name + '" value="' + value + '" class="currency" type="text" /> '; |
||||
span += '</div>'; |
||||
|
||||
var affix = '<div class="form--field-affix" id="' + obj[0].id + '_affix">' + |
||||
currency + |
||||
'</div>'; |
||||
var form_end = '</div></div></section>'; |
||||
|
||||
jQuery(form_start + button + span + affix + form_end).insertAfter(obj); |
||||
|
||||
var that = this; |
||||
jQuery('#' + obj[0].id + '_cancel').on('click', function() { |
||||
that.cleanUp(obj) |
||||
return false; |
||||
}); |
||||
} |
||||
|
||||
private cleanUp(obj:any) { |
||||
jQuery('#' + obj[0].id + '_section').remove(); |
||||
obj.show(); |
||||
} |
||||
} |
||||
|
||||
function costUnitSubform():any { |
||||
return { |
||||
restrict: 'E', |
||||
scope: {}, |
||||
bindToController: true, |
||||
controller: CostUnitSubformController, |
||||
controllerAs: '$ctrl' |
||||
}; |
||||
} |
||||
|
||||
angular.module('OpenProjectLegacy').directive('costUnitSubform', costUnitSubform); |
@ -1,99 +0,0 @@ |
||||
// -- copyright
|
||||
// OpenProject is a project management system.
|
||||
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License version 3.
|
||||
//
|
||||
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||||
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
// Copyright (C) 2010-2013 the ChiliProject Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// See doc/COPYRIGHT.rdoc for more details.
|
||||
// ++
|
||||
|
||||
export class CostSubformController { |
||||
|
||||
// Container for rows
|
||||
private container: ng.IAugmentedJQuery; |
||||
|
||||
// Template for new rows to insert, is rendered with INDEX placeholder
|
||||
private rowTemplate: string; |
||||
|
||||
// Current row index
|
||||
public rowIndex: number; |
||||
|
||||
// subform item count as output by rails
|
||||
public itemCount: string; |
||||
|
||||
constructor(public $element:ng.IAugmentedJQuery) { |
||||
this.container = $element.find('.subform-container'); |
||||
this.rowIndex = parseInt(this.$element.attr('item-count') as string); |
||||
|
||||
$element.on('click', '.delete-row-button,.delete-budget-item', (evt:JQueryEventObject) => { |
||||
var row = angular.element(evt.target).closest('.subform-row'); |
||||
row.remove(); |
||||
return false; |
||||
}); |
||||
|
||||
// Add new row handler
|
||||
$element.find('.add-row-button,.wp-inline-create--add-link').click((evt) => { |
||||
evt.preventDefault(); |
||||
this.addRow(); |
||||
return false; |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* Adds a new empty budget item row with the correct index set |
||||
*/ |
||||
public addRow() { |
||||
this.container.append(this.indexedTemplate); |
||||
this.rowIndex += 1; |
||||
|
||||
this.container.find('.costs-date-picker').datepicker(); |
||||
this.container.find('.subform-row:last-child input:first').focus(); |
||||
} |
||||
|
||||
/** |
||||
* Return the next possible new row from rowTemplate, |
||||
* with the index set to the current last value. |
||||
*/ |
||||
private get indexedTemplate() { |
||||
return this.rowTemplate.replace(/INDEX/g, this.rowIndex.toString()); |
||||
} |
||||
} |
||||
|
||||
function costsSubform():any { |
||||
return { |
||||
restrict: 'E', |
||||
scope: { itemCount: '@' }, |
||||
link: (scope:ng.IScope, |
||||
element:ng.IAugmentedJQuery, |
||||
attr:ng.IAttributes, |
||||
ctrl:any) => { |
||||
const template = element.find('.subform-row-template'); |
||||
ctrl.rowTemplate = template[0].outerHTML; |
||||
template.remove(); |
||||
}, |
||||
bindToController: true, |
||||
controller: CostSubformController, |
||||
controllerAs: '$ctrl' |
||||
}; |
||||
} |
||||
|
||||
angular.module('OpenProjectLegacy').directive('costsSubform', costsSubform); |
@ -0,0 +1,103 @@ |
||||
// -- copyright
|
||||
// OpenProject is a project management system.
|
||||
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License version 3.
|
||||
//
|
||||
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||||
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
// Copyright (C) 2010-2013 the ChiliProject Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// See doc/COPYRIGHT.rdoc for more details.
|
||||
// ++
|
||||
|
||||
import {Injectable} from "@angular/core"; |
||||
import {HttpClient} from '@angular/common/http'; |
||||
import {WorkPackageNotificationService} from "core-app/components/wp-edit/wp-notification.service"; |
||||
|
||||
@Injectable() |
||||
export class CostSubformAugmentService { |
||||
|
||||
constructor(private wpNotifications:WorkPackageNotificationService, |
||||
private http:HttpClient) { |
||||
jQuery('costs-budget-subform').each((i, match) => { |
||||
let el = jQuery(match); |
||||
|
||||
const container = el.find('.budget-item-container'); |
||||
const template:string = el.find('.budget-row-template')[0].outerHTML; |
||||
let rowIndex = parseInt(el.attr('item-count') as string); |
||||
|
||||
// Refresh row on changes
|
||||
el.on('change', '.budget-item-value', (evt) => { |
||||
let row = jQuery(evt.target).closest('.cost_entry'); |
||||
this.refreshRow(el, row.attr('id') as string); |
||||
}); |
||||
|
||||
el.on('click', '.delete-budget-item', (evt) => { |
||||
evt.preventDefault(); |
||||
jQuery(evt.target).closest('.cost_entry').remove(); |
||||
return false; |
||||
}); |
||||
|
||||
// Add new row handler
|
||||
el.find('.budget-add-row').click((evt) => { |
||||
evt.preventDefault(); |
||||
container.append(template.replace(/INDEX/g, rowIndex.toString())); |
||||
rowIndex += 1; |
||||
return false; |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* Refreshes the given row after updating values |
||||
*/ |
||||
public refreshRow(el:JQuery, row_identifier:string) { |
||||
let row = el.find('#' + row_identifier); |
||||
let request = this.buildRefreshRequest(row, row_identifier); |
||||
|
||||
this.http |
||||
.post(el.attr('update-url')!, request, { headers: { 'Accept': 'application/json' } }) |
||||
.subscribe( |
||||
(data:any) => { |
||||
_.each(data, (val:string, selector:string) => { |
||||
jQuery('#' + selector).html(val); |
||||
}); |
||||
}, |
||||
(error:any) => this.wpNotifications.handleRawError(error) |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* Returns the params for the update request |
||||
*/ |
||||
private buildRefreshRequest(row:JQuery, row_identifier:string) { |
||||
let request:any = { |
||||
element_id: row_identifier, |
||||
fixed_date: row.find('#cost_object_fixed_date').val() |
||||
}; |
||||
|
||||
// Augment common values with specific values for this type
|
||||
row.find('.budget-item-value').each((_i:number, el:any) => { |
||||
let field = jQuery(el); |
||||
request[field.data('requestKey')] = field.val() || '0'; |
||||
}); |
||||
|
||||
return request; |
||||
} |
||||
} |
@ -0,0 +1,62 @@ |
||||
// -- copyright
|
||||
// OpenProject is a project management system.
|
||||
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License version 3.
|
||||
//
|
||||
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||||
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
// Copyright (C) 2010-2013 the ChiliProject Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// See doc/COPYRIGHT.rdoc for more details.
|
||||
// ++
|
||||
|
||||
import {Injectable} from "@angular/core"; |
||||
|
||||
@Injectable() |
||||
export class CostSubformAugmentService { |
||||
|
||||
constructor() { |
||||
jQuery('costs-subform').each((i, match) => { |
||||
let el = jQuery(match); |
||||
|
||||
const container = el.find('.subform-container'); |
||||
const template = el.find('.subform-row-template')[0].outerHTML; |
||||
let rowIndex = parseInt(el.attr('item-count')!); |
||||
|
||||
el.on('click', '.delete-row-button,.delete-budget-item', (evt:any) => { |
||||
jQuery(evt.target).closest('.subform-row').remove(); |
||||
return false; |
||||
}); |
||||
|
||||
// Add new row handler
|
||||
el.find('.add-row-button,.wp-inline-create--add-link').click((evt:any) => { |
||||
evt.preventDefault(); |
||||
container.append(template.replace(/INDEX/g, rowIndex.toString())); |
||||
rowIndex += 1; |
||||
|
||||
container.find('.costs-date-picker').datepicker(); |
||||
container.find('.subform-row:last-child input:first').focus(); |
||||
|
||||
return false; |
||||
}); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
|
@ -0,0 +1,101 @@ |
||||
// -- copyright
|
||||
// OpenProject is a project management system.
|
||||
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License version 3.
|
||||
//
|
||||
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||||
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
// Copyright (C) 2010-2013 the ChiliProject Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// See doc/COPYRIGHT.rdoc for more details.
|
||||
// ++
|
||||
|
||||
export class PlannedCostsFormAugment { |
||||
|
||||
public obj:JQuery; |
||||
public objId:string; |
||||
public objName:string; |
||||
|
||||
static listen() { |
||||
jQuery(document).on('click', '.costs--edit-planned-costs-btn', (evt) => { |
||||
const form = jQuery(evt.target).closest('cost-unit-subform'); |
||||
new PlannedCostsFormAugment(form); |
||||
}); |
||||
} |
||||
|
||||
constructor(public $element:JQuery) { |
||||
this.objId = this.$element.attr('obj-id')!; |
||||
this.objName = this.$element.attr('obj-name')!; |
||||
this.obj = jQuery(this.objId); |
||||
|
||||
this.makeEditable('#' + this.objId, this.objName); |
||||
} |
||||
|
||||
private getCurrencyValue(str:string) { |
||||
var result = str.match(/^\s*(([0-9]+[.,])+[0-9]+) (.+)\s*/); |
||||
return result ? new Array(result[1], result[3]) : new Array(str, ""); |
||||
} |
||||
|
||||
public makeEditable(id:string, name:string) { |
||||
this.edit_and_focus(); |
||||
} |
||||
|
||||
private edit_and_focus() { |
||||
this.edit(); |
||||
|
||||
jQuery('#' + this.objId + '_edit').trigger('focus'); |
||||
jQuery('#' + this.objId + '_edit').trigger('select'); |
||||
} |
||||
|
||||
private edit() { |
||||
this.obj.hide(); |
||||
|
||||
let obj_value = this.obj[0].innerHTML; |
||||
let id = this.obj[0].id; |
||||
let parsed = this.getCurrencyValue(obj_value); |
||||
let value = parsed[0]; |
||||
let currency = parsed[1]; |
||||
let name = this.objName; |
||||
|
||||
let template = ` |
||||
<section class="form--section" id="${id}_section"> |
||||
<div class="form--field"> |
||||
<div class="form--field-container"> |
||||
<div id="${id}_cancel" class="form--field-affix -transparent icon icon-close"></div>'; |
||||
<div id="${id}_editor" class="form--text-field-container"> |
||||
<input id="${id}_edit" class="form--text-field" name="${name}" value="${value}" class="currency" type="text" /> |
||||
</div> |
||||
<div class="form--field-affix" id="${id}_affix">${currency}</div> |
||||
</div> |
||||
</div> |
||||
</section> |
||||
`;
|
||||
|
||||
|
||||
jQuery(template).insertAfter(this.obj); |
||||
|
||||
let that = this; |
||||
jQuery('#' + id + '_cancel').on('click', function () { |
||||
jQuery('#' + id + '_section').remove(); |
||||
that.obj.show(); |
||||
return false; |
||||
}); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue