7 #include <Wt/WApplication>
12 #include <Wt/WIntValidator>
13 #include <Wt/WRegExpValidator>
15 #include <gdcore/gdCore.h>
24 : WContainerWidget(parent), m_pNode(pNode), m_ml(rMl), m_pAuthor(0), m_pShortDescEditor(0), m_pShortDescTextArea(0), m_pCBInMenu(0), m_pCBInView(0), m_pFhtmlEditor(0), m_pInitPage(0), m_bUseTextArea(true), m_pSave(0), m_pLock(0), m_pTimer(0), m_pTimerTick(0), m_timeLockLeft(0)
27 if ( WString::tr(
"byObjectStyleSheet").narrow() ==
"true" )
28 wApp->useStyleSheet(wApp->theme()->resourcesUrl() +
"wittyshare/Css/WsFormConfig.css");
29 addStyleClass(
"WsFormConfig");
52 WTable* pTable =
new WTable();
56 WDateTime dt(WDateTime::currentDateTime());
57 std::string sDateTime = pNode.get()->getProperties().get()->get(
"global",
"publish_date", boost::lexical_cast<std::string>(dt.toTime_t()));
58 m_wDateTime.setTime_t(boost::lexical_cast<time_t>(sDateTime));
59 Wt::WRegExpValidator* validatorName =
new Wt::WRegExpValidator(
"[a-zA-Z0-9._& ]{2,48}");
60 new WText(
"(new ?) name", pTable->elementAt(iRow, 0));
61 m_sName = pNode.get()->getName();
62 m_pName =
new WLineEdit(WString::fromUTF8(m_sName), pTable->elementAt(iRow, 2));
63 m_pName->setValidator(validatorName);
65 if ( pNode.get()->isDirectory() ) {
66 new WText(
"Initial page", pTable->elementAt(iRow, 4));
67 m_sInitPage = pNode.get()->getProperties().get()->get(
"global",
"initial_page",
"");
68 m_pInitPage =
new WLineEdit(WString::fromUTF8(m_sInitPage), pTable->elementAt(iRow, 6));
72 new WText(
"Publish Date", pTable->elementAt(iRow, 0));
74 m_pDatePicker->setFormat(
"yyyy-MM-dd");
77 new WText(
"Display name", pTable->elementAt(iRow, 4));
80 m_pDisplayName =
new WLineEdit(WString::fromUTF8(m_sDisplayName), pTable->elementAt(iRow, 6));
85 m_sAuthor = pNode.get()->getProperties().get()->get(
"global",
"author", curUser);
86 new WText(
"Author", pTable->elementAt(iRow, 0));
88 m_pAuthor->setTextSize(30);
89 std::string sSortNumber = pNode.get()->getProperties().get()->get(
"global",
"sort_number",
"-1");
90 new WText(
"Sort Number", pTable->elementAt(iRow, 4));
92 m_pSortNumber =
new WLineEdit(WString::fromUTF8(sSortNumber), pTable->elementAt(iRow, 6));
93 m_pSortNumber->setTextSize(10);
94 WIntValidator* validator =
new WIntValidator(-1, 9999);
95 validator->setMandatory(
true);
96 m_pSortNumber->setValidator(validator);
98 m_pCBInheritRights =
new WCheckBox(
"Inherit parent rights", pTable->elementAt(iRow, 0));
99 std::string sInheritRights = pNode.get()->getProperties().get()->get(
"global",
"inherit_rights_from_parent",
"false");
100 if ( sInheritRights ==
"true" )
103 m_pCBInMenu =
new WCheckBox(
"In menu", pTable->elementAt(iRow, 2));
105 std::string sInMenu = pNode.get()->getProperties().get()->get(
"global",
"in_menu",
"false");
106 if ( sInMenu ==
"true" )
109 std::string sSort = pNode.get()->getProperties().get()->get(
"global",
"sort",
"false");
110 m_pCBSort =
new WCheckBox(
"Sort", pTable->elementAt(iRow, 4));
111 if ( sSort ==
"true" )
114 m_pCBInView =
new WCheckBox(
"In view", pTable->elementAt(iRow, 6));
115 std::string sInView = pNode.get()->getProperties().get()->get(
"global",
"in_view",
"true");
116 if ( sInView ==
"true" )
120 new WText(
"Template", pTable->elementAt(iRow, 0));
122 std::string sTemplate = pNode.get()->getProperties().get()->get(
"global",
"template",
"stdSubPage.tpl");
124 std::vector<std::string> vTemplates;
125 vTemplates.push_back(
"root.tpl");
126 vTemplates.push_back(
"stdSubPage.tpl");
127 for (
int countTemplates = 0; countTemplates < vTemplates.size(); ++countTemplates) {
128 m_pCBBTemplates->addItem(vTemplates[countTemplates]);
129 if ( vTemplates[countTemplates] == sTemplate ) {
130 m_pCBBTemplates->setCurrentIndex(countTemplates);
135 m_sShortDesc = pNode.get()->getProperties().get()->get(
"global",
"short_description",
"");
146 WPushButton* pButCancel =
new WPushButton(
"Cancel");
148 addWidget(pButCancel);
149 m_pSave =
new WPushButton(
"Save");
151 if (!pNode->isDirectory()) {
152 m_pLock =
new WPushButton(
"Extend the lock");
158 WContainerWidget* pCW =
new WContainerWidget();
159 pCW->addWidget(pTable);
160 pCW->addWidget(
new WText(
"<b>Short Description</b>"));
165 std::string title =
"Properties of " + pNode.get()->getPath().string();
166 WPanel* pPanel =
new WPanel();
167 pPanel->setTitle(title);
168 pPanel->setCentralWidget(pCW);
169 pPanel->setCollapsible(
true);
174 for (
int iModule = 0; iModule <
m_ml.
modules().size(); iModule++) {
176 if ( !curModule->
isLoaded() )
continue;
180 WPanel* pPanel2 =
new WPanel();
182 pPanel2->setCentralWidget(w);
183 pPanel2->setCollapsible(
true);
185 pCW->addWidget(pPanel2);
201 wApp->setInternalPath(
m_pNode->getPath().string(),
true);
213 WsApp->wsUser()->isLocked(
m_pNode->getPath().string(), id);
214 addWidget(
new WText(
"<font color='red'>The file is currently locked by \"" +
id +
"\". Please try again later</font>"));
244 WMessageBox::show(
"Warning",
"The file lock is released. Please copy your data and refresh the page to continue editing", Ok);
251 std::string tl = boost::lexical_cast<std::string>(
m_timeLockLeft / 60);
252 m_pSave->setText(
"Save..(" + tl +
" min left)");
265 if ( !
m_pName->validate() )
return;
267 bool bUpdated =
false;
268 WDateTime dt(
m_pDatePicker->date(), WTime::currentServerTime());
269 std::string sDateTime = dt.toString(
"yyyy-MM-dd hh:mm:ss").narrow();
270 std::string sName =
m_pName->text().toUTF8();
271 if ( sName.size() < 2 )
return;
272 std::string sInitPage =
"";
276 std::string sAuthor =
m_pAuthor->text().toUTF8();
277 std::string sInMenu = (
m_pCBInMenu->checkState() == Wt::Checked ?
"true" :
"false");
278 std::string sInView = (
m_pCBInView->checkState() == Wt::Checked ?
"true" :
"false");
279 std::string sShortDesc;
284 std::string sSort = (
m_pCBSort->checkState() == Wt::Checked ?
"true" :
"false");
286 std::string sInheritRights = (
m_pCBInheritRights->checkState() == Wt::Checked ?
"true" :
"false");
288 gdcore_string_erase_right(sDisplayName,
' ');
289 gdcore_string_erase_left(sDisplayName,
' ');
290 gdcore_string_erase_right(sAuthor,
' ');
291 gdcore_string_erase_left(sAuthor,
' ');
297 m_pNode->getProperties().get()->set(
"global",
"publish_date", boost::lexical_cast<std::string>(dt.toTime_t()));
300 if (
m_pNode->isDirectory() ) {
302 m_pNode->getProperties().get()->set(
"global",
"initial_page", sInitPage);
306 m_pNode->getProperties().get()->set(
"global",
"display_name", sDisplayName);
310 m_pNode->getProperties().get()->set(
"global",
"author", sAuthor);
314 m_pNode->getProperties().get()->set(
"global",
"in_menu", sInMenu);
318 m_pNode->getProperties().get()->set(
"global",
"in_view", sInView);
322 m_pNode->getProperties().get()->set(
"global",
"template", sTemplate);
326 m_pNode->getProperties().get()->set(
"global",
"short_description", sShortDesc);
330 m_pNode->getProperties().get()->set(
"global",
"sort", sSort);
333 if (
m_lSortNumber != boost::lexical_cast<long>(sSortNumber) ) {
334 m_pNode->getProperties().get()->set(
"global",
"sort_number", sSortNumber);
338 m_pNode->getProperties().get()->set(
"global",
"inherit_rights_from_parent", sInheritRights);
344 wApp->log(
"notice") <<
"WsFormConfig::doSave() fhtml file = " <<
m_pNode->getFullPath();
346 wApp->log(
"notice") <<
"WsFormConfig::doSave() cannot open " <<
m_pNode->getFullPath();
348 std::string oldName =
m_pNode->getPath().string();
349 std::string newName =
m_pNode->getPath().parent_path().string();
350 if ( newName !=
"/" ) newName +=
"/";
352 wApp->log(
"notice") <<
"WsFormConfig::doSave() rename oldName = " << oldName <<
" newName " << newName;
357 wApp->setInternalPath(newName,
true);
boost::shared_ptr< WsAbstractNode > NodePtr
int getPermissions(const std::string &p)
return the permissions on specific node
const std::vector< WsModuleLoader * > & modules()
int saveProperties(WsNodeProperties *props, const std::string &path)
save the properties of the node on disk. The user must have access and edit rights for the node...
int writeFile(const std::string path, const std::string &text)
writes the text to the file
virtual WsEditorWidget * createEditor(Wt::WContainerWidget *parent=0) const =0
Create the contents for an editor (create a view of options).
Interface that provides differents methods for accessing the FsTree as well as other features...
const std::string & moduleName() const
const std::string & getFirstName() const
return the name of the person
const std::string & getSurname() const
return the surname of the person
#define WsApp
Define a shortcut to the application instance.
int renameNode(const string &path, const string &newPath)
renames a node In case of a WsDirNode, all the contents of the directory and the directory will be mo...