Wtx ~ Wt Extension Library
WtxLib
ViewDetail.cpp
1 /**************************************************************************
2 ###########################################################################
3 ##
4 ## $SHOWOFFDB_BEGIN_LICENSE$
5 ## Copyright (C) 2011 Lorimark Solutions, LLC and/or its subsidiary(-ies).
6 ## All rights reserved.
7 ## Contact: Lorimark Solutions, LLC (info@showoff-db.org)
8 ##
9 ## This file is part of the Showoff Database Application Framework.
10 ##
11 ## Commercial Usage
12 ## Licensees holding valid ShowoffDB Commercial licenses may use this file in
13 ## accordance with the ShowoffDB Commercial License Agreement provided with the
14 ## Software or, alternatively, in accordance with the terms contained in
15 ## a written agreement between you and Lorimark Solutions, LLC.
16 ##
17 ## GNU Lesser General Public License Usage
18 ## Alternatively, this file may be used under the terms of the GNU Lesser
19 ## General Public License version 2.1 as published by the Free Software
20 ## Foundation and appearing in the file LICENSE.LGPL included in the
21 ## packaging of this file. Please review the following information to
22 ## ensure the GNU Lesser General Public License version 2.1 requirements
23 ## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ##
25 ## In addition, as a special exception, Lorimark Solutions, LLC gives
26 ## you certain additional rights. These rights are described in the
27 ## Lorimark Solutions, LLC ShowoffDB LGPL Exception version 1.0, included in
28 ## the file LGPL_EXCEPTION.txt in this package.
29 ##
30 ## GNU General Public License Usage
31 ## Alternatively, this file may be used under the terms of the GNU
32 ## General Public License version 3.0 as published by the Free Software
33 ## Foundation and appearing in the file LICENSE.GPL included in the
34 ## packaging of this file. Please review the following information to
35 ## ensure the GNU General Public License version 3.0 requirements will be
36 ## met: http://www.gnu.org/copyleft/gpl.html.
37 ##
38 ## If you have questions regarding the use of this file, please contact
39 ## Lorimark Solutions, LLC at info@showoff-db.org.
40 ## $SHOWOFFDB_END_LICENSE$
41 ##
42 #############################################################################
43 ****************************************************************************/
44 
45 
46 #include <Wt/WTemplate.h>
47 #include <Wt/WText.h>
48 
49 #include "Item.h"
50 #include "ViewDetail.h"
51 
52 #ifndef ID_DETAIL_ITEM
53 #define ID_DETAIL_ITEM "Wtx.Web.BlogEntry.Item.DetailForm"
54 #endif
55 
56 void Wtx::Web::BlogEntry::ViewDetail::init( const Wt::Dbo::ptr<Wtx::Web::BlogEntry::Item> & item )
57 {
58  if( !item )
59  {
60  addNew<Wt::WText>( "Oops, I was unable to find that article" );
61  return;
62  }
63 
64  /*
65  ** Try to load the template. If it does not load then
66  ** default to one that may be suitable.
67  **
68  */
69  auto tr = Wt::WString::tr( ID_DETAIL_ITEM );
70  if( tr.toUTF8().find("??") != std::string::npos )
71  {
72  tr =
73  Wt::WString
74  (
75  "<div>"
76  " <strong><big>${title}</big></strong><br />"
77  " ${<if-posted>}"
78  " <small>Posted on ${date}</small><br />"
79  " ${</if-posted>}"
80  " ${body}<br />"
81  " <br />"
82  " <br />"
83  "</div>"
84  );
85  }
86 
87  /*
88  ** Load the template and bind stuff to it.
89  **
90  */
91  auto templt = addNew<Wt::WTemplate>( tr );
92 
93  /*
94  ** If the date has nothing in it, then just leave it empty
95  **
96  */
97  templt-> setCondition( "if-posted", item-> datePosted.value() != "" );
98  templt-> bindNew<Wt::WText>( "date", item-> datePosted.value() );
99 
100  templt-> bindNew<Wt::WText>( "title", item-> keyField().value() );
101  templt-> bindNew<Wt::WText>( "body", item-> body.value(), Wt::TextFormat::UnsafeXHTML );
102 }
103 
104 Wtx::Web::BlogEntry::ViewDetail::ViewDetail( const Wt::Dbo::ptr<Wtx::Web::BlogEntry::Item> & item )
105 : Wt::WContainerWidget()
106 {
107  init( item );
108 }
109 
110 #ifdef NEVER
111 Wtx::Web::BlogEntryViewDetail::BlogEntryViewDetail( const std::string & url )
112 : Wt::WContainerWidget()
113 {
114  auto key = url.substr( std::string(BLOG_ENTRY_URL).length() );
115 // auto key = url.substr( 8 );
116 
117  std::cout << __FILE__ << ":" << __LINE__ << " " << url.size() << " " << url << ":" << key << std::endl;
118 
119  Wt::Dbo::Transaction t(*kbwSession);
120  auto item =
121  kbwSession-> find<Wtx::Web::BlogEntry>()
122  .where( "\"keyField\" = ?" ).bind( key )
123  .resultValue()
124  ;
125 
126  init( item );
127 }
128 #endif
129 
130