summaryrefslogtreecommitdiff
path: root/templates/edit_movement.tpl
blob: c5c8c91e6b6e3ff9413220cb89a88e1effa0dafc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
{strip}
<div class="edit stock">
	<div class="header">
		<h1>
			{if $gContent->isValid()}
				{tr}Edit Movement{/tr}: {$gContent->getTitle()|escape}
			{else}
				{tr}Create Movement{/tr}
			{/if}
		</h1>
	</div>

	<div class="body">
		{formfeedback error=$errors}

		{form id="editMovementForm" enctype="multipart/form-data" ipackage="stock" ifile="edit_movement.php"}
			<input type="hidden" name="content_id" value="{$gContent->mContentId|escape}" />

			<div class="form-group">
				{formlabel label="Reference" for="title" mandatory="y"}
				{forminput}
					<input type="text" class="form-control input-xlarge" name="title" id="title"
						value="{$gContent->getTitle()|escape}" maxlength="160" />
				{/forminput}
			</div>

			{if !$isBuild}
			{if $refTypes}
			<div class="form-group">
				{formlabel label="Movement Type" mandatory="y"}
				{forminput}
					{foreach from=$refTypes key=item item=label}
						<label class="radio-inline">
							<input type="radio" name="movement_type" value="{$item|escape}"
								{if ($gContent->mInfo.ref_type|default:'TRANS') eq $item} checked="checked"{/if} /> {$label|escape}
						</label>
					{/foreach}
				{/forminput}
			</div>
			{/if}

			<div class="form-group">
				{formlabel label="From" for="ref_from"}
				{forminput}
					<input type="hidden" name="ref_contact_id" id="ref_contact_id"
						value="{$gContent->mInfo.ref_contact_id|default:''|escape}" />
					<div style="position:relative">
						<input type="text" class="form-control" name="ref_from" id="ref_from"
							autocomplete="off"
							value="{if $gContent->mInfo.ref_contact_name}{$gContent->mInfo.ref_contact_name|escape}{else}{$gContent->mInfo.ref_from_data|default:''|escape}{/if}"
							maxlength="160" placeholder="Type to search contacts…" />
						<ul id="contact_dropdown" class="dropdown-menu"
							style="display:none;position:absolute;width:100%;z-index:1000;max-height:220px;overflow-y:auto"></ul>
					</div>
				{/forminput}
			</div>

			<div class="form-group">
				{formlabel label="Ref Key" for="ref_key"}
				{forminput}
					<input type="text" class="form-control" name="ref_key" id="ref_key"
						value="{$gContent->mInfo.ref_key|default:''|escape}" maxlength="160" />
				{/forminput}
			</div>
			{/if}

			<div class="form-group">
				{formlabel label="{if $isPbld}Build Date{else}Ordered{/if}" for="ordered_date"}
				{forminput}
					<input type="text" class="form-control input-small" name="ordered_date" id="ordered_date"
						placeholder="dd/mm/yyyy" value="{$orderedDateVal|escape}" maxlength="10" />
				{/forminput}
			</div>

			<div class="form-group">
				{formlabel label="{if $isPbld}Completed{else}Received{/if}" for="received_date"}
				{forminput}
					<input type="text" class="form-control input-small" name="received_date" id="received_date"
						placeholder="dd/mm/yyyy" value="{$receivedDateVal|escape}" maxlength="10" />
				{/forminput}
			</div>

			<div class="form-group">
				{formlabel label="Note" for="edit"}
				{forminput}
					<textarea class="form-control" name="edit" id="edit" rows="2">{$gContent->mInfo.data|default:''|escape}</textarea>
				{/forminput}
			</div>

			{if !$gContent->isValid()}
			<div class="form-group">
				{formlabel label="Load CSV"}
				{forminput}
					<input type="file" name="csv_file" accept=".csv,text/csv" />
					{formhelp note="Optional — upload movement CSV at creation time"}
				{/forminput}
			</div>
			{/if}

			{include file="bitpackage:liberty/edit_content_owner_inc.tpl"}

			<div class="form-group submit">
				<input type="submit" class="btn btn-primary" name="fSave" value="{tr}Save{/tr}" />
				{if $gContent->isValid() && $gBitUser->hasPermission('p_stock_expunge')}
					<input type="submit" class="btn btn-danger pull-right" name="delete" value="{tr}Delete{/tr}" />
				{/if}
			</div>
		{/form}

		{if $gContent->isValid()}

			{if $gXrefInfo->mGroups}
				{jstabs}
					{foreach $gXrefInfo->mGroups as $xrefGroup}
						{if $xrefGroup->mXGroup neq 'reference' && ($xrefGroup->mXGroup neq 'assembly' || $isBuild)}
							{include file=$gContent->getXrefListTemplate($xrefGroup->mTemplate)
								xrefGroup=$xrefGroup
								allow_add=true
								allow_edit=true}
						{/if}
					{/foreach}
				{/jstabs}
			{/if}

			{if !$isBuild}
			{* ── Upload CSV (orders/transfers only) ── *}
			<h4>{tr}Upload CSV{/tr}</h4>
			{form enctype="multipart/form-data" ipackage="stock" ifile="edit_movement.php"}
				<input type="hidden" name="content_id" value="{$gContent->mContentId|escape}" />
				<div class="form-inline">
					<input type="file" name="csv_file" accept=".csv,text/csv" />
					<input type="submit" class="btn btn-default" name="upload_csv" value="{tr}Upload{/tr}" />
				</div>
			{/form}
			{/if}

			{* ── Upload results ── *}
			{if isset($csvLoaded)}
				<div class="alert alert-info">
					{tr}Loaded{/tr}: <strong>{$csvLoaded}</strong>
					{if $csvSkipped} &nbsp; {tr}Skipped{/tr}: <strong>{$csvSkipped}</strong>{/if}
				</div>
				{if $csvErrors}
					<ul class="text-warning">
						{foreach from=$csvErrors item=msg}<li>{$msg|escape}</li>{/foreach}
					</ul>
				{/if}
			{/if}

		{/if}

	</div><!-- end .body -->
