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

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

Ключ

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

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

  • Индекс
  • Адрес отправки - массив адресов, для дальнейшей возможности выбора 
  • ФИО получателяполучателя 
  • Телефон получателя - массив телефонов, для дальнейшей возможности выбора 

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

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

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

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

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

Оглавление

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

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

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

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

Блок кода
languagexml
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>
<		<!--...-->
  </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.CorrespondentTableDialogForm.CorrespondentformCorrespondentDialog.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) {
	if (changedField == "Correspondent") {
 	// Получение tn-объекта
	var tuning = object.tuning();
		
		//Обнуление полей
		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 correspondent = object.tuning().getValues().get('Correspondent').getValue(); //значение из поля Корреспондент

			var emplAddrs = new ArrayList();
			var emplPhones = new ArrayList(); Карта 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.getAddress() != ""null) {

				emplAddrs.add(correspondent.getAddress()); //заполняем адресПолучение изtn-объекта бородыкорреспондента
				var    }
			
			if (correspondent.originalData().getType() == SOBeard.Type.NONSYS_ORGANIZATION) { appTNObject = AFSession.get().getApplication(TunableObjectApplication.class);
				if (correspondent.originalData().getParty().addressInfo().legal().getAddress()var correspondentObject = appTNObject.getEntityByUNID(AFCMDomino.ormUnidToTNUnid(correspondent.getUNID()));
				if (correspondentObject != ""null) {

					emplAddrs.add(person.originalData().getParty().addressInfo().legal().getAddress());
				}
			}

// Формирование списка адресов
					var emplAddrs = new ArrayList();

					// Почтовый/физический адрес
					if (!emplAddrscorrespondent.isEmptygetAddress() != "") {
						TuningHelper.processProperty(object.tuning().getValues(), "all_address", emplAddrs, object.tuningadd().getSchema().getProperty("all_address"correspondent.getAddress());
					}

					var// fio = new ArrayList();
Юридический адрес
					fio.add(personif (correspondent.originalData().getFullNamegetType());
 == SOBeard.Type.NONSYS_ORGANIZATION) {
						var fioValue = new AFInstanceArrayImpl(object.tuningif (correspondent.originalData().getSchemagetParty(), fio);
			object.tuning.addressInfo().getValueslegal().putgetAddress() != "Recipient",) fioValue);
{
							var appTNObject = AFSession.getemplAddrs.add(correspondent.originalData().getApplicationgetParty(TunableObjectApplication.class);
			var objectBeard = appTNObject.getEntityByUNID(AFCMDomino.ormUnidToTNUnid(person.getUNID()));
			var phoneH = objectBeard.tuning().getValues().get("phoneHouse");
.addressInfo().legal().getAddress()); //заполняем адрес для несистемных организаций
						}
					}

					// Формирование списка телефонов
					var phoneWemplPhones = objectBeard.tuning().getValues().get("phoneWork");
 new ArrayList();

					// Карта объектов AFInstance корреспондента
					var phoneMcorrespondentValue = objectBeardcorrespondentObject.tuning().getValues().get("phoneMobil");
					var phonephoneH = objectBeard.tuning().getValues()correspondentValue.get("phonephoneHouse");
					emplPhones.add(phoneHvar phoneW = correspondentValue.get("phoneWork");
					var phoneM = correspondentValue.get("phoneMobil");
					emplPhones.add(phoneWvar phone = correspondentValue.get("phone");

					emplPhones.add(phoneMphoneH);
					if (phoneemplPhones.add(phoneW);
					emplPhones.add(phoneM);

					if (phone != null && phone.getValues() != null) {
						emplPhones.addAll(phone.getValues());
					}

					// Вычисление телефона по умолчанию
					var phoneValue;
					if (phoneM != null) {
						phoneValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("phoneMobil"));
phoneM);
					} else if (phoneW != null) {
						phoneValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("phoneWork")phoneW);
					} else if (phoneH != null) {
						phoneValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("phoneHouse")phoneM);
					} else if (phone != null && objectBeard.tuning()phone.getValues().get("phone").getValues() ! != null) {
						phoneValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("phone").getValues().get(0));
					}

					// Получатель
					ifvar (phoneValuerecipientValue != new nullArrayList() {;
					TuningHelperrecipientValue.processPropertyadd(objectcorrespondent.tuningoriginalData().getValues(), "Phone", phoneValue, object.tuning().getSchema().getProperty("Phone"getFullName());
			}
			if (!emplPhonescorrespondent.isEmptyoriginalData()) {
				TuningHelper.processProperty(object.tuning.getType().toString().getValuesequals(), "allPRIVATE_phone", emplPhones, object.tuning().getSchema().getProperty("all_phone"));
			}
			if (objectBeard != null) {
				if (person.originalData().getType().toString().equals("PRIVATE_HUMAN")) {
HUMAN")) { // В качестве корреспондента выбрано 'Частное лицо'
						var indexValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("sendIndex")); // Индекс
						var countryValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("country")); // Страна
						var indexValueregionValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues()correspondentValue.get("sendIndexregion")); // Регион
						//var phoneValuedistrictValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().correspondentValue.get("phoneHousedistrict")); // Населенный пункт
						var countryValuecityValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues()correspondentValue.get("countrycity")); // Город
						var regionValuestreetValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues()correspondentValue.get("regionstreet")); // Улица
						var districtValuehouseValue = TunableObjectHelper.getAFInstanceValue(objectBeardcorrespondentValue.tuning().getValues().get("districtget("house")); // Дом
						var cityValuestructureValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues()correspondentValue.get("citystructure")); // Корпус
						var streetValuehousingValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues()correspondentValue.get("streethousing")); // Строение
						var houseValueroomValue = TunableObjectHelper.getAFInstanceValue(objectBeardcorrespondentValue.tuning().getValues().get("houseget("room")); // Комната

						var//Формирование structureValueадреса = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("structure"));
по умолчанию
						var housingValueaddressValue = TunableObjectHelper.getAFInstanceValue(objectBeardStringUtils.tuninghasLength().getValues().get("housing"));
					var roomValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("room"));
					var addressValue =countryValue) ? countryValue + ', ' : "") + (StringUtils.hasLength(countryValueregionValue) ? countryValueregionValue + ', ' : "") + (StringUtils.hasLength(regionValuedistrictValue) ? 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")) { // В качестве корреспондента выбрана 'Системная организация'

						var addressValue = correspondent.originalData().getParty().getOrganizationDescription().addressInfo().post().getAddress(); //Адрес
						var indexValue = correspondent.originalData().getParty().getOrganizationDescription().addressInfo().post().getZipCode(); //Индекс	

					} else { // if (person.originalData().getType().toString().equals("SYS_ORGANIZATION")) {
В качестве корреспондента выбрана 'Не системная организация'

						var indexValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jSendIndex")); //Индекс
						var addressValuecountryValue = personTunableObjectHelper.originalDatagetAFInstanceValue()correspondentValue.getPartyget("jcountryName").getOrganizationDescription().addressInfo().post().getAddress();
); //Страна
						var indexValueregionValue = personTunableObjectHelper.originalDatagetAFInstanceValue()correspondentValue.getParty().getOrganizationDescription().addressInfo().post().getZipCode();
get("region")); //Регион
						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 districtValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jDistrict")); //Населенный пункт
						var cityValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jCity")); //Город
						var streetValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jStreet")); //Улица
						var indexValuehouseValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues()correspondentValue.get("jSendIndexjHouse")); //Дом
						var countryValuestructureValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues()correspondentValue.get("jcountryNamejStructure")); //Корпус
						var regionValuehousingValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues()correspondentValue.get("regionjHousing")); //Строение

						//Формирование адреса по умолчанию
						var districtValueaddressValue = TunableObjectHelper.getAFInstanceValue(objectBeardStringUtils.tuninghasLength().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")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);
					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")));
			}
		}
	}
}}

					// Запись в поле 'Список телефонов'
					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>