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

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

Ключ

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

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

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

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

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

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

Оглавление

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

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

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

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

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

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

Блок кодаlanguagejs

Включить в схеме 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>
</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.Correspondent.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
titleОбработчик событий
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);(changedField == "Correspondent") {
		
		//Обнуление полей
		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) {) != null) { //Поле Корреспондент не пустое
			
			var personcorrespondent = object.tuning().getValues().get('Correspondent').getValue(); //значение из поля Корреспондент

			var emplAddrs = new ArrayList();
			var emplPhones = new ArrayList();
			
			if (personcorrespondent.getAddress() != "") {
				emplAddrs.add(personcorrespondent.getAddress()); //заполняем адрес из бороды
		    }
			}
			if (personcorrespondent.originalData().getType() == SOBeard.Type.NONSYS_ORGANIZATION) { 
				if (personcorrespondent.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) {
				phoneValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("phoneMobil"));
			} else if (phoneW != null) {
				phoneValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("phoneWork"));
			} else if (phoneH != null) {
				phoneValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("phoneHouse"));
			} else if (phone != null && objectBeard.tuning().getValues().get("phone").getValues() != null) {
				phoneValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("phone").getValues().get(0));
			}
			if (phoneValue != 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")) {
					var indexValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("sendIndex"));
					//var phoneValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("phoneHouse"));
					var countryValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().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")) {
					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")));
			}
		}
	}
}