</div><!-- end .stock -->
<script>
(function($) {
	var timer, contacts = [];
	var $input = $('#ref_from');
	var $hidden = $('#ref_contact_id');
	var $dd = $('#contact_dropdown');

	$input.on('input', function() {
		var q = $(this).val();
		clearTimeout(timer);
		$dd.hide().empty();
		contacts = [];
		if (q.length < 2) return;
		timer = setTimeout(function() {
			$.getJSON('{$contactLookupUrl}', {ldelim}q: q{rdelim}, function(data) {
				contacts = data;
				if (!data.length) return;
				$.each(data, function(i, row) {
					var label = row.title + (row.scref ? ' (' + row.scref + ')' : '');
					$dd.append($('<li>').append(
						$('<a>').attr('href','#').data('id', row.content_id).data('label', label).text(label)
					));
				});
				$dd.show();
			});
		}, 250);
	});

	$(document).on('mousedown', '#contact_dropdown a', function(e) {
		e.preventDefault();
		$input.val($(this).data('label'));
		$hidden.val($(this).data('id'));
		$dd.hide().empty();
		contacts = [];
	});

	$input.on('blur', function() {
		setTimeout(function() { $dd.hide(); }, 150);
	});

	$input.on('keydown', function(e) {
		if (!$dd.is(':visible')) return;
		var $items = $dd.find('a');
		var idx = $dd.find('li.active a').length ? $items.index($dd.find('li.active a')) : -1;
		if (e.key === 'ArrowDown') {
			e.preventDefault();
			$items.parent().removeClass('active');
			$items.eq(idx + 1 < $items.length ? idx + 1 : 0).parent().addClass('active');
		} else if (e.key === 'ArrowUp') {
			e.preventDefault();
			$items.parent().removeClass('active');
			$items.eq(idx > 0 ? idx - 1 : $items.length - 1).parent().addClass('active');
		} else if (e.key === 'Enter') {
			var $active = $dd.find('li.active a');
			if ($active.length) { e.preventDefault(); $active.trigger('mousedown'); }
		} else if (e.key === 'Escape') {
			$dd.hide();
		}
	});
}(jQuery));
</script>
{/strip}