From: konrad Date: Sun, 16 May 2010 16:02:26 +0000 (+0000) Subject: editing price categories X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=87f747c5a6a9a91a1a673ce8fb6d174c500d2fbe;p=web%2Fkonrad%2Fsmoke.git editing price categories git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@460 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/src/dialogs/pricecatdlg.cpp b/src/dialogs/pricecatdlg.cpp index 211712c..636ae33 100644 --- a/src/dialogs/pricecatdlg.cpp +++ b/src/dialogs/pricecatdlg.cpp @@ -20,7 +20,7 @@ #include #include -MPriceCategoryDialog::MPriceCategoryDialog(QWidget*pw) +MPriceCategoryDialog::MPriceCategoryDialog(QWidget*pw,bool showselect) :QDialog(pw) { m_cat=req->queryGetAllPriceCategories().getpricecategories(); @@ -39,11 +39,19 @@ MPriceCategoryDialog::MPriceCategoryDialog(QWidget*pw) QPushButton*p; hl->addWidget(p=new QPushButton(tr("New...","new price category")),0); connect(p,SIGNAL(clicked()),this,SLOT(newCat())); - p->setEnabled(req->hasRight(req->RCreateArtist)); - hl->addWidget(p=new QPushButton(tr("Select","select price category")),0); - connect(p,SIGNAL(clicked()),this,SLOT(accept())); - hl->addWidget(p=new QPushButton(tr("Cancel")),0); - connect(p,SIGNAL(clicked()),this,SLOT(reject())); + p->setEnabled(req->hasRight(req->RCreatePriceCategory)); + hl->addWidget(p=new QPushButton(tr("Edit...","edit price category")),0); + connect(p,SIGNAL(clicked()),this,SLOT(editCat())); + p->setEnabled(req->hasRight(req->RChangePriceCategory)); + if(showselect){ + hl->addWidget(p=new QPushButton(tr("Select","select price category")),0); + connect(p,SIGNAL(clicked()),this,SLOT(accept())); + hl->addWidget(p=new QPushButton(tr("Cancel")),0); + connect(p,SIGNAL(clicked()),this,SLOT(reject())); + }else{ + hl->addWidget(p=new QPushButton(tr("Close")),0); + connect(p,SIGNAL(clicked()),this,SLOT(reject())); + } } MOPriceCategory MPriceCategoryDialog::selection()const @@ -54,34 +62,24 @@ MOPriceCategory MPriceCategoryDialog::selection()const return m_cat[wlst[0]->data(Qt::UserRole).toInt()]; } +/**helper class: edit a price category*/ +class MPCDEdit:public QDialog +{ + public: + MPCDEdit(QWidget*,const MOPriceCategory&); + MOPriceCategory result()const; + private: + MOPriceCategory cat; + QLineEdit*name,*abbr; +}; + void MPriceCategoryDialog::newCat() { - //TODO: remaining properties - //dialog - QDialog d; - d.setWindowTitle(tr("New Price Category")); - QVBoxLayout*vl; - d.setLayout(vl=new QVBoxLayout); - QFormLayout*fl; - vl->addLayout(fl=new QFormLayout,1); - QLineEdit*name,*abbr; - fl->addRow(tr("Category Name:"),name=new QLineEdit); - fl->addRow(tr("Category Abbreviation:"),abbr=new QLineEdit); - vl->addSpacing(10); - QHBoxLayout*hl; - vl->addLayout(hl=new QHBoxLayout,0); - hl->addStretch(10); - QPushButton*p; - hl->addWidget(p=new QPushButton(tr("Create")),0); - connect(p,SIGNAL(clicked()),&d,SLOT(accept())); - hl->addWidget(p=new QPushButton(tr("Cancel")),0); - connect(p,SIGNAL(clicked()),&d,SLOT(reject())); + MPCDEdit d(this,MOPriceCategory()); //ask if(d.exec()!=QDialog::Accepted)return; //get props, create cat - MOPriceCategory cat; - cat.setname(name->text()); - cat.setabbreviation(abbr->text()); + MOPriceCategory cat=d.result(); MTCreatePriceCategory cpc=req->queryCreatePriceCategory(cat); if(cpc.hasError()){ QMessageBox::warning(this,tr("Warning"),tr("Error while creating new price category: %1").arg(cpc.errorString())); @@ -95,3 +93,58 @@ void MPriceCategoryDialog::newCat() m_list->addItem(it); m_list->setCurrentItem(it); } + +void MPriceCategoryDialog::editCat() +{ + //get current + QListwlst=m_list->selectedItems(); + if(wlst.size()<1)return; + //ask + int pcidx=wlst[0]->data(Qt::UserRole).toInt(); + MPCDEdit d(this,m_cat[pcidx]); + if(d.exec()!=QDialog::Accepted)return; + //get props, create cat + MOPriceCategory cat=d.result(); + MTChangePriceCategory cpc=req->queryChangePriceCategory(cat); + if(cpc.hasError()){ + QMessageBox::warning(this,tr("Warning"),tr("Error while creating new price category: %1").arg(cpc.errorString())); + return; + } + //add and select + cat=cpc.getpricecategory(); + m_cat[pcidx]=cat; + wlst[0]->setText(cat.name()); +} + + + +MPCDEdit::MPCDEdit(QWidget*par,const MOPriceCategory&c) + :QDialog(par),cat(c) +{ + //TODO: remaining properties + //dialog + bool b=cat.pricecategoryid().isNull(); + setWindowTitle(b?tr("New Price Category"):tr("Change Price Category")); + QVBoxLayout*vl; + setLayout(vl=new QVBoxLayout); + QFormLayout*fl; + vl->addLayout(fl=new QFormLayout,1); + fl->addRow(tr("Category Name:"),name=new QLineEdit(cat.name())); + fl->addRow(tr("Category Abbreviation:"),abbr=new QLineEdit(cat.abbreviation())); + vl->addSpacing(10); + QHBoxLayout*hl; + vl->addLayout(hl=new QHBoxLayout,0); + hl->addStretch(10); + QPushButton*p; + hl->addWidget(p=new QPushButton(b?tr("Create"):tr("Save")),0); + connect(p,SIGNAL(clicked()),this,SLOT(accept())); + hl->addWidget(p=new QPushButton(tr("Cancel")),0); + connect(p,SIGNAL(clicked()),this,SLOT(reject())); +} +MOPriceCategory MPCDEdit::result()const +{ + MOPriceCategory rcat(cat); + rcat.setname(name->text()); + rcat.setabbreviation(abbr->text()); + return rcat; +} diff --git a/src/dialogs/pricecatdlg.h b/src/dialogs/pricecatdlg.h index 79af960..45edb6a 100644 --- a/src/dialogs/pricecatdlg.h +++ b/src/dialogs/pricecatdlg.h @@ -24,7 +24,7 @@ class MPriceCategoryDialog:public QDialog { Q_OBJECT public: - MPriceCategoryDialog(QWidget*p=0); + MPriceCategoryDialog(QWidget*p=0,bool showselect=true); /**returns the current selection*/ MOPriceCategory selection()const; @@ -34,6 +34,8 @@ class MPriceCategoryDialog:public QDialog private slots: /**internal: called to create a new category*/ void newCat(); + /**internal: called to change a category*/ + void editCat(); }; #endif diff --git a/src/mwin/eventstab.cpp b/src/mwin/eventstab.cpp index 2b37409..b57b1fd 100644 --- a/src/mwin/eventstab.cpp +++ b/src/mwin/eventstab.cpp @@ -16,6 +16,7 @@ #include "main.h" #include "misc.h" #include "msinterface.h" +#include "pricecatdlg.h" #include "eventstab.h" @@ -95,6 +96,8 @@ QMenu*MEventsTab::menu() showoldevents->setEnabled(req->hasRight(req->RGetAllEvents)); showoldevents->setCheckable(true); showoldevents->setChecked(QSettings().value("profiles/"+profilekey+"/showOldEvents",false).toBool()); + m->addSeparator(); + m->addAction(tr("&Edit Price Categories..."),this,SLOT(editPriceCat())); return m; } @@ -226,3 +229,8 @@ QString MEventsTab::currentEventStart()const if(ilst.size()<1)return ""; return eventmodel->data(eventmodel->index(ilst[0].row(),0)).toString(); } + +void MEventsTab::editPriceCat() +{ + MPriceCategoryDialog(this,false).exec(); +} diff --git a/src/mwin/eventstab.h b/src/mwin/eventstab.h index bda4bdf..a34d4c5 100644 --- a/src/mwin/eventstab.h +++ b/src/mwin/eventstab.h @@ -54,6 +54,8 @@ class MEventsTab:public QWidget void eventSummary(); /**cancel the event*/ void eventCancel(); + /**edit price categories*/ + void editPriceCat(); public slots: /**returns event table model*/ QStandardItemModel*eventModel(){return eventmodel;} diff --git a/src/mwin/overview.cpp b/src/mwin/overview.cpp index 8404d2a..00c8616 100644 --- a/src/mwin/overview.cpp +++ b/src/mwin/overview.cpp @@ -10,19 +10,19 @@ // // +#include "customerdlg.h" #include "main.h" #include "msinterface.h" #include "passwdchg.h" -#include "customerdlg.h" -#include "templatedlg.h" #include "shipping.h" +#include "templatedlg.h" -#include "overview.h" -#include "eventstab.h" +#include "aclwin.h" #include "carttab.h" -#include "orderstab.h" #include "entrancetab.h" -#include "aclwin.h" +#include "eventstab.h" +#include "orderstab.h" +#include "overview.h" #include "centbox.h" diff --git a/wob/event.wolf b/wob/event.wolf index b3a6c01..ff8203d 100644 --- a/wob/event.wolf +++ b/wob/event.wolf @@ -153,6 +153,15 @@ properties as actually stored + + + properties as requested by user + + + + properties as actually stored + + diff --git a/www/inc/wext/price.php b/www/inc/wext/price.php index d1a4bb7..6f89c52 100644 --- a/www/inc/wext/price.php +++ b/www/inc/wext/price.php @@ -30,6 +30,26 @@ class WOPriceCategory extends WOPriceCategoryAbstract //return $trans->setpricecategory(WOPriceCategory::fromTablepricecategory($tab)); } + /**called from ChangePriceCategory transaction*/ + static public function changeCategory($trans) + { + $cat=$trans->getpricecategory(); + if(!is_a($cat,"WOPriceCategory")){ + $trans->abortWithError(tr("Category must be a valid object.")); + return; + } + //TODO: verify that name and abbrev. are unique + //convert + $tab=WTpricecategory::getFromDB($cat->getpricecategoryid()); + if($tab===false){ + $trans->abortWithError(tr("Category does not exist.")); + return; + } + $cat->toTablepricecategory($tab); + $tab->update(); + //return + $trans->setpricecategory(WOPriceCategory::fromTablepricecategory($tab)); + } }; ?> \ No newline at end of file