From 2f981e42e5307f4bad045149eb28a6fa5248bd8d Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Tue, 30 Jul 2013 19:50:05 -0500 Subject: [PATCH] Adding projectrequest files --- indefero/src/IDF/Form/ProjectRequest.php | 72 ++++++++++++++++ indefero/src/IDF/ProjectRequest.php | 85 +++++++++++++++++++ .../templates/idf/admin/approveprojects.html | 60 +++++++++++++ .../IDF/templates/idf/admin/request-email.txt | 10 +++ .../templates/idf/user/projectrequest.html | 60 +++++++++++++ 5 files changed, 287 insertions(+) create mode 100644 indefero/src/IDF/Form/ProjectRequest.php create mode 100644 indefero/src/IDF/ProjectRequest.php create mode 100644 indefero/src/IDF/templates/idf/admin/approveprojects.html create mode 100644 indefero/src/IDF/templates/idf/admin/request-email.txt create mode 100644 indefero/src/IDF/templates/idf/user/projectrequest.html diff --git a/indefero/src/IDF/Form/ProjectRequest.php b/indefero/src/IDF/Form/ProjectRequest.php new file mode 100644 index 0000000..782cd6c --- /dev/null +++ b/indefero/src/IDF/Form/ProjectRequest.php @@ -0,0 +1,72 @@ + __('git'), + 'svn' => __('Subversion'), + 'mercurial' => __('mercurial'), + 'mtn' => __('monotone'), + ); + foreach (Pluf::f('allowed_scm', array()) as $key => $class) { + $choices[$options[$key]] = $key; + } + + $this->fields['shortname'] = new Pluf_Form_Field_Varchar( + array('required' => true, + 'label' => __('Name'), + 'initial' => '', + 'help_text' => __('This will be the name of your repo and of your project - however - you can change the project name later.'), + )); + + $this->fields['repotype'] = new Pluf_Form_Field_Varchar( + array('required' => true, + 'label' => __('Repository type'), + 'initial' => 'git', + 'widget_attrs' => array('choices' => $choices), + 'widget' => 'Pluf_Form_Widget_SelectInput', + )); + + $this->fields['desc'] = new Pluf_Form_Field_Varchar( + array('required' => true, + 'label' => __('Short description'), + 'help_text' => __('A one line description of the project.'), + 'initial' => '', + 'widget_attrs' => array('size' => '35'), + )); + + $this->user = $extra['user']; + } + + + function save($commit=true) + { + if (!$this->isValid()) { + throw new Exception(__('Cannot save the model from an invalid form.')); + } + + $checksql = new Pluf_SQL(sprintf("shortname='%s'", $this->cleaned_data['shortname'])); + $requestcheck = Pluf::factory("IDF_Project")->getCount(array('filter'=>$checksql->gen())); + if ($requestcheck == 1) + return false; + try + { + $request = new IDF_ProjectRequest(); + $request->shortname = $this->cleaned_data['shortname']; + $request->repotype = $this->cleaned_data['repotype']; + $request->desc = $this->cleaned_data['desc']; + $request->submitter = $this->user; + $request->create(); + return true; + } catch (Exception $e) + { + return false; + } + } + +} \ No newline at end of file diff --git a/indefero/src/IDF/ProjectRequest.php b/indefero/src/IDF/ProjectRequest.php new file mode 100644 index 0000000..3301ea5 --- /dev/null +++ b/indefero/src/IDF/ProjectRequest.php @@ -0,0 +1,85 @@ +_a['table'] = 'idf_projectrequest'; + $this->_a['model'] = __CLASS__; + + $this->_a['cols'] = array( + // It is mandatory to have an "id" column. + 'id' => + array( + 'type' => 'Pluf_DB_Field_Sequence', + 'blank' => true, + ), + 'shortname' => + array( + 'type' => 'Pluf_DB_Field_Varchar', + 'blank' => false, + 'size' => 50, + 'verbose' => __('shortname'), + 'unique' => true, + ), + 'repotype' => + array( + 'type' => 'Pluf_DB_Field_Varchar', + 'blank' => false, + 'size' => 25, + 'verbose' => __('Repository Type'), + ), + 'desc' => + array( + 'type' => 'Pluf_DB_Field_Varchar', + 'blank' => false, + 'size' => 250, + 'verbose' => __('Description'), + ), + 'creation_dtime' => + array( + 'type' => 'Pluf_DB_Field_Datetime', + 'blank' => true, + 'verbose' => __('creation date'), + ), + 'submitter' => + array( + 'type' => 'Pluf_DB_Field_Foreignkey', + 'model' => 'Pluf_User', + 'blank' => false, + 'verbose' => __('submitter'), + )); + } + + /** + * String representation of the abstract. + */ + function __toString() + { + return $this->shortname; + } + + /** + * String ready for indexation. + */ + function _toIndex() + { + return ''; + } + + function preSave($create=false) + { + if ($this->id == '') { + $this->creation_dtime = gmdate('Y-m-d H:i:s'); + } + + } +} \ No newline at end of file diff --git a/indefero/src/IDF/templates/idf/admin/approveprojects.html b/indefero/src/IDF/templates/idf/admin/approveprojects.html new file mode 100644 index 0000000..77dcd28 --- /dev/null +++ b/indefero/src/IDF/templates/idf/admin/approveprojects.html @@ -0,0 +1,60 @@ +{extends "idf/gadmin/base.html"} +{block request} class="active"{/block} + +{block body} +{if $createdtext} +{$createdtext} +
+
+{/if} +{if $errors} +{foreach $errors as $error} +{$error} +{/foreach} +{/if} + + + + + + + + + +{foreach $requests as $req} + + + + + + + + +{/foreach} +
+ Short Name + + Description + + Repotype + + Submitter + + Date + + Approve +
+ {$req.shortname} + + {$req.desc} + + {$req.repotype} + + {$req.get_submitter.login} + + {$req.creation_dtime} + + Approve +
+ +{/block} \ No newline at end of file diff --git a/indefero/src/IDF/templates/idf/admin/request-email.txt b/indefero/src/IDF/templates/idf/admin/request-email.txt new file mode 100644 index 0000000..d10613b --- /dev/null +++ b/indefero/src/IDF/templates/idf/admin/request-email.txt @@ -0,0 +1,10 @@ +Hello {$user}, + +You are receiving this email because you have requested a repository. +Your request for {$shortname|safe} was approved! + +If you have any questions please feel free to email a member of the development team. + +Yours faithfully, +The development team. + diff --git a/indefero/src/IDF/templates/idf/user/projectrequest.html b/indefero/src/IDF/templates/idf/user/projectrequest.html new file mode 100644 index 0000000..42f9ab5 --- /dev/null +++ b/indefero/src/IDF/templates/idf/user/projectrequest.html @@ -0,0 +1,60 @@ +{extends "idf/base-simple.html"} +{block body} + +{if $form.errors} +
+

{trans 'Oops, please check the errors on the form.'}

+ {if $form.get_top_errors} + {$form.render_top_errors|unsafe} + {/if} +
+{/if} +{if $success} +
+

+ Thank you - your request has been received and will be approved by an admin shortly. +

+
+{/if} +{if $error} +
+{$error} +
+{/if} + +
+ + + + + + + + + + + + + + + + + +
{$form.f.shortname.labelTag}:{if $form.f.shortname.errors}{$form.f.shortname.fieldErrors}{/if} + {$form.f.shortname|unsafe}
+ {$form.f.shortname.help_text} +
{$form.f.repotype.labelTag}:{if $form.f.repotype.errors}{$form.f.repotype.fieldErrors}{/if} + {$form.f.repotype|unsafe}
+ {$form.f.repotype.help_text} +
{$form.f.desc.labelTag}:{if $form.f.desc.errors}{$form.f.desc.fieldErrors}{/if} + {$form.f.desc|unsafe}
+ {$form.f.desc.help_text} +
 
+ +
+ +{/block} +{block context} + + +{/block} \ No newline at end of file