[dev] [commit] r927 - patches phplib phplib/models templates/admin wwwbase/admin wwwbase/js

automailer at dexonline.ro automailer at dexonline.ro
Wed Aug 14 16:40:58 EEST 2013


Author: cata
Date: Wed Aug 14 16:40:58 2013
New Revision: 927

Log:
Rework the lexemEdit page:

* proper validation, including the lexem, its restrictions and paradigm
* convert lexem sources to a separate class, to allow all sources, not just the few that were hard-coded

Added:
   patches/00091.sql
   patches/00092.php
   patches/00093.sql
   phplib/models/LexemSource.php
Deleted:
   phplib/LexemSources.php
Modified:
   phplib/models/Lexem.php
   phplib/util.php
   templates/admin/lexemEdit.ihtml
   wwwbase/admin/lexemEdit.php
   wwwbase/admin/properNouns.php
   wwwbase/js/struct.js

Added: patches/00091.sql
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ patches/00091.sql	Wed Aug 14 16:40:58 2013	(r927)
@@ -0,0 +1,8 @@
+create table LexemSource (
+  id int not null auto_increment,
+  lexemId int not null,
+  sourceId int not null,
+  createDate int not null,
+  modDate int not null,
+  primary key(id)
+);

Added: patches/00092.php
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ patches/00092.php	Wed Aug 14 16:40:58 2013	(r927)
@@ -0,0 +1,30 @@
+<?php
+
+$sourceMap = array(
+  'der' => Source::get_by_urlName('der'),
+  'dex' => Source::get_by_urlName('dex'),
+  'dlrm' => Source::get_by_urlName('dlrm'),
+  'dmlr' => Source::get_by_urlName('dmlr'),
+  'doom' => Source::get_by_urlName('doom'),
+  'nodex' => Source::get_by_urlName('nodex'),
+  'orto' => Source::get_by_urlName('do'), // it differs here
+);
+
+$lexems = Model::factory('Lexem')->where_not_equal('source', '')->find_many();
+$inserted = 0;
+foreach ($lexems as $l) {
+  $urlNames = explode(',', $l->source);
+  foreach ($urlNames as $urlName) {
+    $source = $sourceMap[$urlName];
+    assert($source);
+    $ls = Model::factory('LexemSource')->create();
+    $ls->lexemId = $l->id;
+    $ls->sourceId = $source->id;
+    $ls->save();
+    $inserted++;
+  }
+}
+
+printf("%d lexems modified, %d lexem sources inserted.\n", count($lexems), $inserted);
+
+?>

Added: patches/00093.sql
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ patches/00093.sql	Wed Aug 14 16:40:58 2013	(r927)
@@ -0,0 +1 @@
+alter table Lexem drop source;

Deleted: phplib/LexemSources.php
==============================================================================
--- phplib/LexemSources.php	Wed Aug 14 16:40:58 2013	(r926)
+++ /dev/null	00:00:00 1970	(deleted)
@@ -1,41 +0,0 @@
-<?php
-
-class LexemSources {
-  //It should be in sync with table Lexem, field source
-  private static $lexemSourcesArray = array(
-                                            "doom"	=> array( "name" => "DOOM" ), 
-                                            "dex" 	=> array( "name" => "DEX" ), 
-                                            "dmlr"	=> array( "name" => "DMLR" ), 
-                                            "nodex"	=> array( "name" => "NODEX" ),
-                                            "mda"	=> array( "name" => "MDA" ),
-                                            "der"	=> array( "name" => "DER" ),
-                                            "orto"	=> array( "name" => "Ortografic" ),
-                                            "dlrm"	=> array( "name" => "DLRM '58" ),
-                                            );
-
-  static function getNamesOfSources($sourceList) {
-    if(!$sourceList) return "";
-    $sList = explode(",", $sourceList);
-    $names = array();
-    foreach($sList as $source) {
-      if (is_array(self::$lexemSourcesArray[$source])){
-        $names[] = self::$lexemSourcesArray[$source]["name"];
-      }
-    }
-    return implode(", ", $names);
-  }
-
-  static function getSourceArrayChecked($sourceList) {
-    $sList = explode(",", $sourceList);
-    $sourceArray = array();
-    foreach(self::$lexemSourcesArray as $id => $source) {
-      $sourceArray[$id] = array("name" => $source["name"]);
-      if (in_array($id, $sList) ) {
-        $sourceArray[$id]["checked"] = 1;
-      }
-    }
-    return $sourceArray;
-  }
-}
-
-?>

