1 | # -*- coding: utf-8 -*-
|
---|
2 | # $Id: wuiadminglobalrsrc.py 69111 2017-10-17 14:26:02Z vboxsync $
|
---|
3 |
|
---|
4 | """
|
---|
5 | Test Manager WUI - Global resources.
|
---|
6 | """
|
---|
7 |
|
---|
8 | __copyright__ = \
|
---|
9 | """
|
---|
10 | Copyright (C) 2012-2017 Oracle Corporation
|
---|
11 |
|
---|
12 | This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
13 | available from http://www.virtualbox.org. This file is free software;
|
---|
14 | you can redistribute it and/or modify it under the terms of the GNU
|
---|
15 | General Public License (GPL) as published by the Free Software
|
---|
16 | Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
17 | VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
18 | hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
19 |
|
---|
20 | The contents of this file may alternatively be used under the terms
|
---|
21 | of the Common Development and Distribution License Version 1.0
|
---|
22 | (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
23 | VirtualBox OSE distribution, in which case the provisions of the
|
---|
24 | CDDL are applicable instead of those of the GPL.
|
---|
25 |
|
---|
26 | You may elect to license modified versions of this file under the
|
---|
27 | terms and conditions of either the GPL or the CDDL or both.
|
---|
28 | """
|
---|
29 | __version__ = "$Revision: 69111 $"
|
---|
30 |
|
---|
31 | # Validation Kit imports.
|
---|
32 | from testmanager.webui.wuibase import WuiException
|
---|
33 | from testmanager.webui.wuicontentbase import WuiContentBase
|
---|
34 | from testmanager.webui.wuihlpform import WuiHlpForm
|
---|
35 | from testmanager.core.globalresource import GlobalResourceData
|
---|
36 | from testmanager.webui.wuicontentbase import WuiListContentBase, WuiTmLink
|
---|
37 |
|
---|
38 |
|
---|
39 | class WuiGlobalResource(WuiContentBase):
|
---|
40 | """
|
---|
41 | WUI global resources content generator.
|
---|
42 | """
|
---|
43 |
|
---|
44 | def __init__(self, oData, fnDPrint = None):
|
---|
45 | """
|
---|
46 | Do necessary initializations
|
---|
47 | """
|
---|
48 | WuiContentBase.__init__(self, fnDPrint)
|
---|
49 | self._oData = oData
|
---|
50 |
|
---|
51 | def showAddModifyPage(self, sAction, dErrors = None):
|
---|
52 | """
|
---|
53 | Render add global resource HTML form.
|
---|
54 | """
|
---|
55 | from testmanager.webui.wuiadmin import WuiAdmin
|
---|
56 |
|
---|
57 | sFormActionUrl = '%s?%s=%s' % (WuiAdmin.ksScriptName,
|
---|
58 | WuiAdmin.ksParamAction, sAction)
|
---|
59 | if sAction == WuiAdmin.ksActionGlobalRsrcAdd:
|
---|
60 | sTitle = 'Add Global Resource'
|
---|
61 | elif sAction == WuiAdmin.ksActionGlobalRsrcEdit:
|
---|
62 | sTitle = 'Modify Global Resource'
|
---|
63 | sFormActionUrl += '&%s=%s' % (GlobalResourceData.ksParam_idGlobalRsrc, self._oData.idGlobalRsrc)
|
---|
64 | else:
|
---|
65 | raise WuiException('Invalid paraemter "%s"' % (sAction,))
|
---|
66 |
|
---|
67 | oForm = WuiHlpForm('globalresourceform',
|
---|
68 | sFormActionUrl,
|
---|
69 | dErrors if dErrors is not None else dict())
|
---|
70 |
|
---|
71 | if sAction == WuiAdmin.ksActionGlobalRsrcAdd:
|
---|
72 | oForm.addIntRO (GlobalResourceData.ksParam_idGlobalRsrc, self._oData.idGlobalRsrc, 'Global Resource ID')
|
---|
73 | oForm.addTimestampRO(GlobalResourceData.ksParam_tsEffective, self._oData.tsEffective, 'Last changed')
|
---|
74 | oForm.addTimestampRO(GlobalResourceData.ksParam_tsExpire, self._oData.tsExpire, 'Expires (excl)')
|
---|
75 | oForm.addIntRO (GlobalResourceData.ksParam_uidAuthor, self._oData.uidAuthor, 'Changed by UID')
|
---|
76 | oForm.addText (GlobalResourceData.ksParam_sName, self._oData.sName, 'Name')
|
---|
77 | oForm.addText (GlobalResourceData.ksParam_sDescription, self._oData.sDescription, 'Description')
|
---|
78 | oForm.addCheckBox (GlobalResourceData.ksParam_fEnabled, self._oData.fEnabled, 'Enabled')
|
---|
79 |
|
---|
80 | oForm.addSubmit('Submit')
|
---|
81 |
|
---|
82 | return (sTitle, oForm.finalize())
|
---|
83 |
|
---|
84 |
|
---|
85 | class WuiGlobalResourceList(WuiListContentBase):
|
---|
86 | """
|
---|
87 | WUI Content Generator.
|
---|
88 | """
|
---|
89 |
|
---|
90 | def __init__(self, aoEntries, iPage, cItemsPerPage, tsEffective, fnDPrint, oDisp, aiSelectedSortColumns = None):
|
---|
91 | WuiListContentBase.__init__(self, aoEntries, iPage, cItemsPerPage, tsEffective,
|
---|
92 | sTitle = 'Global Resources', sId = 'globalResources',
|
---|
93 | fnDPrint = fnDPrint, oDisp = oDisp, aiSelectedSortColumns = aiSelectedSortColumns);
|
---|
94 |
|
---|
95 | self._asColumnHeaders = ['ID', 'Name', 'Description', 'Enabled', 'Actions' ]
|
---|
96 | self._asColumnAttribs = ['align="right"', 'align="center"', 'align="center"',
|
---|
97 | 'align="center"', 'align="center"']
|
---|
98 |
|
---|
99 | def _formatListEntry(self, iEntry):
|
---|
100 | from testmanager.webui.wuiadmin import WuiAdmin
|
---|
101 | oEntry = self._aoEntries[iEntry]
|
---|
102 |
|
---|
103 | aoActions = [ ];
|
---|
104 | if self._oDisp is None or not self._oDisp.isReadOnlyUser():
|
---|
105 | aoActions += [
|
---|
106 | WuiTmLink('Modify', WuiAdmin.ksScriptName,
|
---|
107 | { WuiAdmin.ksParamAction: WuiAdmin.ksActionGlobalRsrcShowEdit,
|
---|
108 | GlobalResourceData.ksParam_idGlobalRsrc: oEntry.idGlobalRsrc }),
|
---|
109 | WuiTmLink('Remove', WuiAdmin.ksScriptName,
|
---|
110 | { WuiAdmin.ksParamAction: WuiAdmin.ksActionGlobalRsrcDel,
|
---|
111 | GlobalResourceData.ksParam_idGlobalRsrc: oEntry.idGlobalRsrc },
|
---|
112 | sConfirm = 'Are you sure you want to remove global resource #%d?' % (oEntry.idGlobalRsrc,)),
|
---|
113 | ];
|
---|
114 |
|
---|
115 | return [ oEntry.idGlobalRsrc,
|
---|
116 | oEntry.sName,
|
---|
117 | oEntry.sDescription,
|
---|
118 | oEntry.fEnabled,
|
---|
119 | aoActions, ];
|
---|
120 |
|
---|