Дерево страниц

Сравнение версий

Ключ

  • Эта строка добавлена.
  • Эта строка удалена.
  • Изменено форматирование.
Информация
iconfalse
titleПостановка задачи

При выборе организации в диалоге в поле Корреспондент необходимо автоматически заполнить поля:

  • Индекс
  • Адрес отправки
  • ФИО получателя 
  • Телефон получателяТелефон получателя

Дополнительно необходимо предусмотреть возможность подключения справочника к полям:

  • Телефоны - выбираются из телефонов корреспондента
  • Адреса - выбираются из адресов корреспондента 
  • ФИО получателя - выбираются из получателей корреспондента
Подсказка
iconfalse
Инструмент: Палитра XML
Свойства страницы
Статус

Статус
colourYellowGreen
titleВ РАБОТЕГОТОВО

РазделФорма
Комментарий

панель
titleРеализация

Оглавление

панель
titleРезультат

Доработать схему

Инициирование формы на обновление

Доработать форму

Включение поля как инициатор

Доработать обработчик событий

Включить в схеме Correspondent признак обновления свойств схемы (recalc="true"), которую использует форма диалога.

Добавить временные поля, для создания списка адресов и телефонов

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); function recalc(object, changedField) { if (changedField == "Correspondent") { object.tuning().getValues().put("all_address", null); object.tuning().getValues().put("all_phone", null); object.tuning().getValues().put("Phone", null); object.tuning().getValues().put("SendAddress", null); if (object.tuning().getValues().get('Correspondent') != null && object.tuning().getValues().get('Correspondent').getValue() != null) { var person = object.tuning().getValues().get('Correspondent').getValue(); var emplAddrs = new ArrayList(); var emplPhones = new ArrayList(); if (person.getAddress() != "") { emplAddrs.add(person.getAddress()); } if (person.originalData().getType() == SOBeard.Type.NONSYS_ORGANIZATION) { if (person.originalData().getParty().addressInfo().legal().getAddress() != "") { emplAddrs.add(person.originalData().getParty().addressInfo().legal().getAddress()); } } if (!emplAddrs.isEmpty()) { TuningHelper.processProperty(object.tuning().getValues(), "all_address", emplAddrs, object.tuning().getSchema().getProperty("all_address")); } var fio = new ArrayList(); fio.add(person.originalData().getFullName()); var fioValue = new AFInstanceArrayImpl(object.tuning().getSchema(), fio); object.tuning().getValues().put("Recipient", fioValue); var appTNObject = AFSession.get().getApplication(TunableObjectApplication.class); var objectBeard = appTNObject.getEntityByUNID(AFCMDomino.ormUnidToTNUnid(person.getUNID())); var phoneH = objectBeard.tuning().getValues().get("phoneHouse"); var phoneW = objectBeard.tuning().getValues().get("phoneWork"); var phoneM = objectBeard.tuning().getValues().get("phoneMobil"); var phone = objectBeard.tuning().getValues().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) {
Блок кода
languagejs
xml
titleСхема
<?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")

Блок кода
languagexml
titleФорма
<?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

Блок кода
languagexml
titleОбработчик событий
<?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>

Код

Блок кода
languagejs
titlerecalc
collapsetrue
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(objectBeard.tuning()phone.getValues().get("phoneMobil"0));
					}

					// Получатель
					}var recipientValue else= ifnew ArrayList(phoneW != null) {
);
					phoneValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuningrecipientValue.add(correspondent.originalData().getValues().get("phoneWork"getFullName());
			} else if (phoneH != null) {
				phoneValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuningif (correspondent.originalData().getType().getValuestoString().getequals("phoneHousePRIVATE_HUMAN"));
 { // В качестве корреспондента выбрано 'Частное лицо'
						}var else if (phone != null && objectBeard.tuning().getValues()indexValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("phonesendIndex").getValues(); != null) {// Индекс
				phoneValue		var countryValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues()correspondentValue.get("phonecountry")).getValues(); // Страна
						var regionValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get(0"region")); // Регион
			}
			ifvar (phoneValuedistrictValue != null) {
				TuningHelper.processProperty(object.tuning().getValues(), "Phone", phoneValue, object.tuning().getSchema().getProperty("Phone"));
			}
			if (!emplPhones.isEmpty()) {
				TuningHelper.processProperty(object.tuning().getValues(), "all_phone", emplPhones, object.tuning().getSchema().getProperty("all_phone"));
			}
			if (objectBeard != null) {
				if (person.originalData().getType().toString().equals("PRIVATE_HUMAN")) {
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 indexValueroomValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().correspondentValue.get("sendIndexroom")); // Комната

						//varФормирование phoneValueадреса = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("phoneHouse"));
по умолчанию
						var countryValueaddressValue = TunableObjectHelper.getAFInstanceValue(objectBeardStringUtils.tuninghasLength().getValues().get("country"));
					var regionValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("region"));
					var districtValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("district"));
					var cityValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("city"));
					var streetValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("street"));
					var houseValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("house"));
					var structureValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("structure"));
					var housingValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("housing"));
					var roomValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().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 : "");
					TuningHelper.processProperty(object.tuning().getValues(), "Index", indexValue, object.tuning().getSchema().getProperty("Index"));
					TuningHelper.processProperty(object.tuning().getValues(), "SendAddress", addressValue, object.tuning().getSchema().getProperty("SendAddress"));
					//TuningHelper.processProperty(object.tuning().getValues(), "Phone", phoneValue, object.tuning().getSchema().getProperty("Phone"));
				} else if (person.originalData().getType().toString().equals("SYS_ORGANIZATION")) {
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 = person.originalData().getParty().getOrganizationDescription().addressInfo().post().getAddress();
					var indexValue = person.originalData().getParty().getOrganizationDescription().addressInfo().post().getZipCode();
					TuningHelper.processProperty(object.tuning().getValues(), "SendAddress", addressValue, object.tuning().getSchema().getProperty("SendAddress"));
					TuningHelper.processProperty(object.tuning().getValues(), "Index", indexValue, object.tuning().getSchema().getProperty("Index"));
				} else {
					var indexValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("jSendIndex"));
					var countryValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("jcountryName"));
					var regionValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("region"));
					var districtValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("jDistrict"));
					var cityValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("jCity"));
					var streetValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("jStreet"));
					var houseValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("jHouse"));
					var structureValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("jStructure"));
					var housingValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().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 : "");
					TuningHelper.processProperty(object.tuning().getValues(), "Index", indexValue, object.tuning().getSchema().getProperty("Index"));
					TuningHelper.processProperty(object.tuning().getValues(), "SendAddress", addressValue, object.tuning().getSchema().getProperty("SendAddress"));
				}
			}
			if (person.originalData().getType().toString().equals("SYS_ORGANIZATION")) {
				object.tuning().put("isSysOrg", TuningHelper.createPropertyValue(true, object.tuning().getSchema().getProperty("isSysOrg")));
			}
			if (person.originalData().getType().toString().equals("NONSYS_ORGANIZATION")) {
				object.tuning().put("isSysOrg", TuningHelper.createPropertyValue(false, object.tuning().getSchema().getProperty("isSysOrg")));
			}
		}
	}
} (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

Блок кода
languagexml
titleФорма
<?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>