Modified: phplib/models/Lexem.php
==============================================================================
--- phplib/models/Lexem.php	Mon Aug 12 17:24:02 2013	(r926)
+++ phplib/models/Lexem.php	Wed Aug 14 16:40:58 2013	(r927)
@@ -13,7 +13,6 @@
     }
     $l->description = '';
     $l->tags = '';
-    $l->source = '';
     $l->modelType = $modelType;
     $l->modelNumber = $modelNumber;
     $l->restriction = $restriction;
@@ -402,6 +401,7 @@
       LexemDefinitionMap::deleteByLexemId($this->id);
       InflectedForm::deleteByLexemId($this->id);
       Meaning::deleteByLexemId($this->id);
+      LexemSource::deleteByLexemId($this->id);
     }
     // Clear the variantOfId field for lexems having $this as main.
     $lexemsToClear = Lexem::get_all_by_variantOfId($this->id);
@@ -414,6 +414,7 @@
 
   public function save() {
     $this->formUtf8General = $this->formNoAccent;
+    $this->reverse = StringUtil::reverse($this->formNoAccent);
     $this->charLength = mb_strlen($this->formNoAccent);
     parent::save();
   }  

Added: phplib/models/LexemSource.php
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ phplib/models/LexemSource.php	Wed Aug 14 16:40:58 2013	(r927)
@@ -0,0 +1,40 @@
+<?php
+
+class LexemSource extends BaseObject implements DatedObject {
+  public static $_table = 'LexemSource';
+
+  /* Returns a list of sourceId's. */
+  public static function getForLexem($lexem) {
+    $results = array();
+    $lexemSources = LexemSource::get_all_by_lexemId($lexem->id);
+    foreach($lexemSources as $ls) {
+      $results[] = $ls->sourceId;
+    }
+    return $results;
+  }
+
+  public static function update($lexemId, $sourceIds) {
+    $lss = self::get_all_by_lexemId($lexemId);
+    while (count($lss) < count($sourceIds)) {
+      $lss[] = Model::factory('LexemSource')->create();
+    }
+    while (count($lss) > count($sourceIds)) {
+      $deadLs = array_pop($lss);
+      $deadLs->delete();
+    }
+    foreach ($sourceIds as $i => $sourceId) {
+      $lss[$i]->lexemId = $lexemId;
+      $lss[$i]->sourceId = $sourceId;
+      $lss[$i]->save();
+    }
+  }
+
+  public static function deleteByLexemId($lexemId) {
+    $meanings = self::get_all_by_lexemId($lexemId);
+    foreach ($meanings as $m) {
+      $m->delete();
+    }
+  }
+}
+
+?>

Modified: phplib/util.php
==============================================================================
--- phplib/util.php	Mon Aug 12 17:24:02 2013	(r926)
+++ phplib/util.php	Wed Aug 14 16:40:58 2013	(r927)
@@ -207,6 +207,12 @@
   return ($string == NULL) ? $default : (int)$string;
 }
 
+/* A boolean is a checkbox, a yes/no radio button pair, or any field that returns empty for false and non-empty for true. */
+function util_getBoolean($name) {
+  $v = util_getRequestParameter($name);
+  return $v ? true : false;
+}
+
 function util_getRequestCheckboxArray($name, $separator) {
   $arr = util_getRequestParameter($name);
   return $arr ? implode($arr, $separator) : '';
@@ -469,4 +475,15 @@
   return $results;
 }
 
+/* Returns an array of { $v -> true } for every value $v in $a */
+function util_makeSet($a) {
+  $result = array();
+  if ($a) {
+    foreach ($a as $v) {
+      $result[$v] = true;
+    }
+  }
+  return $result;
+}
+
 ?>

Modified: templates/admin/lexemEdit.ihtml
==============================================================================
--- templates/admin/lexemEdit.ihtml	Mon Aug 12 17:24:02 2013	(r926)
+++ templates/admin/lexemEdit.ihtml	Wed Aug 14 16:40:58 2013	(r927)
@@ -41,9 +41,11 @@
     <tr>
       <td>Etichete:</td>
       <td>
