editing price categories
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 16 May 2010 16:02:26 +0000 (16:02 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 16 May 2010 16:02:26 +0000 (16:02 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@460 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/dialogs/pricecatdlg.cpp
src/dialogs/pricecatdlg.h
src/mwin/eventstab.cpp
src/mwin/eventstab.h
src/mwin/overview.cpp
wob/event.wolf
www/inc/wext/price.php

index 211712c..636ae33 100644 (file)
@@ -20,7 +20,7 @@
 #include <QMessageBox>
 #include <QPushButton>
 
-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
+       QList<QListWidgetItem*>wlst=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;
+}
index 79af960..45edb6a 100644 (file)
@@ -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
index 2b37409..b57b1fd 100644 (file)
@@ -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();
+}
index bda4bdf..a34d4c5 100644 (file)
@@ -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;}
index 8404d2a..00c8616 100644 (file)
 //
 //
 
+#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"
 
index b3a6c01..ff8203d 100644 (file)
                        <Var name="pricecategory" type="PriceCategory">properties as actually stored</Var>
                </Output>
        </Transaction>
+       <Transaction name="ChangePriceCategory">
+               <Input>
+                       <Var name="pricecategory" type="PriceCategory">properties as requested by user</Var>
+               </Input>
+               <Call lang="php" method="WOPriceCategory::changeCategory($this);"/>
+               <Output>
+                       <Var name="pricecategory" type="PriceCategory">properties as actually stored</Var>
+               </Output>
+       </Transaction>
        
        <Class name="EventPrice">
                <Abstract lang="php"/>
index d1a4bb7..6f89c52 100644 (file)
@@ -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