Включить в схеме Correspondent признак обновления свойств схемы (recalc="true"), которую использует форма диалога.
Добавить временные поля, для создания списка адресов и телефонов
<?xml version='1.0' encoding='UTF-8'?> <schemas xmlns="http://www.intertrust.ru/schema/palette/tn-schema"> <schema name="schemaCorrespondent" recalc="true" > <!--...--> <!-- временное поле, для списка всех адресов корреспондента --> <string name="all_address" array="true" temporal="true"/> <!-- временное поле, для списка всех телефонов --> <string name="all_phone" array="true" temporal="true"/> <!--...--> </schema> </schemas> |
Доработать форму
В форме CorrespondentDialog в поле "Корреспондент" включить признак "Участие в вычисление секции" (recalc = "true")
<?xml version='1.0' encoding='UTF-8'?> <ui xmlns="http://www.intertrust.ru/schema/palette/tn-ui"> <form id="formCorrespondentDialog" schema-ref="schemaCorrespondent" name="${ui.form.CorrespondentDialog.name:Корреспондент}"> <properties> <hide condition-union="AND"> <negative-condition-ref ref="dialog"/> </hide> </properties> <component> <field name="${ui.form.formCorrespondentDialog.name:Корреспондент:}" attribute-ref="Correspondent" recalc="true"> <!--...--> </field> <!--...--> </component> </form> </ui> |
Добавить в обработчик событий recalc
<?xml version='1.0' encoding='UTF-8'?> <schemas xmlns="http://www.intertrust.ru/schema/palette/tn-schema"> <schema name="schemaCorrespondent"> <!--...--> <custom-event-handler lang="JavaScript"><![CDATA[...]]></custom-event-handler> <schema> </schemas> |
Код
importPackage(Packages.java.lang); importPackage(Packages.java.util); importPackage(Packages.ru.intertrust.cmj.af.so); importPackage(Packages.ru.intertrust.cmj.rest.tuning); importPackage(Packages.ru.intertrust.cmj.af.misc); importPackage(Packages.ru.intertrust.cmj.af.utils); importPackage(Packages.ru.intertrust.cmj.af.tuning.impl); importClass(Packages.ru.intertrust.cmj.rest.tuning.TuningHelper); importClass(Packages.java.lang.System); importClass(Packages.ru.intertrust.cmj.tunable.object.common.TunableObjectHelper); importClass(Packages.ru.intertrust.cmj.af.core.AFSession); importClass(Packages.ru.intertrust.cmj.tunable.object.TunableObjectApplication); importClass(Packages.ru.intertrust.cmj.tunable.object.AnyTunableObject); importClass(Packages.ru.intertrust.cmj.af.core.AFCMDomino); importClass(Packages.org.springframework.util.StringUtils); importClass(Packages.ru.intertrust.cmj.af.so.SOApplication); //Функция вызывается при изменении поля, в котором установлен флаг recalc = "true" function recalc(object, changedField) { // Получение tn-объекта var tuning = object.tuning(); // Карта AFInstance текушего объекта var values = tuning.getValues(); // Схема текущего объекта var schema = tuning.getSchema(); // Название измененного поля if (changedField == "Correspondent") { // Обнуление полей values.put("Index", null); //Индекс values.put("Address", null); //Адрес values.put("Recipient", null); //ФИО получателя values.put("Phone", null); //Телефон if (values.get('Correspondent') != null && values.get('Correspondent').getValue() != null) { // Поле Корреспондент не пустое var correspondent = values.get('Correspondent').getValue(); // Значение из поля Корреспондент if (correspondent != null) { // Получение tn-объекта корреспондента var appTNObject = AFSession.get().getApplication(TunableObjectApplication.class); var correspondentObject = appTNObject.getEntityByUNID(AFCMDomino.ormUnidToTNUnid(correspondent.getUNID())); if (correspondentObject != null) { // Формирование списка адресов var emplAddrs = new ArrayList(); // Почтовый/физический адрес if (correspondent.getAddress() != "") { emplAddrs.add(correspondent.getAddress()); } // Юридический адрес if (correspondent.originalData().getType() == SOBeard.Type.NONSYS_ORGANIZATION) { if (correspondent.originalData().getParty().addressInfo().legal().getAddress() != "") { emplAddrs.add(correspondent.originalData().getParty().addressInfo().legal().getAddress()); //заполняем адрес для несистемных организаций } } // Формирование списка телефонов var emplPhones = new ArrayList(); // Карта объектов AFInstance корреспондента var correspondentValue = correspondentObject.tuning().getValues(); var phoneH = correspondentValue.get("phoneHouse"); var phoneW = correspondentValue.get("phoneWork"); var phoneM = correspondentValue.get("phoneMobil"); var phone = correspondentValue.get("phone"); emplPhones.add(phoneH); emplPhones.add(phoneW); emplPhones.add(phoneM); if (phone != null && phone.getValues() != null) { emplPhones.addAll(phone.getValues()); } // Вычисление телефона по умолчанию var phoneValue; if (phoneM != null) { phoneValue = TunableObjectHelper.getAFInstanceValue(phoneM); } else if (phoneW != null) { phoneValue = TunableObjectHelper.getAFInstanceValue(phoneW); } else if (phoneH != null) { phoneValue = TunableObjectHelper.getAFInstanceValue(phoneM); } else if (phone != null && phone.getValues() != null) { phoneValue = TunableObjectHelper.getAFInstanceValue(phone.getValues().get(0)); } // Получатель var recipientValue = new ArrayList(); recipientValue.add(correspondent.originalData().getFullName()); if (correspondent.originalData().getType().toString().equals("PRIVATE_HUMAN")) { // В качестве корреспондента выбрано 'Частное лицо' var indexValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("sendIndex")); // Индекс var countryValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("country")); // Страна var regionValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("region")); // Регион var districtValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("district")); // Населенный пункт var cityValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("city")); // Город var streetValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("street")); // Улица var houseValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("house")); // Дом var structureValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("structure")); // Корпус var housingValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("housing")); // Строение var roomValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("room")); // Комната //Формирование адреса по умолчанию var addressValue = (StringUtils.hasLength(countryValue) ? countryValue + ', ' : "") + (StringUtils.hasLength(regionValue) ? regionValue + ', ' : "") + (StringUtils.hasLength(districtValue) ? districtValue + ', ' : "") + (StringUtils.hasLength(cityValue) ? cityValue + ', ' : "") + (StringUtils.hasLength(streetValue) ? streetValue + ', ' : "") + (StringUtils.hasLength(houseValue) ? houseValue + ', ' : "") + (StringUtils.hasLength(structureValue) ? structureValue + ', ' : "") + (StringUtils.hasLength(housingValue) ? housingValue + ', ' : "") + (StringUtils.hasLength(roomValue) ? roomValue : ""); } else if (person.originalData().getType().toString().equals("SYS_ORGANIZATION")) { // В качестве корреспондента выбрана 'Системная организация' var addressValue = correspondent.originalData().getParty().getOrganizationDescription().addressInfo().post().getAddress(); //Адрес var indexValue = correspondent.originalData().getParty().getOrganizationDescription().addressInfo().post().getZipCode(); //Индекс } else { // В качестве корреспондента выбрана 'Не системная организация' var indexValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jSendIndex")); //Индекс var countryValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jcountryName")); //Страна var regionValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("region")); //Регион var districtValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jDistrict")); //Населенный пункт var cityValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jCity")); //Город var streetValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jStreet")); //Улица var houseValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jHouse")); //Дом var structureValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jStructure")); //Корпус var housingValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jHousing")); //Строение //Формирование адреса по умолчанию var addressValue = (StringUtils.hasLength(countryValue) ? countryValue + ', ' : "") + (StringUtils.hasLength(regionValue) ? regionValue + ', ' : "") + (StringUtils.hasLength(districtValue) ? districtValue + ', ' : "") + (StringUtils.hasLength(cityValue) ? cityValue + ', ' : "") + (StringUtils.hasLength(streetValue) ? streetValue + ', ' : "") + (StringUtils.hasLength(houseValue) ? houseValue + ', ' : "") + (StringUtils.hasLength(structureValue) ? structureValue + ', ' : "") + (StringUtils.hasLength(housingValue) ? housingValue : ""); } // Запись в поле 'Список адресов' if (!emplAddrs.isEmpty()) { TunableObjectHelper.putAFInstanceValue(tuning, "all_address", emplAddrs); } // Запись в поле 'Список телефонов' if (!emplPhones.isEmpty()) { TunableObjectHelper.putAFInstanceValue(tuning, "all_phone", emplPhones); } //Запись остальных полей TunableObjectHelper.putAFInstanceValue(tuning, "Recipient", recipientValue); //Получатель TunableObjectHelper.putAFInstanceValue(tuning, "Index", indexValue); //Индекс TunableObjectHelper.putAFInstanceValue(tuning, "Address", addressValue); //Адрес TunableObjectHelper.putAFInstanceValue(tuning, "Phone", phoneValue); //Телефон } } } } } |
Подключить справочник Адресов и Телефонов к форме CorrespondentDialog, через элемент directory-select-value
<?xml version='1.0' encoding='UTF-8'?> <ui xmlns="http://www.intertrust.ru/schema/palette/tn-ui"> <form id="formCorrespondentDialog" schema-ref="schemaCorrespondent" name="${ui.form.CorrespondentDialog.name:Корреспондент}"> <properties> <hide condition-union="AND"> <negative-condition-ref ref="dialog"/> </hide> </properties> <component> <!--...--> <field name="${ui.form.formCorrespondentDialog.Address.name:Адрес отправки:}" attribute-ref="Address"> <directories manual-input="true"> <directory-select-value name="Адреса" attribute-ref="all_address"/> </directories> </field> <field name="${ui.form.formCorrespondentDialog.Phone.name:Телефон получателя:}" attribute-ref="Phone"> <directories manual-input="true"> <directory-select-value name="Телефоны" attribute-ref="all_phone"/> </directories> </field> <!--...--> </component> </form> </ui> |