-        {foreach from=$sources key=k item=v}
-          <input type="checkbox" name="lexemSources[]" value="{$k}" {if isset($v.checked)}checked="checked"{/if}>{$v.name}</input>
-        {/foreach}
+        <select id="lexemSourceIds" name="lexemSourceIds[]" multiple="multiple">
+          {foreach from=$sources item=s}
+            <option value="{$s->id}" {if array_key_exists($s->id, $lexemSourceIdMap)}selected="selected"{/if}>{$s->shortName}</option>
+          {/foreach}
+        </select>
         <br/>
         <input type="text" name="lexemTags" value="{$lexem->tags|escape}" size="40"/>
 
@@ -57,16 +59,9 @@
       <td>Inclus în LOC</td>
       <td>
         {if $sUser && ($sUser->moderator & $smarty.const.PRIV_LOC)}
-          <input type="radio" name="lexemIsLoc" value="1"
-                 id="lexemIsLocYes"
-                 {if $lexem->isLoc}checked="checked"{/if}/>
-          <label for="lexemIsLocYes">Da</label>
-
-          <input type="radio" name="lexemIsLoc" value=""
-                 id="lexemIsLocNo"
-                 {if !$lexem->isLoc}checked="checked"{/if}/>
-          <label for="lexemIsLocNo">Nu</label>
+          <input type="checkbox" name="lexemIsLoc" value="1" {if $lexem->isLoc}checked="checked"{/if}/>
         {else}
+          <input type="hidden" name="lexemIsLoc" value="{if $lexem->isLoc}1{/if}"/>
           {if $lexem->isLoc}Da{else}Nu{/if}
         {/if}
 
@@ -79,15 +74,7 @@
     <tr>
       <td>Necesită accent</td>
       <td>
-        <input type="radio" name="lexemNoAccent" value=""
-               id="lexemYesAccent"
-               {if !$lexem->noAccent}checked="checked"{/if}/>
-        <label for="lexemYesAccent">Da</label>
-
-        <input type="radio" name="lexemNoAccent" value="1"
-               id="lexemNoAccent"
-               {if $lexem->noAccent}checked="checked"{/if}/>
-        <label for="lexemNoAccent">Nu</label>
+        <input type="checkbox" name="needsAccent" value="1" {if !$lexem->noAccent}checked="checked"{/if}/>
 
         <span class="tooltip" title="Majoritatea lexemelor necesită accent. Excepție fac cuvintele compuse, denumirile științifice de animale și
         plante, elementele de compunere etc."> </span>
@@ -129,15 +116,14 @@
 
 <div class="lexemSectionHeader">Paradigmă</div>
 
-{if $sUser && ($sUser->moderator & $smarty.const.PRIV_LOC)}
-  <div class="lexemSection">
+<div class="lexemSection">
+  {if $sUser && ($sUser->moderator & $smarty.const.PRIV_LOC)}
     Puteți face etichetarea în trei moduri: (1) alegeți una dintre
     sugestii; (2) indicați un cuvânt care se flexionează la fel; sau
     (3) indicați tipul și numărul modelului.
     <br/><br/>
 
-    <b>1. {include file="common/bits/lexemName.ihtml" lexem=$lexem}</b>
-    se flexionează ca...
+    <b>1. {include file="common/bits/lexemName.ihtml" lexem=$lexem}</b> se flexionează ca...
     {foreach from=$suggestedLexems item=l key=i}
       {if $i}|{/if}
       {include file="common/bits/lexemName.ihtml" lexem=$l accent=1}
@@ -149,8 +135,7 @@
     <input id="similarLexemId" type="text" name="similarLexemId"/>
     <br/><br/>
 
-    <b>3. {include file="common/bits/lexemName.ihtml" lexem=$lexem}</b>
-    se flexionează conform modelului
+    <b>3. {include file="common/bits/lexemName.ihtml" lexem=$lexem}</b> se flexionează conform modelului
     <select name="modelType" id="modelTypeListId" onchange="return updateModelList(false)">
       {foreach from=$modelTypes item=mt}
         <option value="{$mt->code|escape}"
@@ -189,8 +174,11 @@
     <input type="checkbox" id="restrT" name="restr[]" value="T"
       {if $restrT}checked="checked"{/if}/>
     <label for="restrT">Trecut</label>
