# -*- coding: utf-8 -*-
from ppms.migration.packet import *

class FixDragNDropMsg(ChangeDTPPacket):
    '''Port dialog messages for drag and drop copying from Venus to VoE'''
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 10594
    
    VALUES = (['EN', 6296, 'Only existing numbers may be input', 'Only input of existing numbers allowed for DI %s "%s" in DT %s "%s"'],
              ['DE', 6296, 'Nur Eingabe existierender Nummern erlaubt', 'Nur Eingabe existierender Nummern erlaubt für DI %s "%s" in DT %s "%s"'],
              ['FR', 6296, 'Seuls les numéros existants peuvent être entrés', 'Seuls les numéros existants peuvent être entrés pour DI %s "%s" en DT %s "%s"'])

    def fix(self, runner):
        errors = 0

        for row in self.VALUES:
            if not self.update_itext(*row):
                errors += 1

        if not errors:
            return self.success()
        return self.fail('See Above.')

    def update_itext(self, language, i_nr, old_text, new_text):
        rec = self.get_record(435, [i_nr, language], [1538, 1550, 1549])

        if self.change_value(rec, 'i_text', old_text, new_text):
            return True
        return False
