<commit_before>define('tempo30/view/antragEditView', [
    'jquery',
    'tempo30/model/version',
    'tempo30/view/fehler_melden_dialog',
    'tempo30/view/fehler_aufgetaucht_dialog',
    'gettext!tempo30',
    'tempo30/model/antragEditLayout',
    //
    'bootstrap',
    'css!lib/bootstrap-datepicker/bootstrap-datepicker3'
], function ($, version, errorMsgDialog, errorOccDialog, gt, layout) {

    'use strtict';

    var viewElements= {
        'button': function (element) {
            return $('<button type="submit" class="btn btn-primary">Speichern</button>');
        },
        'checkbox': function (element) {
            return $('<div class="checkbox">').append(
                $('<label>')
                    .text(element.label)
                    .prepend($('<input type="checkbox">').prop('id', element.id))

            );
        },
        'datepicker': function (element) {
            var input=$('<input type="text" class="form-control">');
            input.datepicker({
                language: "de",
                format: "dd.mm.yyyy",
                todayBtn: "linked",
                orientation: "left"
            });
            return $('<div class="form-group">').attr('for',element.id)
                .append($('<label>').attr('for',element.id).text(element.label))
                .append(input);
            
        },
        'text': function (element) {
            return $('<div class="form-group">').attr('for',element.id)
                .append($('<label>').attr('for',element.id).text(element.label))
                .append($('<input type="text" class="form-control">').prop('id',element.id));
        },
        'select': function (element) {
            var div=$('<div class="form-group">').attr('for',element.id);
            var selectDiv= $('<select class="form-control">').prop('id',element.id);
            $.each(element.options, function (index,option) {
                selectDiv.append($('<option>').prop('value', option.id).text(option.text));
            });

            div.append($('<label>').attr('for',element.id).text(element.label))
                .append(selectDiv);
            return div;
        }
    };
    function appendElements(sectionDiv, elements) {
        $.each(elements, function (index, element) {
            sectionDiv.append(viewElements[element.type](element));
        });
    }

    function hideIfInArray(div, statusVal, array, id) {
        var ele=div.find('.form-group[for='+id+']');
        var found=false;
        $.each(array, function (idx, ele) {
            if (ele===statusVal) {
                found = true;
            }
        });
        if (found)  {
            ele.hide();
        } else {
            ele.show();
        }
    }
    function getView() {
        var div = $('<div>');
        function appendSection(idx,section) {
            var sectionDiv=$('<div class="section">').prop('id','section_'+section.id).attr('idx',idx);
            div.append($('<h3>').text(section.headline));
            appendElements(sectionDiv, section.elements);
            div.append(sectionDiv);
        }
        $.each(layout, appendSection);

        function enableDisableBoxes() {
            var statusVal=div.find('#status').val();
            var arr=['vorbereitung', 'doch_nicht'];
            hideIfInArray(div, statusVal, arr, 'antragEingang');
            hideIfInArray(div, statusVal, arr, 'kostenBezahlt');
            hideIfInArray(div, statusVal, arr, 'kostenErwartet');
            arr.push('abgeschickt');
            hideIfInArray(div, statusVal, arr, 'antwortAufAntragEingang');
            arr.push('antrag-positiv');
            arr.push('antrag-negativ');
            hideIfInArray(div, statusVal, arr, 'widerspruchEingang');
            arr.push('widerspruch');
            hideIfInArray(div, statusVal, arr, 'widerspruchAntwort');
            arr.push('widerspruch-positiv');
            arr.push('widerspruch-abgelehnt');
            hideIfInArray(div, statusVal, arr, 'klageDatum');
            arr.push('klage');
            hideIfInArray(div, statusVal, arr, 'urteilDatum');
        }
        div.find('#status').change(enableDisableBoxes);
        enableDisableBoxes();
        
        return div;
    }

    return getView;

});<commit_msg>New Function: Update Data<commit_after>define('tempo30/view/antragEditView', [
    'jquery',
    'moment',
    'tempo30/model/version',
    'tempo30/view/fehler_melden_dialog',
    'tempo30/view/fehler_aufgetaucht_dialog',
    'gettext!tempo30',
    'tempo30/model/antragEditLayout',
    //
    'bootstrap',
    'css!lib/bootstrap-datepicker/bootstrap-datepicker3'
], function ($, moment, version, errorMsgDialog, errorOccDialog, gt, layout) {

    'use strtict';

    var saveElements = {
      'datepicker': function (element, section) {
        if (! $("input#"+element.id).is(':visible')) {
          return null;
        }
         var value=$("input#"+element.id).val();
         if (value === '') {
           return null;
         }
         var dateFromatRegEx=/^(\d\d)\.(\d\d)\.(\d\d\d\d)$/;
         if (value) {
           value=value.replace(dateFromatRegEx,'$3-$2-$1');
         }
         return value;
      },
      'checkbox': function (element, section) {
        if (! $("input#"+element.id).is(':visible')) {
          return null;
        }
        return $("input#"+element.id).prop('checked');

      },
      'radio': function (element, section) {
        if (! $("input[name='"+element.id+"']").is(':visible')) {
          return null;
        }
        return $("input[name='"+element.id+"']:checked").val();
      }
    }
    var viewElements= {
        'button': function (element) {
          if (element.subtype=== 'save') {
            var btn=$('<button type="submit" class="btn btn-primary">')
            .text('Speichern')
            btn.click(function () {
              btn.addClass('disabled');
              var data = {};
              var sectionDiv=btn.closest('div.section');
              var container = btn.closest('div.container-fluid');
              $.each(layout, function (index, section) {
                if ('section_'+section.id === sectionDiv.attr('id')) {
                  $.each(section.elements, function (index, element) {
                    var saveFunc=saveElements[element.type];
                    if (typeof(saveFunc) === 'function') {
                      data[element.id] = saveFunc(element, sectionDiv);
                    }
                  });
                }
              });
              container.trigger(element.trigger, data);
              btn.removeClass('disabled');
            });
            return $('<div class="form-group col-sm-12">').append(btn);
          }
          if (element.subtype=== 'delete') {
            return $('<button type="submit" class="btn btn-danger">Meine Daten löschen</button>');
          }
        },
        'checkbox': function (element, value) {
            var c=false;
            if ((value === true) || (value === 't')) {
              c=true;
            }
            var ipt=$('<input type="checkbox">')
              .prop('id', element.id)
              .prop('checked', c);
            if (element.readonly === true) {
              ipt.prop('readonly', true);
              ipt.prop('disabled', true);
            }
            return $('<div class="form-group col-sm-6">').attr('for',element.id).append(
             $('<div class="checkbox">').append(
                $('<label>')
                    .text(element.label)
                    .prepend(ipt))

            );
        },
        'datepicker': function (element, value) {
            var dateFromatRegEx=/^(\d\d\d\d)\-(\d\d)\-(\d\d)$/;
            if (value) {
              value=value.replace(dateFromatRegEx,'$3.$2.$1');
            }
            var input=$('<input type="text" class="form-control">')
            .prop('id', element.id)
            .prop('value', value );

            input.datepicker({
                language: "de",
                format: "dd.mm.yyyy",
                todayBtn: "linked",
                orientation: "left"
            });
            return $('<div class="form-group col-sm-6">').attr('for',element.id)
                .append($('<label>').attr('for',element.id).text(element.label))
                .append(input);

        },
        'text': function (element, value) {
          var ipt=$('<input type="text" class="form-control">')
            .prop('id', element.id);
            if (element.subtype === 'betrag')  {
              ipt.prop('type','number')
              .prop('min', '0')
              .prop('step','0.01');
              if (value === null) {
                value="0.00";
              }
            }
            ipt.prop('value', value);
            if (element.readonly === true) {
              ipt.prop('readonly',true);
            }
            return $('<div class="form-group col-sm-6">').attr('for',element.id)
                .append($('<label>').attr('for',element.id).text(element.label))
                .append(ipt);
        },
        'radio': function (element, value) {
                var div=$('<div class="form-group col-sm-5">').attr('for',element.id);
                div.append($('<label>').attr('for', element.id).text(element.label));
            $.each(element.options, function (index, option) {
              var radioInput=  $('<input type="radio">')
                      .prop('value', option.id)
                      .prop('name', element.id);
              if (value === option.id) {
                radioInput.prop('checked', true);
              }
              var radioDiv=$('<div class="radio">').append(
                  $('<label>').text(option.text).prepend(
                    radioInput)
                );
              div.append(radioDiv);
            });
              return div;
        },
        'select': function (element, value) {
            var div=$('<div class="form-group">').attr('for',element.id);
            var selectDiv= $('<select class="form-control">').prop('id',element.id);
            $.each(element.options, function (index, option) {
              var opt=$('<option>').prop('value', option.id).text(option.text);
              if (option.id == value) {
                opt.prop('selected', true);
              }
              selectDiv.append(opt);
            });

            div.append($('<label>').attr('for',element.id).text(element.label))
                .append(selectDiv);
            return div;
        }
    };
    function appendElements(sectionDiv, elements, data) {
        $.each(elements, function (index, element) {
            var eleData=null;
            if (element.dbid) {
              eleData=data[element.dbid];
            } else if (data[element.id] != null) {
              eleData=data[element.id];
            }
            sectionDiv.append(viewElements[element.type](element, eleData));
        });
    }

    function hideIfInArray(div, statusVal, array, id) {
        var ele=div.find('.form-group[for='+id+']');
        var found=false;
        if (ele.length===0) {
          console.error('Group not found: '+id);
        }
        $.each(array, function (idx, eleM) {
            if (eleM===statusVal) {
                found = true;
            }
        });
        if (found)  {
            ele.hide();
        } else {
            ele.show();
        }
    }
    function getView(data) {
        var div = $('<div class="container-fluid">');
        function appendSection(idx,section) {
            var sectionDiv=$('<div class="row section">').prop('id','section_'+section.id).attr('idx',idx);
            div.append($('<h3>').text(section.headline));
            appendElements(sectionDiv, section.elements, data);
            div.append(sectionDiv);
        }
        $.each(layout, appendSection);

        function enableDisableBoxes() {
            var statusVal=div.find('input[name=status]:checked').val();
            var arr=['0', '1'];
            hideIfInArray(div, statusVal, arr, 'antragdate');
            hideIfInArray(div, statusVal, arr, 'belegantragsabgabe');
  /*          hideIfInArray(div, statusVal, arr, 'kostenBezahlt');
            hideIfInArray(div, statusVal, arr, 'kostenErwartet');*/
            arr.push('2');
            hideIfInArray(div, statusVal, arr, 'antwortaufantrag');
            arr.push('3');
            arr.push('4');
            arr.push('6');
            arr.push('7');
            hideIfInArray(div, statusVal, arr, 'widersprucheingang');
            hideIfInArray(div, statusVal, arr, 'belegwiderspruchabgabe');
            arr.push('5');
            hideIfInArray(div, statusVal, arr, 'widerspruchantwort');
            arr.push('8');
            arr.push('9');
            arr.push('11');
            arr.push('12');
            hideIfInArray(div, statusVal, arr, 'klagedatum');
            arr.push('13');
            arr.push('10');
            hideIfInArray(div, statusVal, arr, 'urteildatum');
        }
        div.find('input[name=status]').change(enableDisableBoxes);
        enableDisableBoxes();
        div.find('#section_status').after($('<hr>')).after($('<div class="alert alert-info">').text('Du hast Fragen oder möchtest uns etwas mitteilen was hier im Formular keinen Raum findet? Schreibe uns an ').
        append($('<strong>').append($('<a href="mailto:<EMAIL>?subject=Tempo30-Antrag-Daten-Id-'+data.id+'">').text('<EMAIL>')))).after($('<hr>'));

        if (data.lastchanged !== null) {
          var mLastChange = moment(data.lastchanged);
          if (mLastChange.add(1,'M').isBefore()) {
            mLastChange = moment(data.lastchanged);
            div.prepend($('<div class="alert alert-warning">')
            .text(' Die Daten wurden das letzte mal am '+mLastChange.format('DD.MM.YYYY')+
            ' in der Datenbank aktualisiert. Bitte drücken Sie auch bei keiner Änderung auf den "Speichern" Button um uns mitzuteilen, dass es keine Änderung des Statuses gab ')
            .prepend(
              $('<strong>').text('Achtung')));
          }
        }
        if (data.antragdate !== null) {
          var mAntragDate=moment(data.antragdate, 'YYYY-MM-DD');
          if ((mAntragDate.add(3,'M').isBefore()) && (data.status === '2')) {
              div.prepend($('<div class="alert alert-warning">')
              .text(' Seit der Antragsstelung sind mehr als 3 Monate vergangen. Die Behörde hätte Ihnen antwoten müssen. Sie könnten jetzt eine Untätigkeitsklage gegen die Stadt erheben. Vielleicht macht es auch Sinn, nochmal bei der Behörde nach dem Bearbeitungsstand zu fragen.')
              .prepend(
                $('<strong>').text('Achtung')));
          }
        }
        if (data.updateStatus !== undefined) {
          div.prepend($('<div class="alert alert-success">')
          .text(' Die Daten wurden erfolgreich aktualisiert.')
          .prepend(
            $('<strong>').text('Vielen Dank')));
        }
        return div;
    }

    return getView;

});
{'fraction_non_alphanumeric': 0.17184072325998803, 'fraction_numerical': 0.004786279332579938, 'mean_word_length': 1.893076923076923, 'pattern_counts': {'":': 0, '<': 60, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '951934', 'n_tokens_mistral': 4424, 'n_tokens_neox': 4330, 'n_words': 745}