-  </div>
-{/if}
+  {else}
+    <b>{include file="common/bits/lexemName.ihtml" lexem=$lexem}</b> se flexionează conform modelului
+    {$lexem->modelType}{$lexem->modelNumber}{$lexem->restriction}.
+  {/if}
+</div>
 
 {if $ifMap && !$errorMessage}
   {include file="common/paradigm/current/paradigm.ihtml" lexem=$lexem ifMap=$ifMap}
@@ -212,7 +200,7 @@
 <div class="lexemSection">
   <input type="submit" name="refreshLexem" value="Reafișează"/>
     
-  <input type="submit" name="updateLexem" value="Salvează"/>
+  <input type="submit" name="saveLexem" value="Salvează"/>
     
   <input type="submit" name="cloneLexem" value="Clonează"/>
 

Modified: wwwbase/admin/lexemEdit.php
==============================================================================
--- wwwbase/admin/lexemEdit.php	Mon Aug 12 17:24:02 2013	(r926)
+++ wwwbase/admin/lexemEdit.php	Wed Aug 14 16:40:58 2013	(r927)
@@ -10,11 +10,11 @@
 $associateDefinitionId = util_getRequestParameter('associateDefinitionId');
 $lexemForm = util_getRequestParameter('lexemForm');
 $lexemDescription = util_getRequestParameter('lexemDescription');
-$lexemSources = util_getRequestParameter('lexemSources');
+$lexemSourceIds = util_getRequestParameter('lexemSourceIds');
 $lexemTags = util_getRequestParameter('lexemTags');
 $lexemComment = util_getRequestParameter('lexemComment');
-$lexemIsLoc = util_getRequestParameter('lexemIsLoc');
-$lexemNoAccent = util_getRequestParameter('lexemNoAccent');
+$lexemIsLoc = util_getBoolean('lexemIsLoc');
+$needsAccent = util_getBoolean('needsAccent');
 $modelType = util_getRequestParameter('modelType');
 $modelNumber = util_getRequestParameter('modelNumber');
 $similarModel = util_getRequestParameter('similarModel');
@@ -23,14 +23,15 @@
 $miniDefTarget = util_getRequestParameter('miniDefTarget');
 
 $refreshLexem = util_getRequestParameter('refreshLexem');
-$updateLexem = util_getRequestParameter('updateLexem');
+$saveLexem = util_getRequestParameter('saveLexem');
 $cloneLexem = util_getRequestParameter('cloneLexem');
 $deleteLexem = util_getRequestParameter('deleteLexem');
 $createDefinition = util_getRequestParameter('createDefinition');
 
 $lexem = Lexem::get_by_id($lexemId);
-$oldModelType = $lexem->modelType;
-$oldModelNumber = $lexem->modelNumber;
+$original = Lexem::get_by_id($lexemId); // Keep a copy so we can test whether certain fields have changed
+
+/*************************** various actions other than the save/refresh buttons ***************************/
 
 if ($associateDefinitionId) {
   LexemDefinitionMap::associate($lexem->id, $associateDefinitionId);
@@ -77,127 +78,80 @@
   util_redirect("lexemEdit.php?lexemId={$newLexem->id}");
 }
 
