vendorform.js
2.92 KB
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
var numCommands = 0
function processPrice(price)
{
newPrice = price.replace(",",".")
pattern = /^\d{1,2}.\d{1,2}$/
if(newPrice.search(pattern) == -1)
{
alert("Maximum price exceeded or incorrect price format")
return ""
}
euros = newPrice.substring(0,newPrice.indexOf("."))
cents = newPrice.substring(newPrice.indexOf(".")+1)
if(euros.length != 2)
{
euros = "0" + euros
}
if(cents.length != 2)
{
cents += "0"
}
return euros + cents
}
function addCommand()
{
command=$("input[name=command]:checked").val()
if(typeof command == 'undefined')
{
alert("No command selected")
return
}
else if(command == "Hello")
{
//NOTHING TO DO
}
else if(command == "A5")
{
date=$("input[name=datepicker]").val()
if(date == "")
{
alert("Date not set. Please check that BOTH date and time are set in the field")
return
}
command += date.substring(8,10)
command += date.substring(3,5)
command += date.substring(0,2)
command += date.substring(11,13)
command += date.substring(14,16)
command += date.substring(17,19)
}
else if(command == "A6")
{
channel=$("input[name=channela6]").val()
product=$("input[name=producta6]").val()
price=$("input[name=price]").val()
if(channel == "" || product == "" || price == "")
{
alert("Missing required parameters for Product Price Change command. Please check that Channel, Product and Price fields are set")
return
}
command += channel
command += product
newPrice = processPrice(price)
if(newPrice == "")
{
return
}
command += newPrice
}
else if(command == "A7")
{
channel=$("input[name=channela7]").val()
product=$("input[name=producta7]").val()
productName=$("input[name=productname]").val()
if(channel == "" || product == "" || productName == "")
{
alert("Missing required parameters for Product Name Change command. Please check that Channel, Product and Product Name fields are set")
return
}
command += channel
command += product
command += productName
}
else if(command == "Bye")
{
//NOTHING TO DO
}
$("select[name=commandlist]").append(new Option(command,command))
numCommands++
$("select[name=commandlist]").attr('size',numCommands)
}
function removeCommand()
{
numCommands -= $("select[name=commandlist] option:selected").length
$("select[name=commandlist] option:selected").remove()
$("select[name=commandlist]").attr('size',numCommands)
}
function submitForm()
{
name = $("input[name=name]").val()
machineID = $("input[name=machineid]").val()
commands = ""
commandList = $("select[name=commandlist] option")
if(commandList.length == 0)
{
alert("No commands added in command list")
return
}
var i
for(i = 0; i < commandList.length; i++)
{
commands += commandList[i].text + ","
}
commands = commands.slice(0,-1)
$("input[name=commands]").val(commands)
document.getElementById("btvendor").submit()
}
$(function()
{
$('#datetimepicker1').datetimepicker(
{
language: 'es-ES'
});
});