147 |
ilm |
1 |
package org.openconcerto.modules.customersupport;
|
|
|
2 |
|
|
|
3 |
import java.sql.SQLException;
|
|
|
4 |
import java.util.Date;
|
|
|
5 |
import java.util.HashSet;
|
|
|
6 |
import java.util.Set;
|
|
|
7 |
|
|
|
8 |
import javax.swing.JComponent;
|
|
|
9 |
import javax.swing.JLabel;
|
|
|
10 |
|
|
|
11 |
import org.openconcerto.sql.element.GroupSQLComponent;
|
|
|
12 |
import org.openconcerto.sql.element.SQLElement;
|
|
|
13 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
14 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
15 |
import org.openconcerto.sql.sqlobject.SQLSearchableTextCombo;
|
|
|
16 |
import org.openconcerto.sql.users.UserManager;
|
|
|
17 |
import org.openconcerto.ui.JDateTime;
|
|
|
18 |
import org.openconcerto.ui.component.ComboLockedMode;
|
|
|
19 |
import org.openconcerto.ui.component.ITextArea;
|
|
|
20 |
import org.openconcerto.ui.group.Group;
|
|
|
21 |
import org.openconcerto.utils.ExceptionHandler;
|
|
|
22 |
|
|
|
23 |
public class CustomerSupportTicketSQLComponent extends GroupSQLComponent {
|
|
|
24 |
public CustomerSupportTicketSQLComponent(SQLElement element, Group group) {
|
|
|
25 |
super(element, group);
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
@Override
|
|
|
29 |
protected Set<String> createRequiredNames() {
|
|
|
30 |
final Set<String> s = new HashSet<String>(1);
|
|
|
31 |
s.add("ID_CLIENT");
|
|
|
32 |
s.add("ID_USER_COMMON");
|
|
|
33 |
s.add("LABEL");
|
|
|
34 |
s.add("DATE");
|
|
|
35 |
s.add("STATUS");
|
|
|
36 |
return s;
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
@Override
|
|
|
40 |
public int insert(SQLRow order) {
|
|
|
41 |
|
|
|
42 |
int id = super.insert(order);
|
|
|
43 |
SQLRow row = getTable().getRow(id);
|
|
|
44 |
try {
|
|
|
45 |
final SQLRowValues createEmptyUpdateRow = row.createEmptyUpdateRow();
|
|
|
46 |
createEmptyUpdateRow.put("NUMBER", id);
|
|
|
47 |
if (row.getObject("DATE") == null) {
|
|
|
48 |
createEmptyUpdateRow.put("DATE", new Date());
|
|
|
49 |
}
|
|
|
50 |
SQLRowValues rowValsHisto = new SQLRowValues(getTable().getTable(Module.TABLE_CUSTOMER_SUPPORT_TICKET_HISTORY));
|
|
|
51 |
rowValsHisto.put("INFORMATION", "Ouverture du ticket");
|
183 |
ilm |
52 |
// rowValsHisto.put("DATE", row.getObject("DATE"));
|
147 |
ilm |
53 |
rowValsHisto.put("ID_USER_COMMON", row.getForeignID("ID_USER_COMMON"));
|
|
|
54 |
rowValsHisto.put("ID_" + getTable().getName(), createEmptyUpdateRow);
|
|
|
55 |
createEmptyUpdateRow.commit();
|
|
|
56 |
} catch (SQLException e) {
|
|
|
57 |
ExceptionHandler.handle("Impossible d'affecter un numéro sur le ticket", e);
|
|
|
58 |
}
|
|
|
59 |
return id;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
@Override
|
|
|
63 |
public JComponent createEditor(String id) {
|
|
|
64 |
|
|
|
65 |
if (id.equals("INFOS")) {
|
|
|
66 |
final ITextArea jTextArea = new ITextArea();
|
|
|
67 |
jTextArea.setFont(new JLabel().getFont());
|
|
|
68 |
jTextArea.setRows(3);
|
|
|
69 |
return jTextArea;
|
|
|
70 |
} else if (id.equals("TYPE") || id.equals("STATUS") || id.equals("RATING")) {
|
|
|
71 |
return new SQLSearchableTextCombo(ComboLockedMode.UNLOCKED, 1, 20, false);
|
|
|
72 |
} else if (id.equals("DATE")) {
|
|
|
73 |
return new JDateTime(true);
|
|
|
74 |
}
|
|
|
75 |
return super.createEditor(id);
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
@Override
|
|
|
79 |
protected SQLRowValues createDefaults() {
|
|
|
80 |
SQLRowValues rowVals = new SQLRowValues(getTable());
|
|
|
81 |
rowVals.put("STATUS", "Nouveau");
|
|
|
82 |
rowVals.put("RATING", "Normale");
|
|
|
83 |
|
|
|
84 |
final int idUser = UserManager.getInstance().getCurrentUser().getId();
|
|
|
85 |
rowVals.put("ID_USER_COMMON", idUser);
|
|
|
86 |
|
|
|
87 |
return rowVals;
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
}
|