-if (!$similarModel && !$similarLexemId && !$refreshLexem && !$updateLexem) {
+if (!$similarModel && !$similarLexemId && !$refreshLexem && !$saveLexem) {
   RecentLink::createOrUpdate("Lexem: {$lexem}");
 }
 
-if ($lexemForm !== null) {
-  $oldUnaccented = $lexem->formNoAccent;
+if ($refreshLexem || $saveLexem) {
+  // Populate lexem fields from request parameters.
   $lexem->form = AdminStringUtil::formatLexem($lexemForm);
   $lexem->formNoAccent = str_replace("'", '', $lexem->form);
-  $lexem->reverse = StringUtil::reverse($lexem->formNoAccent);
-  if ($lexem->formNoAccent != $oldUnaccented) {
-    $lexem->modelType = 'T';
-    $lexem->modelNumber = 1;
-  }
-}
-
-if ($lexemDescription !== null) {
   $lexem->description = AdminStringUtil::internalize($lexemDescription, false);
-}
-
-if ($lexemTags !== null) {
   $lexem->tags = AdminStringUtil::internalize($lexemTags, false);
-}
-
-if ($lexemSources !== null) {
-  $lexem->source = implode(',', $lexemSources);
-}	
-
-if ($lexemComment !== null) {
-  $newComment = trim(AdminStringUtil::internalize($lexemComment, false));
-  $oldComment = trim($lexem->comment);
-  if (StringUtil::startsWith($newComment, $oldComment) &&
-      $newComment != $oldComment &&
-      !StringUtil::endsWith($newComment, ']]')) {
-    $newComment .= " [[" . session_getUser() . ", " .
-      strftime("%d %b %Y %H:%M") . "]]\n";
-  } else if ($newComment) {
-    $newComment .= "\n";
-  }
-  $lexem->comment = $newComment;
-}
-
-if ($lexemIsLoc !== null) {
-  $lexem->isLoc = ($lexemIsLoc != '');
-}
-
-if ($lexemNoAccent !== null) {
-  $lexem->noAccent = ($lexemNoAccent != '');
-}
-
-// The new model type, number and restrictions can come from three sources:
-// $similarModel, $similarLexemId or ($modelType, $modelNumber,
-// $restriction) directly
-$errorMessage = '';
-if ($similarModel !== null) {
-  $parts = FlexModel::splitName($similarModel);
-  $lexem->modelType = $parts[0];
-  $lexem->modelNumber = $parts[1];
-  $lexem->restriction = $parts[2];
-} else if ($similarLexemId) {
-  $similarLexem = Lexem::get_by_id($similarLexemId);
-  $lexem->modelType = $similarLexem->modelType;
-  $lexem->modelNumber = $similarLexem->modelNumber;
-  $lexem->restriction = $similarLexem->restriction;
-} else if ($modelType !== null) {
-  $lexem->modelType = $modelType;
-  $lexem->modelNumber = $modelNumber;
-  $lexem->restriction = $restriction;
-}
-
-if (!$errorMessage) {
-  $errorMessage = validate($lexem);
-}
-
-if (!$errorMessage) {
-  $errorMessage = validateRestriction($lexem->modelType, $lexem->restriction);
-}
+  $lexem->comment = trim(AdminStringUtil::internalize($lexemComment, false));
+  // Sign appended comments
+  if (StringUtil::startsWith($lexem->comment, $original->comment) &&
+      $lexem->comment != $original->comment &&
+      !StringUtil::endsWith($lexem->comment, ']]')) {
+    $lexem->comment .= " [[" . session_getUser() . ", " . strftime("%d %b %Y %H:%M") . "]]";
+  }
+  $lexem->isLoc = $lexemIsLoc;
+  $lexem->noAccent = !$needsAccent;
+
+  // The new model type, number and restrictions can come from three sources:
+  // $similarModel, $similarLexemId or ($modelType, $modelNumber,
+  // $restriction) directly
+  if ($similarModel !== null) {
+    $parts = FlexModel::splitName($similarModel);
+    $lexem->modelType = $parts[0];
+    $lexem->modelNumber = $parts[1];
+    $lexem->restriction = $parts[2];
+  } else if ($similarLexemId) {
+    $similarLexem = Lexem::get_by_id($similarLexemId);
+    $lexem->modelType = $similarLexem->modelType;
+    $lexem->modelNumber = $similarLexem->modelNumber;
+    $lexem->restriction = $similarLexem->restriction;
+  } else if ($modelType !== null) {
+    $lexem->modelType = $modelType;
+    $lexem->modelNumber = $modelNumber;
+    $lexem->restriction = $restriction;
+  }
+
+  $ifs = $lexem->generateParadigm();
+
+  if (validate($lexem, $ifs)) {
+    if ($saveLexem) {
+      if ($original->modelType == 'VT' && $lexem->modelType != 'VT') {
+        $lexem->deleteParticiple($original->modelNumber);
+      }
+      if (($original->modelType == 'VT' || $original->modelType == 'V') &&
+          ($lexem->modelType != 'VT' && $lexem->modelType != 'V')) {
+        $lexem->deleteLongInfinitive();
+      }
+      $lexem->save();
+      LexemSource::update($lexem->id, $lexemSourceIds);
+      $lexem->regenerateParadigm(); // This generates AND saves the paradigm
 
-if ($updateLexem && !$errorMessage) {
-  if ($oldModelType == 'VT' && $lexem->modelType != 'VT') {
-    $lexem->deleteParticiple($oldModelNumber);
-  }
-  if (($oldModelType == 'VT' || $oldModelType == 'V') &&
-      ($lexem->modelType != 'VT' && $lexem->modelType != 'V')) {
-    $lexem->deleteLongInfinitive();
+      log_userLog("Edited lexem {$lexem->id} ({$lexem->form})");
+      util_redirect("lexemEdit.php?lexemId={$lexem->id}");
+    }
   }
-  $lexem->save();
-  // There are two reasons to regenerate the paradigm: the model has changed
-  // or the form has changed. It's easier to do it every time.
-  $lexem->regenerateParadigm();
-
-  log_userLog("Edited lexem {$lexem->id} ({$lexem->form})");
-  util_redirect("lexemEdit.php?lexemId={$lexem->id}");
+} else {
+  $ifs = $lexem->generateParadigm();
+  $lexemSourceIds = LexemSource::getForLexem($lexem);
 }
 
 $definitions = Definition::loadByLexemId($lexem->id);
 $searchResults = SearchResult::mapDefinitionArray($definitions);
 $definitionLexem = mb_strtoupper(AdminStringUtil::internalize($lexem->form, false));
 
-// Generate new inflected forms, but do not overwrite the old ones.
-$ifs = $lexem->generateParadigm();
-if (!is_array($ifs)) {
-  $infl = Inflection::get_by_id($ifs);
-  if (!$errorMessage) {
-    $errorMessage = "Nu pot genera flexiunea '".htmlentities($infl->description)."' " .
-      "conform modelului {$lexem->modelType}{$lexem->modelNumber}.";
-  }
-} else {
+if (is_array($ifs)) {
   $ifMap = InflectedForm::mapByInflectionRank($ifs);
   SmartyWrap::assign('ifMap', $ifMap);
-  SmartyWrap::assign('searchResults', $searchResults);
 }
 
-$models = FlexModel::loadByType($lexem->modelType);
-
-$sources = LexemSources::getSourceArrayChecked($lexem->source);
-$sourceNames = LexemSources::getNamesOfSources($lexem->source);
-$canEditForm = !$lexem->isLoc || util_isModerator(PRIV_LOC);
-
 SmartyWrap::assign('lexem', $lexem);
-SmartyWrap::assign('sources', $sources);
-SmartyWrap::assign('sourceNames', $sourceNames);
+SmartyWrap::assign('lexemSourceIdMap', util_makeSet($lexemSourceIds));
 SmartyWrap::assign('searchResults', $searchResults);
 SmartyWrap::assign('definitionLexem', $definitionLexem);
 SmartyWrap::assign('homonyms', Model::factory('Lexem')->where('formNoAccent', $lexem->formNoAccent)->where_not_equal('id', $lexem->id)->find_many());
@@ -208,58 +162,63 @@
 SmartyWrap::assign('restrI', FlexStringUtil::contains($lexem->restriction, 'I'));
 SmartyWrap::assign('restrT', FlexStringUtil::contains($lexem->restriction, 'T'));
 SmartyWrap::assign('modelTypes', Model::factory('ModelType')->order_by_asc('code')->find_many());
-SmartyWrap::assign('models', $models);
-SmartyWrap::assign('canEditForm', $canEditForm);
+SmartyWrap::assign('models', FlexModel::loadByType($lexem->modelType));
+SmartyWrap::assign('canEditForm', !$lexem->isLoc || util_isModerator(PRIV_LOC));
 SmartyWrap::assign('allStatuses', util_getAllStatuses());
-SmartyWrap::assign('errorMessage', $errorMessage);
-SmartyWrap::assign('recentLinks', RecentLink::loadForUser());
 SmartyWrap::addCss('jqueryui', 'paradigm', 'select2');
 SmartyWrap::addJs('jquery', 'jqueryui', 'struct', 'select2');
 SmartyWrap::assign('sectionTitle', "Editare lexem: {$lexem->form} {$lexem->modelType}{$lexem->modelNumber}{$lexem->restriction}");
 SmartyWrap::displayAdminPage('admin/lexemEdit.ihtml');
 
-function validate($lexem) {
+/**************************************************************************/
+
+function validate($lexem, $ifs) {
   if (!$lexem->form) {
-    return 'Forma nu poate fi vidă.';
+    FlashMessage::add('Forma nu poate fi vidă.');
   }
+
   $numAccents = mb_substr_count($lexem->form, "'");
   // Note: we allow multiple accents for lexems like hárcea-párcea
   if ($numAccents && $lexem->noAccent) {
-    return 'Ați indicat că lexemul nu necesită accent, dar forma conține un accent.';
+    FlashMessage::add('Ați indicat că lexemul nu necesită accent, dar forma conține un accent.');
   } else if (!$numAccents && !$lexem->noAccent) {
-    return 'Adăugați un accent sau bifați câmpul "Nu necesită accent".';
+    FlashMessage::add('Adăugați un accent sau debifați câmpul "Necesită accent".');
   }
-  return null;
-}
 
-function validateRestriction($modelType, $restriction) {
   $hasS = false;
   $hasP = false;
-  for ($i = 0; $i < mb_strlen($restriction); $i++) {
-    $char = StringUtil::getCharAt($restriction, $i);
+  for ($i = 0; $i < mb_strlen($lexem->restriction); $i++) {
+    $char = StringUtil::getCharAt($lexem->restriction, $i);
     if ($char == 'T' || $char == 'U' || $char == 'I') {
-      if ($modelType != 'V' && $modelType != 'VT') {
-        return "Restricția <b>$char</b> se aplică numai verbelor";
+      if ($lexem->modelType != 'V' && $lexem->modelType != 'VT') {
+        FlashMessage::add("Restricția <b>$char</b> se aplică numai verbelor");
       }
     } else if ($char == 'S') {
-      if ($modelType == 'I' || $modelType == 'T') {
-        return "Restricția S nu se aplică modelului $modelType";
+      if ($lexem->modelType == 'I' || $lexem->modelType == 'T') {
+        FlashMessage::add("Restricția <b>S</b> nu se aplică modelului $lexem->modelType");
       }
       $hasS = true;
     } else if ($char == 'P') {
-      if ($modelType == 'I' || $modelType == 'T') {
-        return "Restricția P nu se aplică modelului $modelType";
+      if ($lexem->modelType == 'I' || $lexem->modelType == 'T') {
+        FlashMessage::add("Restricția <b>P</b> nu se aplică modelului $lexem->modelType");
       }
       $hasP = true;
     } else {
-      return "Restricția <b>$char</b> este incorectă.";
+      FlashMessage::add("Restricția <b>$char</b> este incorectă.");
     }
   }
   
   if ($hasS && $hasP) {
-    return "Restricțiile <b>S</b> și <b>P</b> nu pot coexista.";
+    FlashMessage::add("Restricțiile <b>S</b> și <b>P</b> nu pot coexista.");
+  }
+
+  if (!is_array($ifs)) {
+    $infl = Inflection::get_by_id($ifs);
+    FlashMessage::add(sprintf("Nu pot genera flexiunea '%s' conform modelului %s%s",
+                              htmlentities($infl->description), $lexem->modelType, $lexem->modelNumber));
   }
-  return null;
+
+  return FlashMessage::getMessage() == null;
 }
 
 function loadSuggestions($lexem, $limit) {

Modified: wwwbase/admin/properNouns.php
==============================================================================
--- wwwbase/admin/properNouns.php	Mon Aug 12 17:24:02 2013	(r926)
+++ wwwbase/admin/properNouns.php	Wed Aug 14 16:40:58 2013	(r927)
@@ -34,7 +34,6 @@
           $l->form = AdminStringUtil::capitalize($l->form);
         }
         $l->formNoAccent = str_replace("'", '', $l->form);
-        $l->reverse = StringUtil::reverse($l->formNoAccent);
         break;
         
       case 'singular':

Modified: wwwbase/js/struct.js
==============================================================================
--- wwwbase/js/struct.js	Mon Aug 12 17:24:02 2013	(r926)
+++ wwwbase/js/struct.js	Wed Aug 14 16:40:58 2013	(r927)
@@ -103,6 +103,9 @@
 }
 
 function lexemEditInit() {
+  $('#lexemSourceIds').select2({
+    width: '333px',
+  });
   $('#similarLexemId').select2({
     ajax: struct_lexemAjax,
     minimumInputLength: 1,


More information about the Dev mailing list