// -- 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 as any).closest('cost-unit-subform') as JQuery; 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}`) as any; 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 = `
${currency}
`; jQuery(template).insertAfter(this.obj); let that = this; jQuery('#' + id + '_cancel').on('click', function () { jQuery('#' + id + '_section').remove(); that.obj.show(); return false; }); } }